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

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