| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Includes\Builder; |
| 4 |
|
| 5 |
use Elementor\Widget_Base; |
| 6 |
use UltimateStoreKit\Ultimate_Store_Kit_Loader; |
| 7 |
|
| 8 |
|
| 9 |
if (! defined('ABSPATH')) { |
| 10 |
exit; |
| 11 |
} // Exit if accessed directly |
| 12 |
|
| 13 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- usk_ / BDTUSK_ / ultimate-store-kit- are this plugin's established public prefixes. Ultimate Store Kit Pro calls into these names, as does third-party integration code, so renaming them is a breaking change. Plugin Check only recognises prefixes derived verbatim from the slug and so reports them as unprefixed. |
| 14 |
|
| 15 |
abstract class Builder_Widget_Base extends Widget_Base { |
| 16 |
|
| 17 |
public $__temp_query = null; |
| 18 |
public $__product_data = false; |
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* Check if we currently in Elementor mode |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function in_elementor() { |
| 27 |
$result = false; |
| 28 |
|
| 29 |
if (wp_doing_ajax()) { |
| 30 |
$result = isset($this->is_elementor_ajax); |
| 31 |
} elseif ( |
| 32 |
\Elementor\Plugin::instance()->editor->is_edit_mode() |
| 33 |
|| \Elementor\Plugin::instance()->preview->is_preview_mode() |
| 34 |
|| Ultimate_Store_Kit_Loader::elementor()->editor->is_edit_mode() |
| 35 |
|| Ultimate_Store_Kit_Loader::elementor()->preview->is_preview_mode() |
| 36 |
) { |
| 37 |
$result = true; |
| 38 |
} |
| 39 |
|
| 40 |
return apply_filters('ultimate-store-kit-builder/in-elementor', $result); |
| 41 |
} |
| 42 |
|
| 43 |
protected function is_ultimate_builder_editor() { |
| 44 |
|
| 45 |
if (! $this->in_elementor() && ! wp_doing_ajax()) |
| 46 |
return; |
| 47 |
if (get_post_type() !== Meta::POST_TYPE) |
| 48 |
return; |
| 49 |
|
| 50 |
return true; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Set editor data for ajax save only |
| 56 |
*/ |
| 57 |
public function usk_set_single_post_preview_data() { |
| 58 |
|
| 59 |
if (! $this->is_ultimate_builder_editor()) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
global $post; |
| 64 |
|
| 65 |
$templateId = get_transient('ultimate_store_kit_template_id_' . get_current_user_id()); |
| 66 |
$posts = get_transient('ultimate_store_kit_template_sample_post_' . get_current_user_id()); |
| 67 |
|
| 68 |
if ($posts instanceof \WP_Query && $posts->have_posts() && $templateId == $post->ID) { |
| 69 |
foreach ($posts->posts as $post) { |
| 70 |
$GLOBALS['post'] = $post; |
| 71 |
setup_postdata($post); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|