PluginProbe
Ultimate Store Kit / trunk
Ultimate Store Kit vtrunk
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 trunk, at includes/builder/builder-template-helper.php

145 lines 3.8 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 if (! defined('ABSPATH')) {
6 exit; // Exit if accessed directly
7 }
8
9 class Builder_Template_Helper {
10
11 public static function isTemplateEditMode() {
12 if ( get_post_type() == 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 }
21
22 public static function separator() {
23 return '|';
24 }
25
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 ];
37
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 ];
48
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 );
58
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 }
72
73 $product = [
74 'product' => $shop_item,
75 'account' => $my_account,
76 ];
77
78 $templates = apply_filters(
79 'ultimate_store_kit_builder_templates',
80 $product
81 );
82
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 }
95
96 return apply_filters(
97 'ultimate_store_kit_builder_all_templates',
98 $return
99 );
100 }
101
102 return $templates;
103 }
104
105 public static function templateForSelectDropdown() {
106 return static::templates();
107 }
108
109 public static function getTemplateByIndex( $index ) {
110 $index = trim( $index );
111 $templates = static::templates( true );
112
113 return array_key_exists( $index, $templates ) ? $templates[ $index ] : false;
114 }
115
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 }
122
123 public static function is_elementor_active() {
124 return did_action( 'elementor/loaded' );
125 }
126
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 }
144 }
145