| @@ -1,160 +1,208 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Merchant_Admin_Loader Class. | |
| 4 | - */ | |
| 5 | - | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 7 | - exit; // Exit if accessed directly | |
| 8 | -} | |
| 9 | - | |
| 10 | -if ( ! class_exists( 'Merchant_Admin_Loader' ) ) { | |
| 11 | - | |
| 12 | - class Merchant_Admin_Loader { | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * The single class instance. | |
| 16 | - */ | |
| 17 | - private static $instance = null; | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * Instance. | |
| 21 | - */ | |
| 22 | - public static function instance() { | |
| 23 | - if ( is_null( self::$instance ) ) { | |
| 24 | - self::$instance = new self(); | |
| 25 | - } | |
| 26 | - return self::$instance; | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * Constructor. | |
| 31 | - */ | |
| 32 | - public function __construct() { | |
| 33 | - | |
| 34 | - add_action( 'init', array( $this, 'includes' ) ); | |
| 35 | - | |
| 36 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ) ); | |
| 37 | - add_action( 'plugin_action_links_' . MERCHANT_BASE, array( $this, 'action_links' ) ); | |
| 38 | - add_filter( 'admin_footer_text', array( $this, 'add_admin_footer_text' ), 999 ); | |
| 39 | - add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 999 ); | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * Include admin classes. | |
| 44 | - */ | |
| 45 | - public function includes() { | |
| 46 | - | |
| 47 | - // Notices. | |
| 48 | - require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice.php'; | |
| 49 | - require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-review.php'; | |
| 50 | - require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-upsell.php'; | |
| 51 | - | |
| 52 | - require_once MERCHANT_DIR . 'inc/classes/class-merchant-svg-icons.php'; | |
| 53 | - require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-menu.php'; | |
| 54 | - require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-modules.php'; | |
| 55 | - require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-options.php'; | |
| 56 | - require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-utils.php'; | |
| 57 | - require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-preview.php'; | |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * Enqueue admin styles and scripts. | |
| 62 | - */ | |
| 63 | - public function enqueue_styles_scripts() { | |
| 64 | - | |
| 65 | - $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 66 | - | |
| 67 | - wp_register_script( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.full.min.js', array( 'jquery' ), '4.0.13', true ); | |
| 68 | - | |
| 69 | - wp_register_style( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.min.css', array(), '4.0.13' ); | |
| 70 | - | |
| 71 | - if ( ! empty( $page ) && false !== strpos( $page, 'merchant' ) ) { | |
| 72 | - | |
| 73 | - wp_enqueue_media(); | |
| 74 | - | |
| 75 | - wp_enqueue_style( 'merchant-admin', MERCHANT_URI . 'assets/css/admin/admin.min.css', array(), MERCHANT_VERSION ); | |
| 76 | - | |
| 77 | - wp_enqueue_script( 'merchant-jquery-form', MERCHANT_URI . 'assets/vendor/jquery-form/jquery.form.min.js', array( 'jquery' ), '4.3.0', true ); | |
| 78 | - | |
| 79 | - wp_enqueue_script( 'merchant-pickr', MERCHANT_URI . 'assets/vendor/pickr/pickr.min.js', array( 'jquery' ), '1.8.2', true ); | |
| 80 | - | |
| 81 | - wp_enqueue_script( 'merchant-admin', MERCHANT_URI . 'assets/js/admin/admin.min.js', array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-core', 'wp-util' ), MERCHANT_VERSION, true ); | |
| 82 | - | |
| 83 | - wp_localize_script( 'merchant-admin', 'merchant', array( | |
| 84 | - 'nonce' => wp_create_nonce( 'merchant' ), | |
| 85 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 86 | - ) ); | |
| 87 | - | |
| 88 | - $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 89 | - | |
| 90 | - if( !empty($module) ) { | |
| 91 | - wp_enqueue_script( 'merchant-admin-preview', MERCHANT_URI . 'assets/js/admin/merchant-preview.min.js', array( 'jquery' ), MERCHANT_VERSION, true ); | |
| 92 | - } | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * Add plugin settings link on the plugin page. | |
| 98 | - */ | |
| 99 | - public function action_links( $links ) { | |
| 100 | - | |
| 101 | - $page_url = add_query_arg( array( 'page' => 'merchant' ), admin_url( 'themes.php' ) ); | |
| 102 | - | |
| 103 | - $action_links = array( | |
| 104 | - 'settings' => '<a href="' . esc_url( $page_url ) . '">' . esc_html__( 'Settings', 'merchant' ) . '</a>', | |
| 105 | - ); | |
| 106 | - | |
| 107 | - return array_merge( $action_links, $links ); | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * Add plugin settings link on the plugin page. | |
| 112 | - */ | |
| 113 | - public function add_admin_footer_text( $text ) { | |
| 114 | - $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 115 | - $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 116 | - | |
| 117 | - if ( ! empty( $page ) && false !== strpos( $page, 'merchant' ) ) { | |
| 118 | - | |
| 119 | - $text = ''; | |
| 120 | - | |
| 121 | - if ( empty( $module ) ) { | |
| 122 | - | |
| 123 | - $text .= sprintf( '<a href="https://www.facebook.com/groups/245922400035997" target="_blank" class="merchant-admin-footer-text-link">%s</a>', esc_html__( 'Join our community', 'merchant' ) ); | |
| 124 | - $text .= esc_html__( 'to discuss about the product and ask for support or help the community.', 'merchant' ); | |
| 125 | - | |
| 126 | - } | |
| 127 | - | |
| 128 | - } | |
| 129 | - | |
| 130 | - return $text; | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * Add admin body class. | |
| 135 | - */ | |
| 136 | - public function add_admin_body_class( $classes ) { | |
| 137 | - $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 138 | - $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 139 | - | |
| 140 | - if ( ! empty( $page ) && false !== strpos( $page, 'merchant' ) ) { | |
| 141 | - | |
| 142 | - if ( ! empty( $module ) ) { | |
| 143 | - | |
| 144 | - $classes .= ' merchant-admin-page-module'; | |
| 145 | - | |
| 146 | - } else { | |
| 147 | - | |
| 148 | - $classes .= ' merchant-admin-page'; | |
| 149 | - | |
| 150 | - } | |
| 151 | - | |
| 152 | - } | |
| 153 | - | |
| 154 | - return $classes; | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | - Merchant_Admin_Loader::instance(); | |
| 159 | - | |
| 160 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Merchant_Admin_Loader Class. | |
| 4 | + */ | |
| 5 | + | |
| 6 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 7 | + exit; // Exit if accessed directly | |
| 8 | +} | |
| 9 | + | |
| 10 | +if ( ! class_exists( 'Merchant_Admin_Loader' ) ) { | |
| 11 | + | |
| 12 | + class Merchant_Admin_Loader { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * The single class instance. | |
| 16 | + */ | |
| 17 | + private static $instance = null; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * Instance. | |
| 21 | + */ | |
| 22 | + public static function instance() { | |
| 23 | + if ( is_null( self::$instance ) ) { | |
| 24 | + self::$instance = new self(); | |
| 25 | + } | |
| 26 | + return self::$instance; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Constructor. | |
| 31 | + */ | |
| 32 | + public function __construct() { | |
| 33 | + | |
| 34 | + $this->includes_not_hooked(); | |
| 35 | + | |
| 36 | + add_action( 'init', array( $this, 'includes' ) ); | |
| 37 | + add_action( 'plugins_loaded', array( $this, 'includes_after_plugins_loaded' ) ); | |
| 38 | + | |
| 39 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ) ); | |
| 40 | + add_action( 'plugin_action_links_' . MERCHANT_BASE, array( $this, 'action_links' ) ); | |
| 41 | + add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 999 ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Include files after plugins loaded. | |
| 46 | + * | |
| 47 | + * Before init hook. | |
| 48 | + */ | |
| 49 | + public function includes_after_plugins_loaded() { | |
| 50 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-statistics-tracking.php'; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * No hooked includes. | |
| 55 | + * These files are included without any WordPress hook. | |
| 56 | + */ | |
| 57 | + public function includes_not_hooked() { | |
| 58 | + require_once MERCHANT_DIR . 'inc/classes/class-merchant-svg-icons.php'; | |
| 59 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-modules.php'; | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Include admin classes. | |
| 64 | + */ | |
| 65 | + public function includes() { | |
| 66 | + | |
| 67 | + // Notices. | |
| 68 | + require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice.php'; | |
| 69 | + require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-review.php'; | |
| 70 | + require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-upsell.php'; | |
| 71 | + require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-campaign.php'; | |
| 72 | + require_once MERCHANT_DIR . 'admin/notices/class-merchant-patcher-eol-notice.php'; | |
| 73 | + | |
| 74 | + // Admin classes. | |
| 75 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-menu.php'; | |
| 76 | + | |
| 77 | + // Field architecture. | |
| 78 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/interface-merchant-field.php'; | |
| 79 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-abstract-field.php'; | |
| 80 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-field-registry.php'; | |
| 81 | + | |
| 82 | + // Extracted SRP classes. | |
| 83 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-admin-assets.php'; | |
| 84 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-select2-choices.php'; | |
| 85 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-settings-saver.php'; | |
| 86 | + require_once MERCHANT_DIR . 'admin/classes/admin-options/class-merchant-settings-renderer.php'; | |
| 87 | + | |
| 88 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-options.php'; | |
| 89 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-ajax.php'; | |
| 90 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-utils.php'; | |
| 91 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-preview.php'; | |
| 92 | + // Plugin installer. | |
| 93 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-plugin-installer.php'; | |
| 94 | + | |
| 95 | + // White Label settings section. | |
| 96 | + require_once MERCHANT_DIR . 'admin/classes/class-merchant-white-label-settings.php'; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * Enqueue admin styles and scripts. | |
| 101 | + */ | |
| 102 | + public function enqueue_styles_scripts() { | |
| 103 | + $section = sanitize_text_field( wp_unslash( $_GET['section'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 104 | + | |
| 105 | + wp_register_script( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.full.min.js', array( 'jquery' ), '4.0.13', true ); | |
| 106 | + wp_register_style( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.min.css', array(), '4.0.13' ); | |
| 107 | + | |
| 108 | + // Registering stays unconditional so other screens can enqueue the handles; the | |
| 109 | + // enqueues below are for Merchant's own screens only. | |
| 110 | + if ( $this->is_merchant_screen() ) { | |
| 111 | + | |
| 112 | + // For settings page only | |
| 113 | + if ( $section === 'settings' ) { | |
| 114 | + wp_enqueue_code_editor( array( 'type' => 'text/css' ) ); // No need to enqueue again for JS. It'll be handled by JS. | |
| 115 | + wp_enqueue_script( 'merchant-settings', MERCHANT_URI . 'assets/js/admin/settings.min.js', array( 'jquery', 'code-editor' ), MERCHANT_VERSION, true ); | |
| 116 | + } | |
| 117 | + | |
| 118 | + wp_enqueue_media(); | |
| 119 | + | |
| 120 | + wp_enqueue_style( 'merchant-admin', MERCHANT_URI . 'assets/css/admin/admin.min.css', array(), MERCHANT_VERSION ); | |
| 121 | + | |
| 122 | + if ( is_rtl() ) { | |
| 123 | + wp_enqueue_style( 'merchant-admin-rtl', MERCHANT_URI . 'assets/css/admin/admin-rtl.min.css', array(), MERCHANT_VERSION ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + wp_enqueue_script( 'merchant-jquery-form', MERCHANT_URI . 'assets/vendor/jquery-form/jquery.form.min.js', array( 'jquery' ), '4.3.0', true ); | |
| 127 | + | |
| 128 | + wp_enqueue_script( 'merchant-pickr', MERCHANT_URI . 'assets/vendor/pickr/pickr.min.js', array( 'jquery' ), '1.8.2', true ); | |
| 129 | + | |
| 130 | + wp_enqueue_script( 'merchant-admin', MERCHANT_URI . 'assets/js/admin/admin.min.js', array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-core', 'jquery-ui-accordion', 'wp-util' ), MERCHANT_VERSION, true ); | |
| 131 | + | |
| 132 | + $localized_data = array( | |
| 133 | + 'nonce' => wp_create_nonce( 'merchant' ), | |
| 134 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 135 | + 'ai_prompt_copy_hint' => esc_html__( 'Click to copy', 'merchant' ), | |
| 136 | + 'ai_prompt_copied_label' => esc_html__( 'Copied!', 'merchant' ), | |
| 137 | + ); | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Hook 'merchant_admin_localize_script' | |
| 141 | + * | |
| 142 | + * @since 1.9.6 | |
| 143 | + */ | |
| 144 | + $localized_data = apply_filters( 'merchant_admin_localize_script', $localized_data ); | |
| 145 | + | |
| 146 | + wp_localize_script( 'merchant-admin', 'merchant', $localized_data ); | |
| 147 | + | |
| 148 | + $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 149 | + | |
| 150 | + if ( ! empty( $module ) ) { | |
| 151 | + wp_enqueue_script( 'merchant-admin-preview', MERCHANT_URI . 'assets/js/admin/merchant-preview.min.js', array( 'jquery' ), MERCHANT_VERSION, true ); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * Add plugin settings link on the plugin page. | |
| 158 | + */ | |
| 159 | + public function action_links( $links ) { | |
| 160 | + | |
| 161 | + $page_url = add_query_arg( array( 'page' => 'merchant' ), admin_url( 'themes.php' ) ); | |
| 162 | + | |
| 163 | + $action_links = array( | |
| 164 | + 'settings' => '<a href="' . esc_url( $page_url ) . '">' . esc_html__( 'Settings', 'merchant' ) . '</a>', | |
| 165 | + ); | |
| 166 | + | |
| 167 | + return array_merge( $action_links, $links ); | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * Add admin body class. | |
| 172 | + */ | |
| 173 | + public function add_admin_body_class( $classes ) { | |
| 174 | + if ( ! $this->is_merchant_screen() ) { | |
| 175 | + return $classes; | |
| 176 | + } | |
| 177 | + | |
| 178 | + $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 179 | + $section = ( ! empty( $_GET['section'] ) ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 180 | + | |
| 181 | + if ( ! empty( $module ) ) { | |
| 182 | + return $classes . ' merchant-admin-page-module'; | |
| 183 | + } | |
| 184 | + | |
| 185 | + $section = $section ? 'merchant-admin-page__' . $section : 'merchant-admin-page__dashboard'; | |
| 186 | + | |
| 187 | + return $classes . ' merchant-admin-page ' . $section; | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Whether the screen being rendered is one of Merchant's own. | |
| 192 | + * | |
| 193 | + * Exact match, not a substring one: every Merchant screen arrives as | |
| 194 | + * `page=merchant`, and a substring match leaked the admin bundle onto foreign | |
| 195 | + * screens such as `page=merchant-delivery-calendar`, where it hid admin notices. | |
| 196 | + * | |
| 197 | + * @return bool | |
| 198 | + */ | |
| 199 | + private function is_merchant_screen() { | |
| 200 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 201 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; | |
| 202 | + | |
| 203 | + return 'merchant' === $page; | |
| 204 | + } | |
| 205 | + } | |
| 206 | + | |
| 207 | + Merchant_Admin_Loader::instance(); | |
| 208 | +} | |