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