| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Essential functions. |
| 5 |
* |
| 6 |
* @package Merchant |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Get template part. |
| 15 |
* |
| 16 |
*/ |
| 17 |
function merchant_get_template_part( $folder_path = '', $name = '', $args = array(), $return_results = false ) { |
| 18 |
if ( ! empty( $args ) && is_array( $args ) ) { |
| 19 |
extract( $args ); |
| 20 |
} |
| 21 |
|
| 22 |
$folder_path = ! empty( $folder_path ) ? "/$folder_path/" : ''; |
| 23 |
|
| 24 |
$template = ''; |
| 25 |
|
| 26 |
// Look in yourtheme/merchant/folder-path/name.php and yourtheme/merchant/folder-path/name.php. |
| 27 |
if ( $name ) { |
| 28 |
$template = locate_template( array( "merchant{$folder_path}{$name}.php" ) ); |
| 29 |
} |
| 30 |
|
| 31 |
// Get default. |
| 32 |
if ( ! $template && $name ) { |
| 33 |
// Try to get it from the PRO dir if it exists. |
| 34 |
if ( defined( 'MERCHANT_PRO_DIR' ) && file_exists( MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php" ) ) { |
| 35 |
$template = MERCHANT_PRO_DIR . "templates{$folder_path}{$name}.php"; |
| 36 |
// Otherwise take it from the base dir. |
| 37 |
} elseif ( file_exists( MERCHANT_DIR . "templates{$folder_path}{$name}.php" ) ) { |
| 38 |
$template = MERCHANT_DIR . "templates{$folder_path}{$name}.php"; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Hook: 'merchant_get_template_part' |
| 44 |
* |
| 45 |
* @since 1.0 |
| 46 |
*/ |
| 47 |
$template = apply_filters( 'merchant_get_template_part', $template, $folder_path, $name ); |
| 48 |
|
| 49 |
|
| 50 |
if ( $template ) { |
| 51 |
// Whether to return template HTML as string or to echo it |
| 52 |
if ( $return_results ) { |
| 53 |
ob_start(); |
| 54 |
include( $template ); |
| 55 |
|
| 56 |
return ob_get_clean(); |
| 57 |
} |
| 58 |
|
| 59 |
return include( $template ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Check if Merchant Pro is installed and active. |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
if ( ! function_exists( 'merchant_is_pro_active' ) ) { |
| 69 |
function merchant_is_pro_active() { |
| 70 |
return defined( 'MERCHANT_PRO_VERSION' ); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Check if Botiga theme is installed and active. |
| 76 |
* |
| 77 |
* @return bool |
| 78 |
*/ |
| 79 |
if ( ! function_exists( 'merchant_is_botiga_active' ) ) { |
| 80 |
function merchant_is_botiga_active() { |
| 81 |
return defined( 'BOTIGA_VERSION' ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Check if Divi theme is installed and active. |
| 87 |
* |
| 88 |
* @return bool |
| 89 |
*/ |
| 90 |
if ( ! function_exists( 'merchant_is_divi_active' ) ) { |
| 91 |
function merchant_is_divi_active() { |
| 92 |
return defined( 'ET_CORE_VERSION' ); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Check if Avada theme is installed and active. |
| 98 |
* |
| 99 |
* @return bool |
| 100 |
*/ |
| 101 |
if ( ! function_exists( 'merchant_is_avada_active' ) ) { |
| 102 |
function merchant_is_avada_active() { |
| 103 |
return defined( 'AVADA_VERSION' ); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Check if Kadence theme is installed and active. |
| 109 |
* |
| 110 |
* @return bool |
| 111 |
*/ |
| 112 |
if ( ! function_exists( 'merchant_is_kadence_active' ) ) { |
| 113 |
function merchant_is_kadence_active() { |
| 114 |
return class_exists( '\Kadence\Theme' ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Check if OceanWP theme is installed and active. |
| 120 |
* |
| 121 |
* @return bool |
| 122 |
*/ |
| 123 |
if ( ! function_exists( 'merchant_is_oceanwp_active' ) ) { |
| 124 |
function merchant_is_oceanwp_active() { |
| 125 |
return class_exists( 'OCEANWP_Theme_Class' ); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Check if Blocksy theme is installed and active. |
| 131 |
* |
| 132 |
* @return bool |
| 133 |
*/ |
| 134 |
if ( ! function_exists( 'merchant_is_blocksy_active' ) ) { |
| 135 |
function merchant_is_blocksy_active() { |
| 136 |
return class_exists( 'Blocksy_Manager' ); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Check if Flatsome theme is installed and active. |
| 142 |
* |
| 143 |
* @return bool |
| 144 |
*/ |
| 145 |
if ( ! function_exists( 'merchant_is_flatsome_active' ) ) { |
| 146 |
function merchant_is_flatsome_active() { |
| 147 |
return class_exists( 'Flatsome' ); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Check if Astra theme or its Pro version is installed and active. |
| 153 |
* |
| 154 |
* @param $is_pro_active |
| 155 |
* |
| 156 |
* @return bool |
| 157 |
*/ |
| 158 |
if ( ! function_exists( 'merchant_is_astra_active' ) ) { |
| 159 |
function merchant_is_astra_active( $is_pro_active = false ) { |
| 160 |
if ( $is_pro_active ) { |
| 161 |
return function_exists( 'astra_has_pro_woocommerce_addon' ) && astra_has_pro_woocommerce_addon(); |
| 162 |
} |
| 163 |
|
| 164 |
return defined( 'ASTRA_THEME_VERSION' ); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Check if Storefront theme is installed and active. |
| 170 |
* |
| 171 |
* @return bool |
| 172 |
*/ |
| 173 |
if ( ! function_exists( 'merchant_is_storefront_active' ) ) { |
| 174 |
function merchant_is_storefront_active() { |
| 175 |
return class_exists( 'Storefront' ); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Check if WooCommerce Germanized theme is installed and active. |
| 181 |
* |
| 182 |
* @return bool |
| 183 |
*/ |
| 184 |
if ( ! function_exists( 'merchant_is_woocommerce_germanized_active' ) ) { |
| 185 |
function merchant_is_woocommerce_germanized_active() { |
| 186 |
return class_exists( 'WooCommerce_Germanized' ); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Check if Breakdance Builder is installed and active. |
| 192 |
* |
| 193 |
* @return bool |
| 194 |
*/ |
| 195 |
if ( ! function_exists( 'merchant_is_breakdance_active' ) ) { |
| 196 |
function merchant_is_breakdance_active() { |
| 197 |
return defined( '__BREAKDANCE_VERSION' ); |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Check if Brick Builder is installed and active. |
| 203 |
* |
| 204 |
* @return bool |
| 205 |
*/ |
| 206 |
if ( ! function_exists( 'merchant_is_bricks_builder_active' ) ) { |
| 207 |
function merchant_is_bricks_builder_active() { |
| 208 |
return defined( 'BRICKS_VERSION' ); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Check if Elementor or its Pro version is installed and active. |
| 214 |
* |
| 215 |
* @return bool |
| 216 |
*/ |
| 217 |
if ( ! function_exists( 'merchant_is_elementor_active' ) ) { |
| 218 |
function merchant_is_elementor_active( $is_pro_active = false ) { |
| 219 |
if ( $is_pro_active ) { |
| 220 |
return defined( 'ELEMENTOR_PRO_VERSION' ); |
| 221 |
} |
| 222 |
|
| 223 |
return defined( 'ELEMENTOR_VERSION' ); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Check if Ohio theme is installed and active. |
| 229 |
* |
| 230 |
* @return bool |
| 231 |
*/ |
| 232 |
if ( ! function_exists( 'merchant_is_ohio_active' ) ) { |
| 233 |
function merchant_is_ohio_active() { |
| 234 |
return function_exists( 'ohio_setup' ); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
if ( ! function_exists( 'merchant_supply_defaults' ) ) { |
| 239 |
/** |
| 240 |
* Recursively merge two arrays, preserving distinct values. |
| 241 |
* |
| 242 |
* Merges the provided arguments into the defaults recursively. If a key exists in both arrays |
| 243 |
* and both values are arrays, they are merged recursively. Otherwise, the value from the |
| 244 |
* arguments array overrides the default value. |
| 245 |
* |
| 246 |
* @param array $defaults The default array containing base values. |
| 247 |
* @param array $args The arguments array containing values to override or supplement defaults. |
| 248 |
* |
| 249 |
* @return array The merged array with defaults supplemented or overridden by arguments. |
| 250 |
*/ |
| 251 |
function merchant_supply_defaults( array $defaults, array $args ) { |
| 252 |
$merged = $defaults; |
| 253 |
foreach ( $args as $key => $value ) { |
| 254 |
if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) { |
| 255 |
$merged[ $key ] = merchant_supply_defaults( $merged[ $key ], $value ); |
| 256 |
} else { |
| 257 |
$merged[ $key ] = $value; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
return $merged; |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
if ( ! function_exists( 'merchant_admin_upgrade_link' ) ) { |
| 266 |
/** |
| 267 |
* Get the Merchant Pro upgrade link. |
| 268 |
* |
| 269 |
* @param string $url The base URL for the upgrade link. |
| 270 |
* @param array $args The arguments for the upgrade link. (Key-value pairs) |
| 271 |
* @param string $type The type of upgrade link. |
| 272 |
* |
| 273 |
* @return string The upgrade link. |
| 274 |
*/ |
| 275 |
function merchant_admin_upgrade_link( $url, $args = array(), $type = 'plugins-page-upgrade-link' ) { |
| 276 |
if ( ! empty( $args ) ) { |
| 277 |
$url = add_query_arg( $args, $url ); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Modify upgrade link. |
| 282 |
* |
| 283 |
* @param string $url The upgrade link URL. |
| 284 |
* @param string $type The type of upgrade link. |
| 285 |
* |
| 286 |
* @since 2.1.5 |
| 287 |
* |
| 288 |
*/ |
| 289 |
return apply_filters( 'merchant_upgrade_link', $url, $type ); |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
if ( ! function_exists( 'merchant_pro_is_active' ) ) { |
| 294 |
/** |
| 295 |
* Check if Merchant Pro is active. |
| 296 |
* |
| 297 |
* @return bool |
| 298 |
*/ |
| 299 |
function merchant_pro_is_active() { |
| 300 |
return defined( 'MERCHANT_PRO_VERSION' ); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
if ( ! function_exists( 'merchant_pro_license_exists' ) ) { |
| 305 |
/** |
| 306 |
* Check if Merchant Pro license exists. |
| 307 |
* |
| 308 |
* @return bool |
| 309 |
*/ |
| 310 |
function merchant_pro_license_exists() { |
| 311 |
return ! empty( get_option( 'merchant_pro_license_key' ) ); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
if ( ! function_exists( 'merchant_white_label_get_settings' ) ) { |
| 316 |
/** |
| 317 |
* Read the White Label settings stored by the aThemes White Label plugin. |
| 318 |
* |
| 319 |
* That option is the single source of truth, so values stay shared whether |
| 320 |
* they were saved from Merchant's settings or from the aThemes White Label plugin. |
| 321 |
* |
| 322 |
* @return array |
| 323 |
*/ |
| 324 |
function merchant_white_label_get_settings() { |
| 325 |
$settings = get_option( 'athemes_white_label_settings', array() ); |
| 326 |
|
| 327 |
return is_array( $settings ) ? $settings : array(); |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
if ( ! function_exists( 'merchant_white_label_is_available' ) ) { |
| 332 |
/** |
| 333 |
* Whether this site is entitled to White Label. |
| 334 |
* |
| 335 |
* False in the free plugin alone. Merchant Pro answers the filter with its |
| 336 |
* Agency-tier check, so the free plugin never calls into Pro. |
| 337 |
* |
| 338 |
* @return bool |
| 339 |
*/ |
| 340 |
function merchant_white_label_is_available() { |
| 341 |
/** |
| 342 |
* Filter White Label entitlement. |
| 343 |
* |
| 344 |
* @param bool $available Whether the site is entitled. |
| 345 |
* |
| 346 |
* @since 2.3.1 |
| 347 |
*/ |
| 348 |
return (bool) apply_filters( 'merchant_white_label_available', false ); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
if ( ! function_exists( 'merchant_white_label_switch_key' ) ) { |
| 353 |
/** |
| 354 |
* The key Merchant's own White Label switch is stored under. |
| 355 |
* |
| 356 |
* @return string |
| 357 |
*/ |
| 358 |
function merchant_white_label_switch_key() { |
| 359 |
return 'merchant_activate_white_label'; |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
if ( ! function_exists( 'merchant_white_label_is_switched_on' ) ) { |
| 364 |
/** |
| 365 |
* Whether Merchant's own White Label switch is on. |
| 366 |
* |
| 367 |
* @return bool |
| 368 |
*/ |
| 369 |
function merchant_white_label_is_switched_on() { |
| 370 |
$options = get_option( 'merchant', array() ); |
| 371 |
|
| 372 |
if ( ! is_array( $options ) || empty( $options['white-label'] ) || ! is_array( $options['white-label'] ) ) { |
| 373 |
return false; |
| 374 |
} |
| 375 |
|
| 376 |
return ! empty( $options['white-label'][ merchant_white_label_switch_key() ] ); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
if ( ! function_exists( 'merchant_white_label_plugin_is_switched_on' ) ) { |
| 381 |
/** |
| 382 |
* Whether the aThemes White Label plugin's own switch is on. |
| 383 |
* |
| 384 |
* Every aThemes product shares this key, so it only speaks for Merchant while |
| 385 |
* the aThemes White Label plugin is the one in charge. |
| 386 |
* |
| 387 |
* @return bool |
| 388 |
*/ |
| 389 |
function merchant_white_label_plugin_is_switched_on() { |
| 390 |
$settings = merchant_white_label_get_settings(); |
| 391 |
|
| 392 |
return ! empty( $settings['activate_white_label'] ); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
if ( ! function_exists( 'merchant_white_label_plugin_is_applying' ) ) { |
| 397 |
/** |
| 398 |
* Whether the aThemes White Label plugin is the one white-labelling this site. |
| 399 |
* |
| 400 |
* Installed is not enough: the plugin has to be switched on, and the shared |
| 401 |
* key alone proves nothing, since Botiga Pro writes it too. |
| 402 |
* |
| 403 |
* @return bool |
| 404 |
*/ |
| 405 |
function merchant_white_label_plugin_is_applying() { |
| 406 |
return merchant_white_label_plugin_available() && merchant_white_label_plugin_is_switched_on(); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
if ( ! function_exists( 'merchant_white_label_is_applied' ) ) { |
| 411 |
/** |
| 412 |
* Whether White Label is in effect for Merchant. |
| 413 |
* |
| 414 |
* Either switch is enough. The plugin's own switch forces it on whatever our |
| 415 |
* tier says, the way it always has; Merchant's switch answers for the rest, |
| 416 |
* entitlement included — so a site with the plugin merely installed and |
| 417 |
* switched off still gets to use the feature from here. |
| 418 |
* |
| 419 |
* @return bool |
| 420 |
*/ |
| 421 |
function merchant_white_label_is_applied() { |
| 422 |
if ( merchant_white_label_plugin_is_applying() ) { |
| 423 |
return true; |
| 424 |
} |
| 425 |
|
| 426 |
return merchant_white_label_is_switched_on() && merchant_white_label_is_available(); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
if ( ! function_exists( 'merchant_white_label_plugin_available' ) ) { |
| 431 |
/** |
| 432 |
* Whether the aThemes White Label plugin is installed. |
| 433 |
* |
| 434 |
* @return bool |
| 435 |
*/ |
| 436 |
function merchant_white_label_plugin_available() { |
| 437 |
return class_exists( 'aThemes_White_Label' ); |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* Check if any shortcode starts with merchant doesn't exist. |
| 443 |
* If the shortcode is not registered, register it with return null to guarantee it exists. |
| 444 |
*/ |
| 445 |
if ( ! function_exists( 'merchant_modules_shortcode_exists' ) ) { |
| 446 |
function merchant_modules_shortcode_exists() { |
| 447 |
/** |
| 448 |
* Filter the shortcodes. |
| 449 |
* |
| 450 |
* @param array $shortcodes modules shortcodes |
| 451 |
* |
| 452 |
* @since 1.8 |
| 453 |
*/ |
| 454 |
$shortcodes = apply_filters( 'merchant_modules_shortcodes', |
| 455 |
array( |
| 456 |
'merchant_module_stock_scarcity', |
| 457 |
'merchant_module_wait_list', |
| 458 |
'merchant_module_volume_discounts', |
| 459 |
'merchant_module_payment_logos', |
| 460 |
'merchant_module_cart_reserved_timer', |
| 461 |
'merchant_module_product_brand_image', |
| 462 |
'merchant_module_size_chart', |
| 463 |
'merchant_module_reasons_to_buy', |
| 464 |
'merchant_module_recently_viewed_products', |
| 465 |
'merchant_module_trust_badges', |
| 466 |
'merchant_module_advanced_reviews', |
| 467 |
'merchant_module_frequently_bought_together', |
| 468 |
'merchant_module_buy_x_get_y', |
| 469 |
'merchant_module_product_bundles', |
| 470 |
'merchant_module_quick_social_links', |
| 471 |
'merchant_module_product_navigation_links', |
| 472 |
'merchant_module_product_video', |
| 473 |
'merchant_module_product_audio', |
| 474 |
'merchant_module_countdown_timer', |
| 475 |
'merchant_module_product_labels', |
| 476 |
'merchant_module_wishlist', |
| 477 |
'merchant_module_clear_cart', |
| 478 |
'merchant_module_free_shipping_progress_bar_single_product_page', |
| 479 |
'merchant_module_free_shipping_progress_bar_cart_page', |
| 480 |
'merchant_module_free_shipping_progress_bar_checkout_page', |
| 481 |
'merchant_module_quick_view', |
| 482 |
'merchant_module_real_time_search', |
| 483 |
'merchant_reviews_carousel', |
| 484 |
'merchant_module_complementary_products', |
| 485 |
) |
| 486 |
); |
| 487 |
|
| 488 |
// Loop through the shortcodes and register them if they don't exist. |
| 489 |
array_map( static function ( $shortcode ) { |
| 490 |
if ( ! shortcode_exists( $shortcode ) ) { |
| 491 |
add_shortcode( $shortcode, '__return_null' ); |
| 492 |
} |
| 493 |
}, $shortcodes ); |
| 494 |
} |
| 495 |
} |
| 496 |
add_action( 'init', 'merchant_modules_shortcode_exists' ); |