| 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 Botiga theme is installed and active. |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
if ( ! function_exists( 'merchant_is_botiga_active' ) ) { |
| 69 |
function merchant_is_botiga_active() { |
| 70 |
return defined( 'BOTIGA_VERSION' ); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Check if Divi theme is installed and active. |
| 76 |
* |
| 77 |
* @return bool |
| 78 |
*/ |
| 79 |
if ( ! function_exists( 'merchant_is_divi_active' ) ) { |
| 80 |
function merchant_is_divi_active() { |
| 81 |
return defined( 'ET_CORE_VERSION' ); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Check if Avada theme is installed and active. |
| 87 |
* |
| 88 |
* @return bool |
| 89 |
*/ |
| 90 |
if ( ! function_exists( 'merchant_is_avada_active' ) ) { |
| 91 |
function merchant_is_avada_active() { |
| 92 |
return defined( 'AVADA_VERSION' ); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Check if Kadence theme is installed and active. |
| 98 |
* |
| 99 |
* @return bool |
| 100 |
*/ |
| 101 |
if ( ! function_exists( 'merchant_is_kadence_active' ) ) { |
| 102 |
function merchant_is_kadence_active() { |
| 103 |
return class_exists( '\Kadence\Theme' ); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Check if OceanWP theme is installed and active. |
| 109 |
* |
| 110 |
* @return bool |
| 111 |
*/ |
| 112 |
if ( ! function_exists( 'merchant_is_oceanwp_active' ) ) { |
| 113 |
function merchant_is_oceanwp_active() { |
| 114 |
return class_exists( 'OCEANWP_Theme_Class' ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Check if Blocksy theme is installed and active. |
| 120 |
* |
| 121 |
* @return bool |
| 122 |
*/ |
| 123 |
if ( ! function_exists( 'merchant_is_blocksy_active' ) ) { |
| 124 |
function merchant_is_blocksy_active() { |
| 125 |
return class_exists( 'Blocksy_Manager' ); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Check if any shortcode starts with merchant. |
| 131 |
* If the shortcode is not registered, register it with return null to guarantee it exists. |
| 132 |
*/ |
| 133 |
if ( ! function_exists( 'merchant_modules_shortcode_exists' ) ) { |
| 134 |
function merchant_modules_shortcode_exists() { |
| 135 |
/** |
| 136 |
* Filter the shortcodes. |
| 137 |
* |
| 138 |
* @param array $shortcodes modules shortcodes |
| 139 |
* |
| 140 |
* @since 1.8 |
| 141 |
*/ |
| 142 |
$shortcodes = apply_filters( 'merchant_modules_shortcodes', |
| 143 |
array( |
| 144 |
'merchant_module_stock_scarcity', |
| 145 |
'merchant_module_wait_list', |
| 146 |
'merchant_module_volume_discounts', |
| 147 |
'merchant_module_payment_logos', |
| 148 |
'merchant_module_cart_reserved_timer', |
| 149 |
'merchant_module_product_brand_image', |
| 150 |
'merchant_module_size_chart', |
| 151 |
'merchant_module_reasons_to_buy', |
| 152 |
'merchant_module_recently_viewed_products', |
| 153 |
'merchant_module_trust_badges', |
| 154 |
'merchant_module_advanced_reviews', |
| 155 |
'merchant_module_frequency_bought_together', |
| 156 |
'merchant_module_buy_x_get_y', |
| 157 |
) |
| 158 |
); |
| 159 |
|
| 160 |
// Loop through the shortcodes and register them if they don't exist. |
| 161 |
array_map( static function ( $shortcode ) { |
| 162 |
if ( ! shortcode_exists( $shortcode ) ) { |
| 163 |
add_shortcode( $shortcode, '__return_null' ); |
| 164 |
} |
| 165 |
}, $shortcodes ); |
| 166 |
} |
| 167 |
} |
| 168 |
add_action( 'init', 'merchant_modules_shortcode_exists' ); |