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

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