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

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