PluginProbe
Ultimate Store Kit / 3.1.0
Ultimate Store Kit v3.1.0
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 3.1.0, at includes/builder/builder-post-singleton.php

58 lines 1.6 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 = usk_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 set_transient('ultimate_store_template_id_' . get_current_user_id(), $postId);
52 set_transient('ultimate_store_template_sample_post_' . get_current_user_id(), $wp_query);
53 $GLOBALS['post'] = $post;
54 setup_postdata($post);
55 }
56 }
57 }
58