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

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