PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
← All changes | admin/class-merchant-admin-loader.php +70 -21 1.10.42.3.2 View file →
@@ -33,8 +33,9 @@
33 33
34 34 $this->includes_not_hooked();
35 35
36 36 add_action( 'init', array( $this, 'includes' ) );
37 + add_action( 'plugins_loaded', array( $this, 'includes_after_plugins_loaded' ) );
37 38
38 39 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ) );
39 40 add_action( 'plugin_action_links_' . MERCHANT_BASE, array( $this, 'action_links' ) );
40 41 add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 999 );
@@ -40,8 +41,17 @@
40 41 add_filter( 'admin_body_class', array( $this, 'add_admin_body_class' ), 999 );
41 42 }
42 43
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 + /**
44 54 * No hooked includes.
45 55 * These files are included without any WordPress hook.
46 56 */
47 57 public function includes_not_hooked() {
@@ -58,13 +68,33 @@
58 68 require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice.php';
59 69 require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-review.php';
60 70 require_once MERCHANT_DIR . 'admin/notices/class-merchant-notice-upsell.php';
61 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';
62 73
74 + // Admin classes.
63 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 +
64 88 require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-options.php';
89 + require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-ajax.php';
65 90 require_once MERCHANT_DIR . 'admin/classes/class-merchant-admin-utils.php';
66 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';
67 97 }
68 98
69 99 /**
70 100 * Enqueue admin styles and scripts.
@@ -69,16 +99,22 @@
69 99 /**
70 100 * Enqueue admin styles and scripts.
71 101 */
72 102 public function enqueue_styles_scripts() {
73 -
74 - $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
103 + $section = sanitize_text_field( wp_unslash( $_GET['section'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
75 104
76 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' );
77 107
78 - wp_register_style( 'merchant-select2', MERCHANT_URI . 'assets/vendor/select2/select2.min.css', array(), '4.0.13' );
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() ) {
79 111
80 - if ( ! empty( $page ) && false !== strpos( $page, 'merchant' ) ) {
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 + }
81 117
82 118 wp_enqueue_media();
83 119
84 120 wp_enqueue_style( 'merchant-admin', MERCHANT_URI . 'assets/css/admin/admin.min.css', array(), MERCHANT_VERSION );
@@ -93,10 +129,12 @@
93 129
94 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 );
95 131
96 132 $localized_data = array(
97 - 'nonce' => wp_create_nonce( 'merchant' ),
98 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
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' ),
99 137 );
100 138
101 139 /**
102 140 * Hook 'merchant_admin_localize_script'
@@ -108,9 +146,9 @@
108 146 wp_localize_script( 'merchant-admin', 'merchant', $localized_data );
109 147
110 148 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
111 149
112 - if( !empty($module) ) {
150 + if ( ! empty( $module ) ) {
113 151 wp_enqueue_script( 'merchant-admin-preview', MERCHANT_URI . 'assets/js/admin/merchant-preview.min.js', array( 'jquery' ), MERCHANT_VERSION, true );
114 152 }
115 153 }
116 154 }
@@ -131,29 +169,40 @@
131 169
132 170 /**
133 171 * Add admin body class.
134 172 */
135 - public function add_admin_body_class( $classes ) {
136 - $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
137 - $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
173 + public function add_admin_body_class( $classes ) {
174 + if ( ! $this->is_merchant_screen() ) {
175 + return $classes;
176 + }
138 177
139 - if ( ! empty( $page ) && false !== strpos( $page, 'merchant' ) ) {
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
140 180
141 - if ( ! empty( $module ) ) {
181 + if ( ! empty( $module ) ) {
182 + return $classes . ' merchant-admin-page-module';
183 + }
142 184
143 - $classes .= ' merchant-admin-page-module';
185 + $section = $section ? 'merchant-admin-page__' . $section : 'merchant-admin-page__dashboard';
144 186
145 - } else {
187 + return $classes . ' merchant-admin-page ' . $section;
188 + }
146 189
147 - $classes .= ' merchant-admin-page';
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'] ) ) : '';
148 202
149 - }
150 -
151 - }
152 -
153 - return $classes;
203 + return 'merchant' === $page;
154 204 }
155 205 }
156 206
157 207 Merchant_Admin_Loader::instance();
158 -
159 208 }