PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.0
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.0
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
merchant / inc / class-merchant-loader.php

class-merchant-loader.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.0, at inc/class-merchant-loader.php

521 lines 15.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant_Loader Class.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly
8 }
9
10 if ( ! class_exists( 'Merchant_Loader' ) ) {
11 class Merchant_Loader {
12
13 /**
14 * The single class instance.
15 */
16 private static $instance = null;
17
18 /**
19 * Instance.
20 */
21 public static function instance() {
22 if ( is_null( self::$instance ) ) {
23 self::$instance = new self();
24 }
25
26 return self::$instance;
27 }
28
29 /**
30 * Constructor.
31 */
32 public function __construct() {
33 // Includes.
34 $this->includes();
35
36 // Register scripts.
37 add_action( 'wp_enqueue_scripts', array( $this, 'register_global_js_and_css' ) );
38
39 // Enqueue scripts.
40 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ) );
41
42 // Add identifier to body class.
43 add_filter( 'body_class', array( $this, 'add_body_class' ) );
44
45 // Add row meta to the plugin screen.
46 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
47
48 // Add settings link to the plugin screen.
49 add_filter( 'plugin_action_links_' . plugin_basename( MERCHANT_DIR . 'merchant.php' ), array( $this, 'settings_link' ) );
50
51 // WP Abilities API integration.
52 add_action( 'plugins_loaded', array( $this, 'load_abilities_bootstrap' ), 20 );
53 }
54
55 /**
56 * Include required classes.
57 */
58 public function includes() {
59
60 // Essential functions.
61 require_once MERCHANT_DIR . 'inc/functions.php';
62
63 // Helpers.
64 require_once MERCHANT_DIR . 'inc/helpers.php';
65
66 // Multi Language.
67 require_once MERCHANT_DIR . 'inc/MultiLang/interface-language-strategy.php';
68 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-no-plugin-support.php';
69 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-polylang-support.php';
70 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-wpml-support.php';
71 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-translator.php';
72
73 // Ajax callbacks.
74 require_once MERCHANT_DIR . 'inc/classes/class-merchant-ajax-callbacks.php';
75
76 // Core classes.
77 require_once MERCHANT_DIR . 'inc/classes/class-merchant-option.php';
78 require_once MERCHANT_DIR . 'inc/classes/class-merchant-modules.php';
79 require_once MERCHANT_DIR . 'inc/classes/class-merchant-custom-css.php';
80 require_once MERCHANT_DIR . 'inc/classes/class-merchant-svg-icons.php';
81 require_once MERCHANT_DIR . 'inc/classes/class-merchant-db-tables.php';
82 require_once MERCHANT_DIR . 'inc/classes/class-merchant-general-hooks.php';
83
84 // Metabox
85 require_once MERCHANT_DIR . 'inc/classes/class-merchant-metabox.php';
86
87 // The main class for adding modules.
88 require_once MERCHANT_DIR . 'inc/modules/class-add-module.php';
89
90 // Modules global settings.
91 require_once MERCHANT_DIR . 'inc/modules/global-settings/global-settings.php';
92
93 // Modules analytics
94 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-db-orm.php';
95 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-logger.php';
96 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-provider.php';
97 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-reports.php';
98 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-ajax.php';
99 require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-hooks.php';
100
101 // Usage Tracking.
102 require_once MERCHANT_DIR . 'inc/usage-tracking/class-merchant-usage-tracking.php';
103 require_once MERCHANT_DIR . 'inc/usage-tracking/class-merchant-send-usage-task.php';
104
105 /*
106 * Action Scheduler requires a special loading procedure.
107 * Load on plugins_loaded to ensure it's available before init.
108 *
109 * @since {VERSION}
110 */
111 add_action(
112 'plugins_loaded',
113 static function() {
114
115 //Check if Action Scheduler is already loaded.
116 if ( function_exists( 'as_schedule_recurring_action' ) ) {
117 return;
118 }
119
120 require_once MERCHANT_DIR . 'vendor/woocommerce/action-scheduler/action-scheduler.php';
121 },
122 );
123
124 // Modules (free and pro).
125 foreach ( Merchant_Admin_Modules::$modules_data as $module_id => $module_data ) {
126 if (
127 defined( 'MERCHANT_PRO_VERSION' )
128 && version_compare( MERCHANT_PRO_VERSION, '1.3', '<' )
129 && isset( $module_data['pro'] ) && $module_data['pro']
130 ) {
131 continue;
132 }
133
134 require_once MERCHANT_DIR . 'inc/modules/' . $module_id . '/class-' . $module_id . '.php';
135 }
136
137 // Compatibility Layer
138 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-botiga-theme.php';
139 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-divi-theme.php';
140 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-avada-theme.php';
141 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-astra-theme.php';
142 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-kadence-theme.php';
143 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-oceanwp-theme.php';
144 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-twenty-twenty-four-theme.php';
145 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-blocksy-theme.php';
146 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-flatsome-theme.php';
147 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-breakdance-builder.php';
148 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-elementor-builder.php';
149 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-bricks-builder.php';
150 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-woo-payments-plugin.php';
151 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-ohio-theme.php';
152 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-woo-multi-currency.php';
153
154 /**
155 * Hook 'merchant_admin_after_include_modules_classes'.
156 *
157 * @since 1.0
158 */
159 do_action( 'merchant_admin_after_include_modules_classes' );
160 }
161
162 /**
163 * Add to body class.
164 */
165 public function add_body_class( $classes ) {
166 $theme = wp_get_theme();
167 $theme = ( get_template_directory() !== get_stylesheet_directory() && $theme->parent() ) ? $theme->parent() : $theme;
168 $theme_name = str_replace( ' ', '-', $theme->name );
169
170 $classes[] = 'merchant-theme-' . strtolower( esc_attr( $theme_name ) );
171
172 return $classes;
173 }
174
175 /**
176 * Bootstrap the WP Abilities API integration.
177 *
178 * Only loads on WordPress 6.9+ where the Abilities API exists.
179 * Zero overhead on older WordPress versions.
180 *
181 * @since 2.3.0
182 */
183 public function load_abilities_bootstrap() {
184 if ( ! function_exists( 'wp_register_ability' ) ) {
185 return;
186 }
187
188 require_once MERCHANT_DIR . 'inc/abilities/class-merchant-abilities-bootstrap.php';
189 Merchant_Abilities_Bootstrap::init();
190 }
191
192 /**
193 * Show row meta on the plugin screen.
194 *
195 * @param mixed $links Plugin Row Meta.
196 * @param mixed $file Plugin Base file.
197 *
198 * @since 2.1.2
199 *
200 * @return array
201 */
202 public function plugin_row_meta($links, $file) {
203 if ( plugin_basename( MERCHANT_FILE ) !== $file ) {
204 return $links;
205 }
206
207 /**
208 * The Merchant documentation URL.
209 *
210 * @since 2.1.2
211 */
212 $docs_url = apply_filters( 'merchant_docs_url', 'https://docs.athemes.com/documentation/merchant/' );
213
214 /**
215 * The Merchant landing page URL.
216 *
217 * @since 2.1.2
218 */
219 $plugin_site = apply_filters( 'merchant_plugin_site_url', 'https://athemes.com/merchant/' );
220
221 /**
222 * The Merchant changelog URL.
223 *
224 * @since 2.1.2
225 */
226 $changelog = apply_filters( 'merchant_changelog_url', 'https://athemes.com/changelog/merchant/' );
227
228 $row_meta = array(
229 'docs' => '<a href="' . esc_url( $docs_url ) . '" aria-label="' . esc_attr__( 'View Merchant documentation', 'merchant' ) . '" target="_blank">' . esc_html__(
230 'Docs',
231 'merchant'
232 ) . '</a>',
233 'apidocs' => '<a href="' . esc_url( $plugin_site ) . '" aria-label="' . esc_attr__( 'View Merchant plugin site', 'merchant' ) . '" target="_blank">' . esc_html__(
234 'Visit plugin site',
235 'merchant' ) . '</a>',
236 'support' => '<a href="' . esc_url( $changelog ) . '" aria-label="' . esc_attr__( 'View Merchant changelog', 'merchant' ) . '" target="_blank">' . esc_html__( 'Changelog',
237 'merchant' ) . '</a>',
238 );
239
240 /**
241 * Filter the plugin row meta links.
242 *
243 * @since 2.1.2
244 *
245 * @param array $row_meta The plugin row meta links.
246 * @param string $file The plugin file.
247 */
248 $row_meta = apply_filters( 'merchant_plugin_row_meta', $row_meta, $file );
249
250 return array_merge( $links, $row_meta );
251 }
252
253 /**
254 * Add settings link to the Plugins page.
255 *
256 * @since 2.1.2
257 *
258 * @param array $links Plugin row links.
259 *
260 * @return array $links
261 */
262 public function settings_link( $links ) {
263 if ( ! merchant_pro_is_active() ) {
264 $url = merchant_admin_upgrade_link(
265 'https://athemes.com/merchant/#pricing',
266 array(),
267 'plugins-page-upgrade-link'
268 );
269 $links['merchant-pro'] = sprintf(
270 '<a href="%1$s" aria-label="%2$s" target="_blank" rel="noopener noreferrer"
271 style="color: #00a32a; font-weight: 700;"
272 onmouseover="this.style.color=\'#008a20\';"
273 onmouseout="this.style.color=\'#00a32a\';"
274 >%3$s</a>',
275 esc_url( $url ),
276 esc_attr__( 'Upgrade to Merchant Pro', 'merchant' ),
277 esc_html__( 'Get Merchant Pro', 'merchant' )
278 );
279 }
280
281 $custom['merchant-settings'] = sprintf(
282 '<a href="%s" aria-label="%s">%s</a>',
283 esc_url(
284 add_query_arg(
285 array(
286 'page' => 'merchant',
287 'section' => 'settings',
288 ),
289 admin_url( 'admin.php' )
290 )
291 ),
292 esc_attr__( 'Go to Merchant Settings page', 'merchant' ),
293 esc_html__( 'Settings', 'merchant' )
294 );
295
296 return array_merge( $custom, (array) $links );
297 }
298
299 /**
300 * Register scripts.
301 * Scripts that might be used by multiple modules should be registered here.
302 *
303 */
304 public function register_global_js_and_css() {
305 // Register styles.
306 $styles = array(
307
308 // Grid.
309 array(
310 'handle' => 'merchant-grid',
311 'src' => 'assets/css/grid.min.css',
312 'dep' => array(),
313 'ver' => MERCHANT_VERSION,
314 'media' => 'all',
315 ),
316
317 // Utilities.
318 array(
319 'handle' => 'merchant-utilities',
320 'src' => 'assets/css/utilities.min.css',
321 'dep' => array(),
322 'ver' => MERCHANT_VERSION,
323 'media' => 'all',
324 ),
325
326 // Carousel.
327 array(
328 'handle' => 'merchant-carousel',
329 'src' => 'assets/css/carousel.min.css',
330 'dep' => array(),
331 'ver' => MERCHANT_VERSION,
332 'media' => 'all',
333 ),
334
335 // Modal.
336 array(
337 'handle' => 'merchant-modal',
338 'src' => 'assets/css/modal.min.css',
339 'dep' => array(),
340 'ver' => MERCHANT_VERSION,
341 'media' => 'all',
342 ),
343
344 // Tooltip.
345 array(
346 'handle' => 'merchant-tooltip',
347 'src' => 'assets/css/tooltip.min.css',
348 'dep' => array(),
349 'ver' => MERCHANT_VERSION,
350 'media' => 'all',
351 ),
352
353 // Pagination.
354 array(
355 'handle' => 'merchant-pagination',
356 'src' => 'assets/css/pagination.min.css',
357 'dep' => array(),
358 'ver' => MERCHANT_VERSION,
359 'media' => 'all',
360 ),
361
362 );
363
364 foreach ( $styles as $style ) {
365 wp_register_style( $style['handle'], MERCHANT_URI . $style['src'], $style['dep'], $style['ver'], $style['media'] );
366 }
367
368 // Register scripts.
369 $scripts = array(
370
371 // Scroll Direction
372 array(
373 'handle' => 'merchant-scroll-direction',
374 'src' => 'assets/js/scroll-direction.min.js',
375 'dep' => array(),
376 'in_footer' => true,
377 ),
378
379 // Toggle Class
380 array(
381 'handle' => 'merchant-toggle-class',
382 'src' => 'assets/js/toggle-class.min.js',
383 'dep' => array(),
384 'in_footer' => true,
385 ),
386
387 // Scroll To
388 array(
389 'handle' => 'merchant-scroll-to',
390 'src' => 'assets/js/scroll-to.min.js',
391 'dep' => array(),
392 'in_footer' => true,
393 ),
394
395 // Custom Add To Cart Button
396 array(
397 'handle' => 'merchant-custom-addtocart-button',
398 'src' => 'assets/js/custom-addtocart-button.min.js',
399 'dep' => array(),
400 'in_footer' => true,
401 ),
402
403 // Carousel
404 array(
405 'handle' => 'merchant-carousel',
406 'src' => 'assets/js/carousel.min.js',
407 'dep' => array(),
408 'in_footer' => true,
409 ),
410
411 // Modal
412 array(
413 'handle' => 'merchant-modal',
414 'src' => 'assets/js/modal.min.js',
415 'dep' => array(),
416 'in_footer' => true,
417 ),
418
419 // Copy To Clipboard
420 array(
421 'handle' => 'merchant-copy-to-clipboard',
422 'src' => 'assets/js/copy-to-clipboard.min.js',
423 'dep' => array(),
424 'in_footer' => true,
425 'localize_script' => array(
426 'object' => 'merchantCopyToClipboard',
427 'data' => array(
428 'i18n' => array(
429 'copied' => esc_html__( 'Copied!', 'merchant' ),
430 ),
431 ),
432 ),
433 ),
434
435 // Pagination
436 array(
437 'handle' => 'merchant-pagination',
438 'src' => 'assets/js/pagination.min.js',
439 'dep' => array(),
440 'in_footer' => true,
441 ),
442 );
443
444 foreach ( $scripts as $script ) {
445 wp_register_script( $script['handle'], MERCHANT_URI . $script['src'], $script['dep'], MERCHANT_VERSION, $script['in_footer'] );
446
447 if ( isset( $script['localize_script'] ) ) {
448 wp_localize_script( $script['handle'], $script['localize_script']['object'], $script['localize_script']['data'] );
449 }
450 }
451 }
452
453 /**
454 * Enqueue styles and scripts.
455 */
456 public function enqueue_styles_scripts() {
457
458 /**
459 * Hook 'merchant_enqueue_before_main_css_js'
460 *
461 * @since 1.0
462 */
463 do_action( 'merchant_enqueue_before_main_css_js' );
464
465 wp_enqueue_style( 'merchant', MERCHANT_URI . 'assets/css/merchant.min.css', array(), MERCHANT_VERSION );
466 wp_enqueue_script( 'merchant', MERCHANT_URI . 'assets/js/merchant.min.js', array( 'jquery' ), MERCHANT_VERSION, true );
467
468 $setting = array(
469 'nonce' => wp_create_nonce( 'merchant-nonce' ),
470 'ajax_url' => admin_url( 'admin-ajax.php' ),
471 );
472
473 // Scroll to Top Button
474 // TODO: Move this to the respective module class.
475 if ( Merchant_Modules::is_module_active( 'scroll-to-top-button' ) ) {
476 $setting['scroll_to_top'] = true;
477 }
478
479 // Auto External Links
480 // TODO: Move this to the respective module class.
481 if ( Merchant_Modules::is_module_active( 'auto-external-links' ) ) {
482 $setting['auto_external_links'] = true;
483 }
484
485 // Cookie Banner
486 if ( Merchant_Modules::is_module_active( 'cookie-banner' ) ) {
487 $setting['cookie_banner'] = true;
488 $setting['cookie_banner_duration'] = Merchant_Admin_Options::get( 'cookie-banner', 'cookie_duration', 365 );
489 }
490
491 /**
492 * Hook 'merchant_enqueue_after_main_css_js'
493 *
494 * @since 1.0
495 */
496 do_action( 'merchant_enqueue_after_main_css_js' );
497
498 /**
499 * Hook 'merchant_localize_script'
500 *
501 * @since 1.0
502 */
503 $setting = apply_filters( 'merchant_localize_script', $setting );
504
505 wp_localize_script( 'merchant', 'merchant', array(
506 'general' => array(
507 'wooCurrencySymbol' => class_exists( 'Woocommerce' ) ? html_entity_decode( get_woocommerce_currency_symbol() ) : '',
508 'wooCurrencyPosition' => class_exists( 'Woocommerce' ) ? get_option( 'woocommerce_currency_pos' ) : 'left',
509 'wooThousandsSeparator' => class_exists( 'Woocommerce' ) ? wc_get_price_thousand_separator() : ',',
510 'wooDecimalSeparator' => class_exists( 'Woocommerce' ) ? wc_get_price_decimal_separator() : '.',
511 'wooNumberOfDecimals' => class_exists( 'Woocommerce' ) ? wc_get_price_decimals() : 2,
512
513 ),
514 'setting' => $setting,
515 ) );
516 }
517 }
518
519 Merchant_Loader::instance();
520 }
521