PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/scripts.php

https://github.com/strangerstudios/paid-memberships-pro
PHP | 145 lines | 103 code | 18 blank | 24 comment | 20 complexity | cf7b72604395a71d37853f03e999d965 MD5 | raw file
  1. <?php
  2. /**
  3. * Enqueue frontend JavaScript and CSS
  4. */
  5. function pmpro_enqueue_scripts() {
  6. global $pmpro_pages;
  7. // Figure out which frontend.css file to load.
  8. if( file_exists( get_stylesheet_directory() . "/paid-memberships-pro/css/frontend.css" ) ) {
  9. $frontend_css = get_stylesheet_directory_uri() . "/paid-memberships-pro/css/frontend.css";
  10. } elseif( file_exists( get_template_directory() . "/paid-memberships-pro/frontend.css" ) ) {
  11. $frontend_css = get_template_directory_uri() . "/paid-memberships-pro/frontend.css";
  12. } else {
  13. $frontend_css = plugins_url( 'css/frontend.css',dirname(__FILE__) );
  14. }
  15. wp_enqueue_style( 'pmpro_frontend', $frontend_css, array(), PMPRO_VERSION, "screen" );
  16. // Figure out which frontend-rlt.css file to load if applicable.
  17. if( is_rtl() ) {
  18. if( file_exists( get_stylesheet_directory() . "/paid-memberships-pro/css/frontend-rtl.css" ) ) {
  19. $frontend_css_rtl = get_stylesheet_directory_uri() . "/paid-memberships-pro/css/frontend-rtl.css";
  20. } elseif ( file_exists( get_template_directory() . "/paid-memberships-pro/css/frontend-rtl.css" ) ) {
  21. $frontend_css_rtl = get_template_directory_uri() . "/paid-memberships-pro/css/frontend-rtl.css";
  22. } else {
  23. $frontend_css_rtl = plugins_url('css/frontend-rtl.css',dirname(__FILE__) );
  24. }
  25. wp_enqueue_style( 'pmpro_frontend_rtl', $frontend_css_rtl, array(), PMPRO_VERSION, "screen" );
  26. }
  27. // Print styles.
  28. if(file_exists(get_stylesheet_directory() . "/paid-memberships-pro/css/print.css"))
  29. $print_css = get_stylesheet_directory_uri() . "/paid-memberships-pro/css/print.css";
  30. elseif(file_exists(get_template_directory() . "/paid-memberships-pro/print.css"))
  31. $print_css = get_template_directory_uri() . "/paid-memberships-pro/print.css";
  32. else
  33. $print_css = plugins_url('css/print.css',dirname(__FILE__) );
  34. wp_enqueue_style('pmpro_print', $print_css, array(), PMPRO_VERSION, "print");
  35. // Checkout page JS
  36. if ( pmpro_is_checkout() ) {
  37. wp_register_script( 'pmpro_checkout',
  38. plugins_url( 'js/pmpro-checkout.js', dirname(__FILE__) ),
  39. array( 'jquery' ),
  40. PMPRO_VERSION );
  41. wp_localize_script( 'pmpro_checkout', 'pmpro', array(
  42. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  43. 'ajax_timeout' => apply_filters( 'pmpro_ajax_timeout', 5000, 'applydiscountcode' ),
  44. 'show_discount_code' => pmpro_show_discount_code(),
  45. 'discount_code_passed_in' => !empty( $_REQUEST['discount_code'] ),
  46. ));
  47. wp_enqueue_script( 'pmpro_checkout' );
  48. }
  49. // Change Password page JS
  50. $is_change_pass_page = ! empty( $pmpro_pages['member_profile_edit'] )
  51. && is_page( $pmpro_pages['member_profile_edit'] )
  52. && ! empty( $_REQUEST['view'] )
  53. && $_REQUEST['view'] === 'change-password';
  54. $is_reset_pass_page = ! empty( $pmpro_pages['login'] )
  55. && is_page( $pmpro_pages['login'] )
  56. && ! empty( $_REQUEST['action'] )
  57. && $_REQUEST['action'] === 'rp';
  58. if ( $is_change_pass_page || $is_reset_pass_page ) {
  59. wp_register_script( 'pmpro_login',
  60. plugins_url( 'js/pmpro-login.js', dirname(__FILE__) ),
  61. array( 'jquery', 'password-strength-meter' ),
  62. PMPRO_VERSION );
  63. /**
  64. * Filter to allow weak passwords on the
  65. * change password and reset password forms.
  66. * At this time, this only disables the JS check on the frontend.
  67. * There is no backend check for weak passwords on those forms.
  68. *
  69. * @since 2.3.3
  70. *
  71. * @param bool $allow_weak_passwords Whether to allow weak passwords.
  72. */
  73. $allow_weak_passwords = apply_filters( 'pmpro_allow_weak_passwords', false );
  74. wp_localize_script( 'pmpro_login', 'pmpro', array(
  75. 'pmpro_login_page' => 'changepassword',
  76. 'strength_indicator_text' => __( 'Strength Indicator', 'paid-memberships-pro' ),
  77. 'allow_weak_passwords' => $allow_weak_passwords ) );
  78. wp_enqueue_script( 'pmpro_login' );
  79. }
  80. }
  81. add_action( 'wp_enqueue_scripts', 'pmpro_enqueue_scripts' );
  82. /**
  83. * Enqueue admin JavaScript and CSS
  84. */
  85. function pmpro_admin_enqueue_scripts() {
  86. // Admin JS
  87. wp_register_script( 'pmpro_admin', plugins_url( 'js/pmpro-admin.js', __DIR__ ), [
  88. 'jquery',
  89. 'jquery-ui-sortable',
  90. ], PMPRO_VERSION );
  91. $all_levels = pmpro_getAllLevels( true, true );
  92. $all_level_values_and_labels = [];
  93. foreach ( $all_levels as $level ) {
  94. $all_level_values_and_labels[] = [
  95. 'value' => $level->id,
  96. 'label' => $level->name,
  97. ];
  98. }
  99. wp_localize_script( 'pmpro_admin', 'pmpro', [
  100. 'all_levels' => $all_levels,
  101. 'all_level_values_and_labels' => $all_level_values_and_labels,
  102. ] );
  103. // Figure out which admin.css to load.
  104. if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/css/admin.css' ) ) {
  105. $admin_css = get_stylesheet_directory_uri() . '/paid-memberships-pro/css/admin.css';
  106. } elseif ( file_exists( get_template_directory() . '/paid-memberships-pro/admin.css' ) ) {
  107. $admin_css = get_template_directory_uri() . '/paid-memberships-pro/admin.css';
  108. } else {
  109. $admin_css = plugins_url( 'css/admin.css', __DIR__ );
  110. }
  111. // Figure out which admin-rtl.css to load if applicable.
  112. if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/css/admin-rtl.css' ) ) {
  113. $admin_css_rtl = get_stylesheet_directory_uri() . '/paid-memberships-pro/css/admin-rtl.css';
  114. } elseif( file_exists( get_template_directory() . '/paid-memberships-pro/css/admin-rtl.css' ) ) {
  115. $admin_css_rtl = get_template_directory_uri() . '/paid-memberships-pro/css/admin-rtl.css';
  116. } else {
  117. $admin_css_rtl = plugins_url( 'css/admin-rtl.css', __DIR__ );
  118. }
  119. wp_register_style( 'pmpro_admin', $admin_css, [], PMPRO_VERSION, 'screen' );
  120. wp_register_style( 'pmpro_admin_rtl', $admin_css_rtl, [], PMPRO_VERSION, 'screen' );
  121. wp_enqueue_script( 'pmpro_admin' );
  122. wp_enqueue_style( 'pmpro_admin' );
  123. if ( is_rtl() ) {
  124. wp_enqueue_style( 'pmpro_admin_rtl' );
  125. }
  126. }
  127. add_action( 'admin_enqueue_scripts', 'pmpro_admin_enqueue_scripts' );