| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Includes\Builder; |
| 4 |
|
| 5 |
class Builder_Template_Helper { |
| 6 |
|
| 7 |
public static function isTemplateEditMode() { |
| 8 |
if (get_post_type() == Meta::POST_TYPE) { |
| 9 |
return true; |
| 10 |
} |
| 11 |
|
| 12 |
if (isset($_REQUEST[Meta::POST_TYPE])) { |
| 13 |
return true; |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
public static function separator() { |
| 18 |
return '|'; |
| 19 |
} |
| 20 |
|
| 21 |
public static function templates($single = false) { |
| 22 |
$shopItem = [ |
| 23 |
'shop' => 'Shop Page', |
| 24 |
'archive' => 'Archive Page', |
| 25 |
'single' => 'Single Page', |
| 26 |
'cart' => 'Cart Page', |
| 27 |
'checkout' => 'Checkout', |
| 28 |
'myaccount' => 'My Account', |
| 29 |
// 'wishlist' => 'Wishlist', |
| 30 |
]; |
| 31 |
|
| 32 |
if ($wcItems = WC()->query->get_query_vars()) { |
| 33 |
array_walk($wcItems, function ($item, $key) use (&$shopItem) { |
| 34 |
$shopItem[$key] = ucwords(str_replace('-', ' ', $key)); |
| 35 |
}); |
| 36 |
} |
| 37 |
|
| 38 |
$product = [ |
| 39 |
'product' => $shopItem, |
| 40 |
]; |
| 41 |
|
| 42 |
$templates = apply_filters( |
| 43 |
'ultimate_store_kit_builder_templates', |
| 44 |
$product |
| 45 |
); |
| 46 |
|
| 47 |
if ($single) { |
| 48 |
$separator = static::separator(); |
| 49 |
$return = []; |
| 50 |
if (is_array($templates) && !empty($templates)) { |
| 51 |
foreach ($templates as $keys => $items) { |
| 52 |
if (is_array($items)) { |
| 53 |
foreach ($items as $itemKey => $item) { |
| 54 |
$return["{$keys}{$separator}{$itemKey}"] = $item; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return apply_filters( |
| 61 |
'ultimate_store_kit_builder_all_templates', |
| 62 |
$return |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
return $templates; |
| 67 |
} |
| 68 |
|
| 69 |
public static function templateForSelectDropdown() { |
| 70 |
return static::templates(); |
| 71 |
} |
| 72 |
|
| 73 |
public static function getTemplateByIndex($index) { |
| 74 |
$index = trim($index); |
| 75 |
$templates = static::templates(true); |
| 76 |
|
| 77 |
return array_key_exists($index, $templates) ? $templates[$index] : false; |
| 78 |
} |
| 79 |
|
| 80 |
public static function getTemplatePostTypeByIndex($index) { |
| 81 |
$index = trim($index); |
| 82 |
if ($item = explode(static::separator(), $index)) { |
| 83 |
return get_post_type_object($item[0]); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
public static function is_elementor_active() { |
| 88 |
return did_action('elementor/loaded'); |
| 89 |
} |
| 90 |
|
| 91 |
public static function getTemplate($slug, $postType = false) { |
| 92 |
if (!$postType) { |
| 93 |
$postType = get_post_type(); |
| 94 |
} |
| 95 |
$separator = static::separator(); |
| 96 |
$template = strtolower("{$postType}{$separator}{$slug}"); |
| 97 |
$enabledTemplate = strtolower(Meta::TEMPLATE_ID . $template); |
| 98 |
|
| 99 |
return get_option($enabledTemplate); |
| 100 |
} |
| 101 |
|
| 102 |
public static function getTemplateId($templateType) { |
| 103 |
$metaIndex = strtolower(Meta::TEMPLATE_ID . $templateType); |
| 104 |
return intval(get_option($metaIndex)); |
| 105 |
} |
| 106 |
} |
| 107 |
|