| @@ -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 | use UltimateStoreKit\Base\Singleton; |
| 6 | 10 | |
| 7 | 11 | class Builder_Post_Singleton { |
| 8 | 12 | use Singleton; |
| @@ -15,9 +19,9 @@ | ||
| 15 | 19 | } |
| 16 | 20 | |
| 17 | 21 | $meta = get_post_meta($postId); |
| 18 | 22 | |
| 19 | - $templateMeta = optional($meta)[Meta::TEMPLATE_TYPE]; | |
| 23 | + $templateMeta = ultimate_store_kit_optional($meta)[Meta::TEMPLATE_TYPE]; | |
| 20 | 24 | |
| 21 | 25 | if (!isset($templateMeta[0])) { |
| 22 | 26 | return; |
| 23 | 27 | } |
| @@ -43,10 +47,13 @@ | ||
| 43 | 47 | $wp_query = new \WP_Query($args); |
| 44 | 48 | |
| 45 | 49 | if ($wp_query->have_posts()) { |
| 46 | 50 | $post = $wp_query->posts[0]; |
| 47 | - set_transient('ultimate_store_template_id_' . get_current_user_id(), $postId); | |
| 48 | - set_transient('ultimate_store_template_sample_post_' . get_current_user_id(), $wp_query); | |
| 51 | + // An explicit lifetime is required: a transient stored with no expiry is | |
| 52 | + // autoloaded on every request, so these editor-preview handoffs otherwise | |
| 53 | + // accumulate one permanent wp_options row per user who opens the builder. | |
| 54 | + set_transient('ultimate_store_kit_template_id_' . get_current_user_id(), $postId, HOUR_IN_SECONDS); | |
| 55 | + set_transient('ultimate_store_kit_template_sample_post_' . get_current_user_id(), $wp_query, HOUR_IN_SECONDS); | |
| 49 | 56 | $GLOBALS['post'] = $post; |
| 50 | 57 | setup_postdata($post); |
| 51 | 58 | } |
| 52 | 59 | } |