PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.1.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.1.4
3.1.4 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 All 93 releases
← All changes | includes/builder/builder-template-helper.php +120 -82 1.6.43.1.4 View file →
@@ -1,106 +1,144 @@
1 1 <?php
2 2
3 3 namespace UltimateStoreKit\Includes\Builder;
4 4
5 +if (! defined('ABSPATH')) {
6 + exit; // Exit if accessed directly
7 +}
8 +
5 9 class Builder_Template_Helper {
6 10
7 - public static function isTemplateEditMode() {
8 - if (get_post_type() == Meta::POST_TYPE) {
9 - return true;
10 - }
11 + public static function isTemplateEditMode() {
12 + if ( get_post_type() == Meta::POST_TYPE ) {
13 + return true;
14 + }
11 15
12 - if (isset($_REQUEST[Meta::POST_TYPE])) {
13 - return true;
14 - }
15 - }
16 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check on whether a builder template is being edited.
17 + if ( isset( $_REQUEST[ Meta::POST_TYPE ] ) ) {
18 + return true;
19 + }
20 + }
16 21
17 - public static function separator() {
18 - return '|';
19 - }
22 + public static function separator() {
23 + return '|';
24 + }
20 25
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 - ];
26 + public static function templates( $single = false ) {
27 + $shop_item = [
28 + 'shop' => 'Shop Page',
29 + 'archive' => 'Archive Page',
30 + 'single' => 'Single Page',
31 + 'category' => 'Category Page',
32 + 'tag' => 'Tag Page',
33 + 'cart' => 'Cart Page',
34 + 'checkout' => 'Checkout',
35 + 'order-received' => 'Order Received (Thank You Page)',
36 + ];
31 37
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 - }
38 + $my_account = [
39 + 'login' => 'Login & Register',
40 + 'myaccount' => 'Dashboard',
41 + 'orders' => 'Orders',
42 + 'downloads' => 'Downloads',
43 + 'edit-address' => 'Address',
44 + 'edit-account' => 'Account Details',
45 + 'wishlist' => 'Wishlist',
46 + 'logout' => 'Customer Logout',
47 + ];
37 48
38 - $product = [
39 - 'product' => $shopItem,
40 - ];
49 + // Endpoints that belong to the order/checkout flow rather than the
50 + // authenticated account area. Everything else from WC()->query is treated
51 + // as an account screen so the dropdown grouping matches the routing in
52 + // Builder_Integration::setFrontendTemplate(), which looks endpoint
53 + // templates up under the `account` post-type group.
54 + $order_flow_endpoints = apply_filters(
55 + 'ultimate_store_kit_builder_order_flow_endpoints',
56 + [ 'order-pay', 'order-received' ]
57 + );
41 58
42 - $templates = apply_filters(
43 - 'ultimate_store_kit_builder_templates',
44 - $product
45 - );
59 + if ( $wcItems = WC()->query->get_query_vars() ) {
60 + foreach ( $wcItems as $key => $item ) {
61 + $label = ucwords( str_replace( '-', ' ', $key ) );
62 + if ( in_array( $key, $order_flow_endpoints, true ) ) {
63 + // Keep hand-written labels (e.g. order-received) intact.
64 + if ( ! isset( $shop_item[ $key ] ) ) {
65 + $shop_item[ $key ] = $label;
66 + }
67 + } else {
68 + $my_account[ $key ] = $label;
69 + }
70 + }
71 + }
46 72
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 - }
73 + $product = [
74 + 'product' => $shop_item,
75 + 'account' => $my_account,
76 + ];
59 77
60 - return apply_filters(
61 - 'ultimate_store_kit_builder_all_templates',
62 - $return
63 - );
64 - }
78 + $templates = apply_filters(
79 + 'ultimate_store_kit_builder_templates',
80 + $product
81 + );
65 82
66 - return $templates;
67 - }
83 + if ( $single ) {
84 + $separator = static::separator();
85 + $return = [];
86 + if ( is_array( $templates ) && ! empty( $templates ) ) {
87 + foreach ( $templates as $keys => $items ) {
88 + if ( is_array( $items ) ) {
89 + foreach ( $items as $itemKey => $item ) {
90 + $return[ "{$keys}{$separator}{$itemKey}" ] = $item;
91 + }
92 + }
93 + }
94 + }
68 95
69 - public static function templateForSelectDropdown() {
70 - return static::templates();
71 - }
96 + return apply_filters(
97 + 'ultimate_store_kit_builder_all_templates',
98 + $return
99 + );
100 + }
72 101
73 - public static function getTemplateByIndex($index) {
74 - $index = trim($index);
75 - $templates = static::templates(true);
102 + return $templates;
103 + }
76 104
77 - return array_key_exists($index, $templates) ? $templates[$index] : false;
78 - }
105 + public static function templateForSelectDropdown() {
106 + return static::templates();
107 + }
79 108
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 - }
109 + public static function getTemplateByIndex( $index ) {
110 + $index = trim( $index );
111 + $templates = static::templates( true );
86 112
87 - public static function is_elementor_active() {
88 - return did_action('elementor/loaded');
89 - }
113 + return array_key_exists( $index, $templates ) ? $templates[ $index ] : false;
114 + }
90 115
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);
116 + public static function getTemplatePostTypeByIndex( $index ) {
117 + $index = trim( $index );
118 + if ( $item = explode( static::separator(), $index ) ) {
119 + return get_post_type_object( $item[0] );
120 + }
121 + }
98 122
99 - return get_option($enabledTemplate);
100 - }
123 + public static function is_elementor_active() {
124 + return did_action( 'elementor/loaded' );
125 + }
101 126
102 - public static function getTemplateId($templateType) {
103 - $metaIndex = strtolower(Meta::TEMPLATE_ID . $templateType);
104 - return intval(get_option($metaIndex));
105 - }
127 + public static function getTemplate( $slug, $postType = false ) {
128 + if ( ! $postType ) {
129 + $postType = get_post_type();
130 + }
131 +
132 + $separator = static::separator();
133 + $template = strtolower( "{$postType}{$separator}{$slug}" );
134 + /**
135 + * important area for debugging
136 + */
137 +
138 + return Meta::get_template_option( $template );
139 + }
140 +
141 + public static function getTemplateId( $templateType ) {
142 + return intval( Meta::get_template_option( $templateType ) );
143 + }
106 144 }