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

375 lines 12.4 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
46 /**
47 * Include required classes.
48 */
49 public function includes() {
50 // Essential functions.
51 require_once MERCHANT_DIR . 'inc/functions.php';
52
53 // Helpers.
54 require_once MERCHANT_DIR . 'inc/helpers.php';
55
56 // Multi Language.
57 require_once MERCHANT_DIR . 'inc/MultiLang/interface-language-strategy.php';
58 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-no-plugin-support.php';
59 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-polylang-support.php';
60 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-wpml-support.php';
61 require_once MERCHANT_DIR . 'inc/MultiLang/class-merchant-translator.php';
62
63 // Ajax callbacks.
64 require_once MERCHANT_DIR . 'inc/classes/class-merchant-ajax-callbacks.php';
65
66 // Core classes.
67 require_once MERCHANT_DIR . 'inc/classes/class-merchant-option.php';
68 require_once MERCHANT_DIR . 'inc/classes/class-merchant-modules.php';
69 require_once MERCHANT_DIR . 'inc/classes/class-merchant-custom-css.php';
70 require_once MERCHANT_DIR . 'inc/classes/class-merchant-svg-icons.php';
71
72 // Metabox
73 require_once MERCHANT_DIR . 'inc/classes/class-merchant-metabox.php';
74
75 // The main class for adding modules.
76 require_once MERCHANT_DIR . 'inc/modules/class-add-module.php';
77
78 // Modules global settings.
79 require_once MERCHANT_DIR . 'inc/modules/global-settings/global-settings.php';
80 require_once MERCHANT_DIR . 'inc/modules/buy-now/class-buy-now.php';
81 require_once MERCHANT_DIR . 'inc/modules/animated-add-to-cart/class-animated-add-to-cart.php';
82 require_once MERCHANT_DIR . 'inc/modules/quick-view/class-quick-view.php';
83 require_once MERCHANT_DIR . 'inc/modules/product-labels/class-product-labels.php';
84 require_once MERCHANT_DIR . 'inc/modules/add-to-cart-text/class-add-to-cart-text.php';
85 require_once MERCHANT_DIR . 'inc/modules/pre-orders/class-pre-orders.php';
86 require_once MERCHANT_DIR . 'inc/modules/cart-count-favicon/class-cart-count-favicon.php';
87 require_once MERCHANT_DIR . 'inc/modules/inactive-tab-message/class-inactive-tab-message.php';
88 require_once MERCHANT_DIR . 'inc/modules/payment-logos/class-payment-logos.php';
89 require_once MERCHANT_DIR . 'inc/modules/trust-badges/class-trust-badges.php';
90 require_once MERCHANT_DIR . 'inc/modules/auto-external-links/class-auto-external-links.php';
91 require_once MERCHANT_DIR . 'inc/modules/real-time-search/class-real-time-search.php';
92 require_once MERCHANT_DIR . 'inc/modules/code-snippets/class-code-snippets.php';
93 require_once MERCHANT_DIR . 'inc/modules/scroll-to-top-button/class-scroll-to-top-button.php';
94 require_once MERCHANT_DIR . 'inc/modules/agree-to-terms-checkbox/class-agree-to-terms-checkbox.php';
95 require_once MERCHANT_DIR . 'inc/modules/cookie-banner/class-cookie-banner.php';
96 require_once MERCHANT_DIR . 'inc/modules/address-autocomplete/class-address-autocomplete.php';
97 require_once MERCHANT_DIR . 'inc/modules/product-bundles/class-product-bundles.php';
98
99 // Modules (free and pro).
100 foreach ( Merchant_Admin_Modules::$modules_data as $module_id => $module_data ) {
101 if ( defined( 'MERCHANT_PRO_VERSION' ) && (float) MERCHANT_PRO_VERSION < 1.3 && isset( $module_data['pro'] ) && $module_data['pro'] ) {
102 continue;
103 }
104
105 require_once MERCHANT_DIR . 'inc/modules/' . $module_id . '/class-' . $module_id . '.php';
106 }
107
108 // Compatibility Layer
109 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-botiga-theme.php';
110 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-divi-theme.php';
111 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-avada-theme.php';
112 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-kadence-theme.php';
113 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-oceanwp-theme.php';
114 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-twenty-twenty-four-theme.php';
115 require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-blocksy-theme.php';
116
117 /**
118 * Hook 'merchant_admin_after_include_modules_classes'.
119 *
120 * @since 1.0
121 */
122 do_action( 'merchant_admin_after_include_modules_classes' );
123 }
124
125 /**
126 * Add to body class.
127 */
128 public function add_body_class( $classes ) {
129 $theme = wp_get_theme();
130 $theme = ( get_template_directory() !== get_stylesheet_directory() && $theme->parent() ) ? $theme->parent() : $theme;
131
132 $classes[] = 'merchant-theme-' . strtolower( esc_attr( $theme->name ) );
133
134 return $classes;
135 }
136
137 /**
138 * Register scripts.
139 * Scripts that might be used by multiple modules should be registered here.
140 *
141 */
142 public function register_global_js_and_css() {
143 // Register styles.
144 $styles = array(
145
146 // Grid.
147 array(
148 'handle' => 'merchant-grid',
149 'src' => 'assets/css/grid.min.css',
150 'dep' => array(),
151 'ver' => MERCHANT_VERSION,
152 'media' => 'all',
153 ),
154
155 // Utilities.
156 array(
157 'handle' => 'merchant-utilities',
158 'src' => 'assets/css/utilities.min.css',
159 'dep' => array(),
160 'ver' => MERCHANT_VERSION,
161 'media' => 'all',
162 ),
163
164 // Carousel.
165 array(
166 'handle' => 'merchant-carousel',
167 'src' => 'assets/css/carousel.min.css',
168 'dep' => array(),
169 'ver' => MERCHANT_VERSION,
170 'media' => 'all',
171 ),
172
173 // Modal.
174 array(
175 'handle' => 'merchant-modal',
176 'src' => 'assets/css/modal.min.css',
177 'dep' => array(),
178 'ver' => MERCHANT_VERSION,
179 'media' => 'all',
180 ),
181
182 // Tooltip.
183 array(
184 'handle' => 'merchant-tooltip',
185 'src' => 'assets/css/tooltip.min.css',
186 'dep' => array(),
187 'ver' => MERCHANT_VERSION,
188 'media' => 'all',
189 ),
190
191 // Pagination.
192 array(
193 'handle' => 'merchant-pagination',
194 'src' => 'assets/css/pagination.min.css',
195 'dep' => array(),
196 'ver' => MERCHANT_VERSION,
197 'media' => 'all',
198 ),
199
200 );
201
202 foreach ( $styles as $style ) {
203 wp_register_style( $style['handle'], MERCHANT_URI . $style['src'], $style['dep'], $style['ver'], $style['media'] );
204 }
205
206 // Register scripts.
207 $scripts = array(
208
209 // Scroll Direction
210 array(
211 'handle' => 'merchant-scroll-direction',
212 'src' => 'assets/js/scroll-direction.min.js',
213 'dep' => array(),
214 'in_footer' => true,
215 ),
216
217 // Toggle Class
218 array(
219 'handle' => 'merchant-toggle-class',
220 'src' => 'assets/js/toggle-class.min.js',
221 'dep' => array(),
222 'in_footer' => true,
223 ),
224
225 // Scroll To
226 array(
227 'handle' => 'merchant-scroll-to',
228 'src' => 'assets/js/scroll-to.min.js',
229 'dep' => array(),
230 'in_footer' => true,
231 ),
232
233 // Custom Add To Cart Button
234 array(
235 'handle' => 'merchant-custom-addtocart-button',
236 'src' => 'assets/js/custom-addtocart-button.min.js',
237 'dep' => array(),
238 'in_footer' => true,
239 ),
240
241 // Carousel
242 array(
243 'handle' => 'merchant-carousel',
244 'src' => 'assets/js/carousel.min.js',
245 'dep' => array(),
246 'in_footer' => true,
247 ),
248
249 // Modal
250 array(
251 'handle' => 'merchant-modal',
252 'src' => 'assets/js/modal.min.js',
253 'dep' => array(),
254 'in_footer' => true,
255 ),
256
257 // Copy To Clipboard
258 array(
259 'handle' => 'merchant-copy-to-clipboard',
260 'src' => 'assets/js/copy-to-clipboard.min.js',
261 'dep' => array(),
262 'in_footer' => true,
263 'localize_script' => array(
264 'object' => 'merchantCopyToClipboard',
265 'data' => array(
266 'i18n' => array(
267 'copied' => esc_html__( 'Copied!', 'merchant' ),
268 ),
269 ),
270 ),
271 ),
272
273 // Pagination
274 array(
275 'handle' => 'merchant-pagination',
276 'src' => 'assets/js/pagination.min.js',
277 'dep' => array(),
278 'in_footer' => true,
279 ),
280 );
281
282 foreach ( $scripts as $script ) {
283 wp_register_script( $script['handle'], MERCHANT_URI . $script['src'], $script['dep'], MERCHANT_VERSION, $script['in_footer'] );
284
285 if ( isset( $script['localize_script'] ) ) {
286 wp_localize_script( $script['handle'], $script['localize_script']['object'], $script['localize_script']['data'] );
287 }
288 }
289 }
290
291 /**
292 * Enqueue styles and scripts.
293 */
294 public function enqueue_styles_scripts() {
295
296 /**
297 * Hook 'merchant_enqueue_before_main_css_js'
298 *
299 * @since 1.0
300 */
301 do_action( 'merchant_enqueue_before_main_css_js' );
302
303 wp_enqueue_style( 'merchant', MERCHANT_URI . 'assets/css/merchant.min.css', array(), MERCHANT_VERSION );
304 wp_enqueue_script( 'merchant', MERCHANT_URI . 'assets/js/merchant.min.js', array( 'jquery' ), MERCHANT_VERSION, true );
305
306 $setting = array(
307 'nonce' => wp_create_nonce( 'merchant-nonce' ),
308 'ajax_url' => admin_url( 'admin-ajax.php' ),
309 );
310
311 // Scroll to Top Button
312 // TODO: Move this to the respective module class.
313 if ( Merchant_Modules::is_module_active( 'scroll-to-top-button' ) ) {
314 $setting['scroll_to_top'] = true;
315 }
316
317 // Animated Add to Cart
318 // TODO: Move this to the respective module class.
319 if ( Merchant_Modules::is_module_active( 'animated-add-to-cart' ) ) {
320 $trigger = Merchant_Admin_Options::get( 'animated-add-to-cart', 'trigger', 'on-mouse-hover' );
321
322 if ( 'on-page-load' === $trigger ) {
323 wp_enqueue_script( 'merchant-animated-add-to-cart', MERCHANT_URI . 'assets/js/modules/animated-add-to-cart.js', array( 'merchant' ), MERCHANT_VERSION, true );
324 }
325 }
326
327 // Auto External Links
328 // TODO: Move this to the respective module class.
329 if ( Merchant_Modules::is_module_active( 'auto-external-links' ) ) {
330 $setting['auto_external_links'] = true;
331 }
332
333 // Cookie Banner
334 if ( Merchant_Modules::is_module_active( 'cookie-banner' ) ) {
335 $setting['cookie_banner'] = true;
336 $setting['cookie_banner_duration'] = Merchant_Admin_Options::get( 'cookie-banner', 'cookie_duration', 365 );
337 }
338
339 // Real Time Search
340 // TODO: Move this to the respective module class.
341 if ( Merchant_Modules::is_module_active( 'real-time-search' ) ) {
342 $setting['ajax_search'] = true;
343 $setting['ajax_search_results_amounth_per_search'] = Merchant_Admin_Options::get( 'real-time-search', 'results_amounth_per_search', 15 );
344 $setting['ajax_search_results_order_by'] = Merchant_Admin_Options::get( 'real-time-search', 'results_order_by', 'title' );
345 $setting['ajax_search_results_order'] = Merchant_Admin_Options::get( 'real-time-search', 'results_order', 'asc' );
346 $setting['ajax_search_results_display_categories'] = Merchant_Admin_Options::get( 'real-time-search', 'display_categories', 0 );
347 $setting['ajax_search_results_enable_search_by_sku'] = Merchant_Admin_Options::get( 'real-time-search', 'enable_search_by_sku', 0 );
348 }
349
350 /**
351 * Hook 'merchant_enqueue_after_main_css_js'
352 *
353 * @since 1.0
354 */
355 do_action( 'merchant_enqueue_after_main_css_js' );
356
357 /**
358 * Hook 'merchant_localize_script'
359 *
360 * @since 1.0
361 */
362 $setting = apply_filters( 'merchant_localize_script', $setting );
363
364 wp_localize_script( 'merchant', 'merchant', array(
365 'general' => array(
366 'wooCurrencySymbol' => class_exists( 'Woocommerce' ) ? html_entity_decode( get_woocommerce_currency_symbol() ) : '',
367 ),
368 'setting' => $setting,
369 ) );
370 }
371 }
372
373 Merchant_Loader::instance();
374 }
375