| 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 = 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 |
|
| 37 |
// Otherwise take it from the base dir. |
| 38 |
} elseif ( file_exists( MERCHANT_DIR . "templates{$folder_path}{$name}.php" ) ) { |
| 39 |
$template = MERCHANT_DIR . "templates{$folder_path}{$name}.php"; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Hook: 'merchant_get_template_part' |
| 45 |
* |
| 46 |
* @since 1.0 |
| 47 |
*/ |
| 48 |
$template = apply_filters( 'merchant_get_template_part', $template, $folder_path, $name ); |
| 49 |
|
| 50 |
|
| 51 |
if ( $template ) { |
| 52 |
// Whether to return template HTML as string or to echo it |
| 53 |
if ( $return ) { |
| 54 |
ob_start(); |
| 55 |
include( $template ); |
| 56 |
|
| 57 |
return ob_get_clean(); |
| 58 |
} else { |
| 59 |
return include( $template ); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Check if Kadence theme is installed and active. |
| 66 |
* |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
if ( ! function_exists( 'merchant_is_kadence_active' ) ) { |
| 70 |
function merchant_is_kadence_active() { |
| 71 |
return class_exists( '\Kadence\Theme' ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Check if OceanWP theme is installed and active. |
| 77 |
* |
| 78 |
* @return bool |
| 79 |
*/ |
| 80 |
if ( ! function_exists( 'merchant_is_oceanwp_active' ) ) { |
| 81 |
function merchant_is_oceanwp_active() { |
| 82 |
return class_exists( 'OCEANWP_Theme_Class' ); |
| 83 |
} |
| 84 |
} |
| 85 |
|