| @@ -11,109 +11,53 @@ | ||
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * The Menu handler class | |
| 16 | - * | |
| 15 | + * Front-end legacy script loader. | |
| 16 | + * | |
| 17 | + * The backend half of this class enqueued the old PHP admin's scripts and styles | |
| 18 | + * on the `better-payment-settings` / `-transactions` / `-analytics` pages. Those | |
| 19 | + * pages no longer exist (the admin is React — see ReactAdmin), so only the | |
| 20 | + * front-end enqueue remains: the user-dashboard templates still rely on | |
| 21 | + * admin.min.js for their copy-to-clipboard buttons. The jQuery UI datepicker is | |
| 22 | + * Pro's (analytics report); its scripts declare that dependency themselves. | |
| 23 | + * | |
| 17 | 24 | * @since 0.0.1 |
| 18 | 25 | */ |
| 19 | 26 | class Menu extends Controller{ |
| 20 | 27 | |
| 21 | - protected $pro_enabled; | |
| 22 | - | |
| 23 | 28 | /** |
| 24 | 29 | * Initialize the class |
| 25 | - * | |
| 30 | + * | |
| 26 | 31 | * @since 0.0.1 |
| 27 | 32 | */ |
| 28 | 33 | function __construct( ) { |
| 29 | - | |
| 34 | + | |
| 30 | 35 | } |
| 31 | 36 | |
| 32 | - public function init($end = 'backend'){ | |
| 33 | - $this->pro_enabled = apply_filters('better_payment/pro_enabled', false); | |
| 34 | - | |
| 35 | - if('backend' === $end) { | |
| 36 | - add_action('admin_enqueue_scripts', array($this, 'handle_scripts_and_styles')); | |
| 37 | - }else if('frontend' === $end){ | |
| 37 | + /** | |
| 38 | + * Register the front-end enqueue. | |
| 39 | + * | |
| 40 | + * @param string $end Only 'frontend' registers anything; the parameter is kept | |
| 41 | + * for existing callers (Frontend passes it). | |
| 42 | + * @since 0.0.1 | |
| 43 | + */ | |
| 44 | + public function init($end = 'frontend'){ | |
| 45 | + if('frontend' === $end){ | |
| 38 | 46 | add_action('wp_enqueue_scripts', array($this, 'handle_scripts_and_styles_frontend')); |
| 39 | 47 | } |
| 40 | 48 | } |
| 41 | 49 | |
| 42 | - /** | |
| 43 | - * Enqueue scripts and styles | |
| 44 | - * | |
| 45 | - * @since 0.0.1 | |
| 46 | - */ | |
| 47 | - public function handle_scripts_and_styles() { | |
| 48 | - $menu_slugs = $this->better_payment_menu_slugs(); | |
| 49 | - | |
| 50 | - if (!empty($_REQUEST['page']) && in_array($_REQUEST['page'], $menu_slugs)) { | |
| 51 | - $this->enqueue_styles(); | |
| 52 | - $this->enqueue_scripts(); | |
| 53 | - } | |
| 54 | - } | |
| 55 | - | |
| 56 | 50 | /** |
| 57 | 51 | * Enqueue scripts and styles |
| 58 | - * | |
| 52 | + * | |
| 59 | 53 | * @since 0.0.1 |
| 60 | 54 | */ |
| 61 | 55 | public function handle_scripts_and_styles_frontend() { |
| 62 | 56 | wp_enqueue_style('toastr-css'); |
| 63 | - | |
| 57 | + | |
| 64 | 58 | wp_enqueue_script('toastr-js'); |
| 65 | 59 | wp_enqueue_script('better-payment-script'); |
| 66 | 60 | wp_enqueue_script('bp-admin-settings'); |
| 67 | 61 | wp_enqueue_script('better-payment-common-script'); |
| 68 | - wp_enqueue_script('better-payment-select2-script'); | |
| 69 | - wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 70 | 62 | } |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Enqueue scripts | |
| 74 | - * | |
| 75 | - * @since 0.0.1 | |
| 76 | - */ | |
| 77 | - public function enqueue_scripts() { | |
| 78 | - wp_enqueue_script( 'bp-admin-settings' ); | |
| 79 | - wp_enqueue_script( 'toastr-js-admin' ); | |
| 80 | - wp_enqueue_script( 'sweetalert2-js' ); | |
| 81 | - wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 82 | - wp_enqueue_script( 'better-payment-common-script' ); | |
| 83 | - do_action('better_payment/admin/after_enqueue_scripts'); | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * Enqueue styles | |
| 88 | - * | |
| 89 | - * @since 0.0.1 | |
| 90 | - */ | |
| 91 | - public function enqueue_styles() { | |
| 92 | - wp_enqueue_style( 'jquery-ui' ); | |
| 93 | - wp_enqueue_style( 'better-payment-common-style' ); | |
| 94 | - wp_enqueue_style( 'bp-settings-style' ); | |
| 95 | - wp_enqueue_style( 'bp-icon-admin' ); | |
| 96 | - wp_enqueue_style( 'toastr-css-admin' ); | |
| 97 | - wp_enqueue_style( 'sweetalert2-css' ); | |
| 98 | - wp_enqueue_style( 'better-payment-admin-style' ); | |
| 99 | - } | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * Menu slugs | |
| 103 | - * | |
| 104 | - * @since 0.0.1 | |
| 105 | - */ | |
| 106 | - public function better_payment_menu_slugs() { | |
| 107 | - $menu_slugs = array( | |
| 108 | - 'better-payment-settings', | |
| 109 | - 'better-payment-transactions', | |
| 110 | - ); | |
| 111 | - | |
| 112 | - if( ! $this->pro_enabled ){ | |
| 113 | - $menu_slugs[] = 'better-payment-analytics'; | |
| 114 | - } | |
| 115 | - | |
| 116 | - return apply_filters( 'better_payment/admin/get_page_menu_slug_list', $menu_slugs ); | |
| 117 | - } | |
| 118 | - | |
| 119 | -} | |
| 63 | +} | |