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

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