| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Includes\Builder; |
| 4 |
|
| 5 |
use Elementor\Widget_Base; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} // Exit if accessed directly |
| 12 |
|
| 13 |
abstract class Builder_Widget_Base extends Widget_Base { |
| 14 |
|
| 15 |
public $__temp_query = null; |
| 16 |
public $__product_data = false; |
| 17 |
|
| 18 |
|
| 19 |
/** |
| 20 |
* Check if we currently in Elementor mode |
| 21 |
* |
| 22 |
* @return void |
| 23 |
*/ |
| 24 |
public function in_elementor() { |
| 25 |
$result = false; |
| 26 |
|
| 27 |
if ( wp_doing_ajax() ) { |
| 28 |
$result = isset($this->is_elementor_ajax); |
| 29 |
} elseif ( |
| 30 |
\Elementor\Plugin::instance()->editor->is_edit_mode() |
| 31 |
|| \Elementor\Plugin::instance()->preview->is_preview_mode() |
| 32 |
) { |
| 33 |
$result = true; |
| 34 |
} |
| 35 |
|
| 36 |
return apply_filters( 'ultimate-store-kit-builder/in-elementor', $result ); |
| 37 |
} |
| 38 |
|
| 39 |
protected function is_ultimate_builder_editor() { |
| 40 |
|
| 41 |
if ( ! $this->in_elementor() && ! wp_doing_ajax() ) |
| 42 |
return; |
| 43 |
if ( get_post_type() !== Meta::POST_TYPE ) |
| 44 |
return; |
| 45 |
|
| 46 |
return true; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Set editor data for ajax save only |
| 52 |
*/ |
| 53 |
public function usk_set_single_post_preview_data() { |
| 54 |
|
| 55 |
if ( ! $this->is_ultimate_builder_editor() ) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
global $post; |
| 60 |
|
| 61 |
$templateId = get_transient( 'ultimate_store_template_id_' . get_current_user_id() ); |
| 62 |
$posts = get_transient( 'ultimate_store_template_sample_post_' . get_current_user_id() ); |
| 63 |
|
| 64 |
if ( $posts instanceof \WP_Query && $posts->have_posts() && $templateId == $post->ID ) { |
| 65 |
foreach ( $posts->posts as $post ) { |
| 66 |
$GLOBALS['post'] = $post; |
| 67 |
setup_postdata( $post ); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|