| @@ -1,8 +1,12 @@ | ||
| 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 | 11 | public static function isTemplateEditMode() { |
| 8 | 12 | if ( get_post_type() == Meta::POST_TYPE ) { |
| @@ -8,8 +12,9 @@ | ||
| 8 | 12 | if ( get_post_type() == Meta::POST_TYPE ) { |
| 9 | 13 | return true; |
| 10 | 14 | } |
| 11 | 15 | |
| 16 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check on whether a builder template is being edited. | |
| 12 | 17 | if ( isset( $_REQUEST[ Meta::POST_TYPE ] ) ) { |
| 13 | 18 | return true; |
| 14 | 19 | } |
| 15 | 20 | } |
| @@ -26,12 +31,13 @@ | ||
| 26 | 31 | 'category' => 'Category Page', |
| 27 | 32 | 'tag' => 'Tag Page', |
| 28 | 33 | 'cart' => 'Cart Page', |
| 29 | 34 | 'checkout' => 'Checkout', |
| 30 | - 'order-received' => 'Order Received', | |
| 35 | + 'order-received' => 'Order Received (Thank You Page)', | |
| 31 | 36 | ]; |
| 32 | 37 | |
| 33 | 38 | $my_account = [ |
| 39 | + 'login' => 'Login & Register', | |
| 34 | 40 | 'myaccount' => 'Dashboard', |
| 35 | 41 | 'orders' => 'Orders', |
| 36 | 42 | 'downloads' => 'Downloads', |
| 37 | 43 | 'edit-address' => 'Address', |
| @@ -39,12 +45,30 @@ | ||
| 39 | 45 | 'wishlist' => 'Wishlist', |
| 40 | 46 | 'logout' => 'Customer Logout', |
| 41 | 47 | ]; |
| 42 | 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 | + | |
| 43 | 59 | if ( $wcItems = WC()->query->get_query_vars() ) { |
| 44 | - array_walk( $wcItems, function ($item, $key) use (&$shop_item) { | |
| 45 | - $shop_item[ $key ] = ucwords( str_replace( '-', ' ', $key ) ); | |
| 46 | - } ); | |
| 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 | + } | |
| 47 | 71 | } |
| 48 | 72 | |
| 49 | 73 | $product = [ |
| 50 | 74 | 'product' => $shop_item, |
| @@ -106,18 +130,15 @@ | ||
| 106 | 130 | } |
| 107 | 131 | |
| 108 | 132 | $separator = static::separator(); |
| 109 | 133 | $template = strtolower( "{$postType}{$separator}{$slug}" ); |
| 110 | - $enabledTemplate = strtolower( Meta::TEMPLATE_ID . $template ); | |
| 111 | - | |
| 112 | 134 | /** |
| 113 | 135 | * important area for debugging |
| 114 | 136 | */ |
| 115 | 137 | |
| 116 | - return get_option( $enabledTemplate ); | |
| 138 | + return Meta::get_template_option( $template ); | |
| 117 | 139 | } |
| 118 | 140 | |
| 119 | 141 | public static function getTemplateId( $templateType ) { |
| 120 | - $metaIndex = strtolower( Meta::TEMPLATE_ID . $templateType ); | |
| 121 | - return intval( get_option( $metaIndex ) ); | |
| 142 | + return intval( Meta::get_template_option( $templateType ) ); | |
| 122 | 143 | } |
| 123 | 144 | } |