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

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