PluginProbe
Ultimate Store Kit / 3.0.9
Ultimate Store Kit v3.0.9
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / includes / builder / builder-template-helper.php

builder-template-helper.php in Ultimate Store Kit 3.0.9, at includes/builder/builder-template-helper.php

140 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $shop_item = [
23 'shop' => 'Shop Page',
24 'archive' => 'Archive Page',
25 'single' => 'Single Page',
26 'category' => 'Category Page',
27 'tag' => 'Tag Page',
28 'cart' => 'Cart Page',
29 'checkout' => 'Checkout',
30 'order-received' => 'Order Received',
31 ];
32
33 $my_account = [
34 'login' => 'Login & Register',
35 'myaccount' => 'Dashboard',
36 'orders' => 'Orders',
37 'downloads' => 'Downloads',
38 'edit-address' => 'Address',
39 'edit-account' => 'Account Details',
40 'wishlist' => 'Wishlist',
41 'logout' => 'Customer Logout',
42 ];
43
44 // Endpoints that belong to the order/checkout flow rather than the
45 // authenticated account area. Everything else from WC()->query is treated
46 // as an account screen so the dropdown grouping matches the routing in
47 // Builder_Integration::setFrontendTemplate(), which looks endpoint
48 // templates up under the `account` post-type group.
49 $order_flow_endpoints = apply_filters(
50 'ultimate_store_kit_builder_order_flow_endpoints',
51 [ 'order-pay', 'order-received' ]
52 );
53
54 if ( $wcItems = WC()->query->get_query_vars() ) {
55 foreach ( $wcItems as $key => $item ) {
56 $label = ucwords( str_replace( '-', ' ', $key ) );
57 if ( in_array( $key, $order_flow_endpoints, true ) ) {
58 $shop_item[ $key ] = $label;
59 } else {
60 $my_account[ $key ] = $label;
61 }
62 }
63 }
64
65 $product = [
66 'product' => $shop_item,
67 'account' => $my_account,
68 ];
69
70 $templates = apply_filters(
71 'ultimate_store_kit_builder_templates',
72 $product
73 );
74
75 if ( $single ) {
76 $separator = static::separator();
77 $return = [];
78 if ( is_array( $templates ) && ! empty( $templates ) ) {
79 foreach ( $templates as $keys => $items ) {
80 if ( is_array( $items ) ) {
81 foreach ( $items as $itemKey => $item ) {
82 $return[ "{$keys}{$separator}{$itemKey}" ] = $item;
83 }
84 }
85 }
86 }
87
88 return apply_filters(
89 'ultimate_store_kit_builder_all_templates',
90 $return
91 );
92 }
93
94 return $templates;
95 }
96
97 public static function templateForSelectDropdown() {
98 return static::templates();
99 }
100
101 public static function getTemplateByIndex( $index ) {
102 $index = trim( $index );
103 $templates = static::templates( true );
104
105 return array_key_exists( $index, $templates ) ? $templates[ $index ] : false;
106 }
107
108 public static function getTemplatePostTypeByIndex( $index ) {
109 $index = trim( $index );
110 if ( $item = explode( static::separator(), $index ) ) {
111 return get_post_type_object( $item[0] );
112 }
113 }
114
115 public static function is_elementor_active() {
116 return did_action( 'elementor/loaded' );
117 }
118
119 public static function getTemplate( $slug, $postType = false ) {
120 if ( ! $postType ) {
121 $postType = get_post_type();
122 }
123
124 $separator = static::separator();
125 $template = strtolower( "{$postType}{$separator}{$slug}" );
126 $enabledTemplate = strtolower( Meta::TEMPLATE_ID . $template );
127
128 /**
129 * important area for debugging
130 */
131
132 return get_option( $enabledTemplate );
133 }
134
135 public static function getTemplateId( $templateType ) {
136 $metaIndex = strtolower( Meta::TEMPLATE_ID . $templateType );
137 return intval( get_option( $metaIndex ) );
138 }
139 }
140