PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 1.6.3
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v1.6.3
3.1.4 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 All 93 releases
ultimate-store-kit / includes / builder / builder-integration.php

builder-integration.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 1.6.3, at includes/builder/builder-integration.php

308 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'WPINC' ) ) {
4 die;
5 }
6
7 use Elementor\Controls_Manager;
8 use Elementor\Plugin;
9 use UltimateStoreKit\Includes\Builder\Builder_Template_Helper;
10 use UltimateStoreKit\Base\Singleton;
11 use UltimateStoreKit\Includes\Builder\Meta;
12 use UltimateStoreKit\Includes\Controls\SelectInput\Dynamic_Select;
13
14
15 class Builder_Integration {
16
17 use Singleton;
18
19 private $current_template = null;
20 public $current_template_id = null;
21
22 function __construct() {
23 add_filter('template_include', [$this, 'set_builder_template'], 9999);
24 add_action('elementor/editor/init', [$this, 'set_sample_post'], 999);
25
26 add_action( 'print_default_editor_scripts', array( $this, 'my_custom_fonts' ) );
27
28 add_action('elementor/documents/register_controls', [$this, 'register_document_controls']);
29 }
30
31 public function my_custom_fonts()
32 {
33 if(is_admin() && Plugin::instance()->editor->is_edit_mode()){
34 if (isset($_REQUEST['usk-template'])) {
35 wp_register_style('usk-template-builder-hide-preview-btn-inline', false); // phpcs:ignore
36 wp_enqueue_style('usk-template-builder-hide-preview-btn-inline');
37 wp_add_inline_style(
38 'usk-template-builder-hide-preview-btn-inline',
39 '#elementor-panel-footer-saver-preview {display:none!important}'
40 );
41 }
42 }
43 }
44 function set_sample_post()
45 {
46 if (Builder_Template_Helper::isTemplateEditMode()) {
47 $object = \UltimateStoreKit\Includes\Builder\Builder_Post_Singleton::instance();
48 $object::set_sample_post();
49 }
50 }
51
52 function register_document_controls($document)
53 {
54 if (!$document instanceof \Elementor\Core\DocumentTypes\PageBase
55 || !$document::get_property('has_elements')) {
56 return;
57 }
58
59 if(\Elementor\Plugin::instance()->preview->is_preview_mode()) return;
60
61 if (!Builder_Template_Helper::isTemplateEditMode()) {
62 return;
63 }
64
65 global $post;
66
67 if (!isset($post->ID)) {
68 return;
69 }
70 $meta = get_post_meta($post->ID);
71
72 $templateMeta = optional($meta)[Meta::TEMPLATE_TYPE];
73 if (!isset($templateMeta[0])) {
74 return;
75 }
76 $postMeta = $templateMeta[0];
77 $postMeta = explode('|', $postMeta);
78 $postType = $postMeta[0];
79
80 if ($postMeta[1] != 'single') {
81 return;
82 }
83
84 $document->start_controls_section(
85 'usk_page_setting_preview',
86 [
87 'label' => esc_html__('Builder Settings', 'ultimate-store-kit'),
88 'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
89 ]
90 );
91
92 $document->add_control(
93 'usk_builder_sample_post_id',
94 [
95 'label' => __('Builder Post', 'ultimate-store-kit'),
96 'type' => Dynamic_Select::TYPE,
97 'multiple' => false,
98 'label_block' => true,
99 'query_args' => [
100 'post_type' => $postType
101 ],
102 ]
103 );
104
105 $document->add_control(
106 'usk_builder_sample_apply_preview',
107 [
108 'type' => Controls_Manager::BUTTON,
109 'label' => esc_html__( 'Apply & Preview', 'ultimate-store-kit' ),
110 'label_block' => true,
111 'show_label' => false,
112 'text' => esc_html__( 'Apply & Preview', 'ultimate-store-kit' ),
113 'separator' => 'none',
114 'event' => 'ultimateStoreKitBuilderSetting:applySinglePagePostOnPreview',
115 ]
116 );
117
118 $document->end_controls_section();
119 }
120
121 /**
122 * Rewrite default template
123 *
124 */
125 function set_builder_template($template)
126 {
127 if (Builder_Template_Helper::isTemplateEditMode()) {
128 return $this->setBackendTemplate($template);
129 } else {
130 return $this->setFrontendTemplate($template);
131 }
132 }
133
134
135 protected function setBackendTemplate($template)
136 {
137 return $template;
138 }
139
140
141 protected function setFrontendTemplate($template)
142 {
143 if (get_post_type() == 'product') {
144 global $product;
145 $product = wc_get_product();
146 }
147
148 if (defined('ELEMENTOR_PATH')) {
149 $elementorTem = ELEMENTOR_PATH."modules/page-templates/templates/";
150 $elementorTem = explode($elementorTem, $template);
151 if (count($elementorTem) == 2) {
152 return $template;
153 }
154 }
155
156 if (is_post_type_archive('product') || is_page(wc_get_page_id('shop')) || is_product_taxonomy()) {
157 if ($custom_template = $this->get_template_id('shop')) {
158 $this->current_template_id = $custom_template;
159 return $this->getTemplatePath('woocommerce/archive-product', $template);
160 }
161 }
162
163 if (is_cart()) {
164 if ($custom_template = $this->get_template_id('cart', 'product')) {
165 $this->current_template_id = $custom_template;
166 return $this->getTemplatePath('woocommerce/cart', $template);
167 }
168 }
169
170 if (is_checkout()) {
171 if ($custom_template = $this->get_template_id('checkout', 'product')) {
172 $this->current_template_id = $custom_template;
173 return $this->getTemplatePath('woocommerce/checkout', $template);
174 }
175 }
176
177 if (is_single() && get_post_type() == 'product') {
178 if ($custom_template = $this->get_template_id('single', 'product')) {
179 $this->current_template_id = $custom_template;
180 return $this->getTemplatePath('woocommerce/single-product', $template);
181 }
182 }
183
184 if (is_account_page()) {
185 global $wp;
186 $query_vars = WC()->query->get_query_vars();
187 if ($endpoint = array_intersect_key($wp->query_vars, $query_vars)) {
188 $endpoint = array_key_first($endpoint);
189
190 if ($endpoint && $custom_template = $this->get_template_id($endpoint, 'product')) {
191 $this->current_template_id = $custom_template;
192
193 if ($newTemplate = $this->getTemplatePath("woocommerce/{$endpoint}")) {
194 return $newTemplate;
195 }
196
197 return $this->getTemplatePath("woocommerce/my-account", '');
198 }
199 } else {
200 if ($custom_template = $this->get_template_id('myaccount', 'product')) {
201 $this->current_template_id = $custom_template;
202 return $this->getTemplatePath('woocommerce/my-account', $template);
203 }
204 }
205 }
206
207
208 if (is_single()) {
209 if ($custom_template = $this->get_template_id('single', 'post')) {
210 $this->current_template_id = $custom_template;
211 return $this->getTemplatePath('single-post', $template);
212 }
213 }
214
215 if (is_archive()) {
216 if ($custom_template = $this->get_template_id('archive', 'post')) {
217 $this->current_template_id = $custom_template;
218 return $this->getTemplatePath('archive-post', $template);
219 }
220 }
221
222 if (is_home()) {
223 if ($custom_template = $this->get_template_id('home', 'post')) {
224 $this->current_template_id = $custom_template;
225 return $this->getTemplatePath('home', $template);
226 }
227 }
228
229 if ($page_Id = intval(get_option( 'bdt_usk_compare_products_page_id' )) ) {
230 if(is_page($page_Id)){
231 if ($custom_template = $this->get_template_id('compare-products','product')) {
232 $this->current_template_id = $custom_template;
233 return $this->getTemplatePath('home', $template);
234 }
235 }
236 }
237
238 return $template;
239 }
240
241
242 public function getThemeTemplatePath( $slug ) {
243
244 $fullPath = get_template_directory()."/ultimate-store-kit/$slug";
245 if ( file_exists( $fullPath ) ) {
246 return $fullPath;
247 }
248 }
249
250 public function getPluginTemplatePath( $slug ) {
251
252 $fullPath = BDTUSK_PATH."includes/builder/templates/$slug";
253 if ( file_exists( $fullPath ) ) {
254 return $fullPath;
255 }
256 }
257
258
259 /**
260 * Get Template Path ID
261 *
262 * @param $slug
263 * @param $postType
264 *
265 * @return mixed|void|null
266 */
267 public function get_template_id( $slug, $postType = false ) {
268
269 if ( null !== $this->current_template_id ) {
270 return $this->current_template_id;
271 }
272
273 $templateId = Builder_Template_Helper::getTemplate( $slug, $postType );
274 $this->current_template_id = apply_filters( 'ultimate-store-kit-builder/custom-shop-template', $templateId );
275
276 return $this->current_template_id;
277 }
278
279
280 /**
281 * Get Template Path
282 *
283 * @param $slug
284 * @param $default
285 *
286 * @return mixed|string|void
287 */
288 protected function getTemplatePath( $slug, $default = '' ) {
289 $phpSlug = "{$slug}.php";
290
291 if($template = $this->getThemeTemplatePath($phpSlug)){
292 return $template;
293 }
294
295 if($template = $this->getPluginTemplatePath($phpSlug)){
296 return $template;
297 }
298
299 return $default;
300 }
301
302 }
303
304
305 Builder_Integration::instance();
306
307
308