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-post-singleton.php

builder-post-singleton.php in Ultimate Store Kit trunk, at includes/builder/builder-post-singleton.php

61 lines 1.9 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 use UltimateStoreKit\Base\Singleton;
10
11 class Builder_Post_Singleton {
12 use Singleton;
13
14 public static function set_sample_post($postId = null) {
15 global $post;
16
17 if (!$postId) {
18 $postId = $post->ID;
19 }
20
21 $meta = get_post_meta($postId);
22
23 $templateMeta = ultimate_store_kit_optional($meta)[Meta::TEMPLATE_TYPE];
24
25 if (!isset($templateMeta[0])) {
26 return;
27 }
28
29 $postMeta = $templateMeta[0];
30 $postMeta = explode('|', $postMeta);
31 $postType = $postMeta[0];
32
33 $args = [
34 'post_type' => $postType,
35 'post_status' => ['publish', 'pending', 'draft', 'future'],
36 'posts_per_page' => 1,
37 ];
38
39 $page_settings_manager = \Elementor\Core\Settings\Manager::get_settings_managers('page');
40 $page_settings_model = $page_settings_manager->get_model($postId);
41 $sample_product = $page_settings_model->get_settings('usk_builder_sample_post_id');
42
43 if ($sample_product) {
44 $args['p'] = $sample_product;
45 }
46
47 $wp_query = new \WP_Query($args);
48
49 if ($wp_query->have_posts()) {
50 $post = $wp_query->posts[0];
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);
56 $GLOBALS['post'] = $post;
57 setup_postdata($post);
58 }
59 }
60 }
61