PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Helpers/BuilderFns.php +234 -98 2.1.33.2.6 View file →
@@ -59,25 +59,41 @@
59 59 */
60 60 public static $view_template_for_archive_meta = 'rtsb_template_for_selected_category';
61 61
62 62 /**
63 - * Page builder id.
63 + * Template builder
64 64 *
65 - * @return int
65 + * @var string
66 66 */
67 - public static function builder_page_id_by_type( $type ) {
67 + public static $categories_product_page_template = 'rtsb_categories_product_page_template';
68 + /**
69 + * Template builder
70 + *
71 + * @var string
72 + */
73 + public static $tags_product_page_template = 'rtsb_tags_product_page_template';
74 + /**
75 + * Get template ID based on page type.
76 + *
77 + * @param string $type Page type (product, archive, etc.).
78 + * @return int Template ID or 0.
79 + */
80 + public static function builder_page_id_by_type( $type ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity
68 81 global $post;
69 82
70 83 if ( ! array_key_exists( $type, self::builder_page_types() ) ) {
71 84 return 0;
72 85 }
73 -
86 + // Wpml Supported.
74 87 $options = self::option_name( $type );
75 88 $post_id = TemplateSettings::instance()->get_option( $options );
76 -
77 89 if ( empty( $post ) ) {
78 - return $post_id;
90 + return 0;
79 91 }
92 + if ( empty( $post_id ) ) {
93 + $options = self::option_name( $type, true );
94 + $post_id = TemplateSettings::instance()->get_option( $options );
95 + }
80 96
81 97 $cache_key = 'rtsb_builder_page_id_by_type_' . $type;
82 98 if ( isset( self::$cache[ $cache_key ] ) ) {
83 99 return self::$cache[ $cache_key ];
@@ -84,50 +100,95 @@
84 100 }
85 101
86 102 switch ( $type ) {
87 103 case 'product':
88 - if ( 'product' === $post->post_type ) {
89 - $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true );
90 - $set_default = self::get_specific_product_as_default( $builder_id );
104 + if ( 'product' !== $post->post_type ) {
105 + break;
106 + }
107 + $cache_key_product = 'template_for_product_page_' . get_the_ID();
108 + $template = get_transient( $cache_key_product );
109 + if ( $template && 'publish' === get_post_status( $template ) ) {
110 + $post_id = $template;
111 + break;
112 + }
113 + Cache::set_transient_cache_key( $cache_key_product );
114 + $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true );
91 115
92 - if ( 'publish' === $post->post_status ) {
93 - $post_id = $builder_id && $set_default ? $builder_id : $post_id;
116 + if ( self::get_specific_product_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) {
117 + $post_id = $builder_id;
118 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
119 + break;
120 + }
121 +
122 + $terms = get_the_terms( get_the_ID(), 'product_cat' );
123 + if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
124 + foreach ( $terms as $term ) {
125 + $template_id = get_term_meta( $term->term_id, self::$categories_product_page_template, true );
126 + if ( empty( $template_id ) || 'publish' !== get_post_status( $template_id ) ) {
127 + continue;
128 + }
129 + $set_default_option_name = self::option_name_product_page_specific_cat_set_default( $template_id );
130 + if ( TemplateSettings::instance()->get_option( $set_default_option_name ) ) {
131 + $post_id = $template_id;
132 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
133 + break 2;
134 + }
94 135 }
95 136 }
137 + $tags = get_the_terms( get_the_ID(), 'product_tag' );
138 + if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
139 + foreach ( $tags as $term ) {
140 + $template_id = get_term_meta( $term->term_id, self::$tags_product_page_template, true );
141 + if ( empty( $template_id ) || 'publish' !== get_post_status( $template_id ) ) {
142 + continue;
143 + }
144 + $set_default_option_name = self::option_name_product_page_specific_tag_set_default( $template_id );
145 + if ( TemplateSettings::instance()->get_option( $set_default_option_name ) ) {
146 + $post_id = $template_id;
147 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
148 + break 2;
149 + }
150 + }
151 + }
152 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS );
96 153 break;
97 154 case 'archive':
98 155 $queried_object = get_queried_object();
99 -
100 156 if ( ! empty( $queried_object->taxonomy ) && 'product_cat' === $queried_object->taxonomy ) {
101 - $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true );
102 - $set_default = self::get_specific_category_as_default( $builder_id );
103 -
104 - if ( 'publish' === $post->post_status ) {
105 - $post_id = $builder_id && $set_default ? $builder_id : $post_id;
157 + $cache_key_archive = 'template_for_archive_page_' . $queried_object->term_id;
158 + $template = get_transient( $cache_key_archive );
159 + if ( $template && 'publish' === get_post_status( $template ) ) {
160 + $post_id = $template;
161 + break;
106 162 }
163 + Cache::set_transient_cache_key( $cache_key_archive );
164 + $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true );
165 + if ( self::get_specific_category_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) {
166 + $post_id = $builder_id;
167 + set_transient( $cache_key_archive, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
168 + }
107 169 }
108 170 break;
109 171
110 172 default:
111 -
112 173 }
113 - if ( 'publish' === $post->post_status && self::builder_type( $post_id ) === $type ) {
174 + if ( 'publish' === get_post_status( $post_id ) && self::builder_type( $post_id ) === $type ) {
114 175 self::$cache[ $cache_key ] = $post_id;
115 176 return $post_id;
116 177 }
117 178
118 - return $post_id;
179 + return 0;
119 180 }
120 181
121 182 /**
122 - * Page builder id.
183 + * Get current page builder ID via filter.
123 184 *
124 - * @return init
185 + * @return int Template ID or 0.
125 186 */
126 187 public static function builder_page_id_by_page() {
127 188 $type = apply_filters( 'rtsb/builder/set/current/page/type', '' );
128 189 if ( ! $type ) {
129 - return;
190 + return 0;
130 191 }
131 192
132 193 return self::builder_page_id_by_type( $type );
133 194 }
@@ -133,18 +194,19 @@
133 194 }
134 195
135 196 /**
136 197 * Page builder Page for.
198 + * No need translatable Text and textdomain.
137 199 *
138 200 * @return array
139 201 */
140 202 public static function builder_page_types() {
141 203 $page_types = [
142 - 'shop' => esc_html__( 'Shop', 'shopbuilder' ),
143 - 'archive' => esc_html__( 'Category Archive', 'shopbuilder' ),
144 - 'product' => esc_html__( 'Product Page', 'shopbuilder' ),
145 - 'cart' => esc_html__( 'Cart', 'shopbuilder' ),
146 - 'checkout' => esc_html__( 'Checkout', 'shopbuilder' ),
204 + 'shop' => 'Shop',
205 + 'archive' => 'Category Archive',
206 + 'product' => 'Product Page',
207 + 'cart' => 'Cart',
208 + 'checkout' => 'Checkout',
147 209 ];
148 210
149 211 return apply_filters( 'rtsb/builder/register/page/types', $page_types );
150 212 }
@@ -149,24 +211,36 @@
149 211 return apply_filters( 'rtsb/builder/register/page/types', $page_types );
150 212 }
151 213
152 214 /**
153 - * Option name.
215 + * Get option key for template storage.
154 216 *
155 - * @param string $type Builder type.
156 - *
157 - * @return string
217 + * @param string $type Template type.
218 + * @param bool $default_lang Use default language.
219 + * @return string Option key.
158 220 */
159 - public static function option_name( $type ) {
160 - $type = str_replace( [ '-', ' ' ], '_', $type );
221 + public static function option_name( $type, $default_lang = false ) {
161 222
162 - return self::$template_meta . '_default_' . $type;
223 + $type = str_replace( [ '-', ' ' ], '_', $type );
224 + $suffix = $type;
225 +
226 + if ( $default_lang ) {
227 + return self::$template_meta . '_default_' . $suffix;
228 + }
229 + $current_lang = Fns::wpml_current_language();
230 +
231 + if ( ! empty( $current_lang ) ) {
232 + $suffix = $type . '_' . $current_lang;
233 + }
234 +
235 + return self::$template_meta . '_default_' . $suffix;
163 236 }
164 237
165 238 /**
166 - * @param $post_id
239 + * Option name to mark product template as default.
167 240 *
168 - * @return string|void
241 + * @param int $post_id Template ID.
242 + * @return string|null
169 243 */
170 244 public static function option_name_for_specific_product_set_default( $post_id ) {
171 245 if ( ! $post_id ) {
172 246 return;
@@ -175,11 +249,12 @@
175 249 return 'rtsb_template_specific_product_set_default_' . $post_id;
176 250 }
177 251
178 252 /**
179 - * @param $post_id
253 + * Check if a specific product template is default.
180 254 *
181 - * @return false|mixed|void|null
255 + * @param int $post_id Template ID.
256 + * @return mixed
182 257 */
183 258 public static function get_specific_product_as_default( $post_id ) {
184 259 if ( ! $post_id ) {
185 260 return;
@@ -185,15 +260,16 @@
185 260 return;
186 261 }
187 262 $options = self::option_name_for_specific_product_set_default( $post_id );
188 263
189 - return TemplateSettings::instance()->get_option( $options ); // get_option( $options );
264 + return TemplateSettings::instance()->get_option( $options );
190 265 }
191 266
192 267 /**
193 - * @param $post_id
268 + * Option name for default category template.
194 269 *
195 - * @return string|void
270 + * @param int $post_id Template ID.
271 + * @return string|null
196 272 */
197 273 public static function option_name_for_specific_category_set_default( $post_id ) {
198 274 if ( ! $post_id ) {
199 275 return;
@@ -202,11 +278,12 @@
202 278 return 'rtsb_template_specific_category_set_default_' . $post_id;
203 279 }
204 280
205 281 /**
206 - * @param $post_id
282 + * Check if a specific category template is default.
207 283 *
208 - * @return false|mixed|void|null
284 + * @param int $post_id Template ID.
285 + * @return mixed
209 286 */
210 287 public static function get_specific_category_as_default( $post_id ) {
211 288 if ( ! $post_id ) {
212 289 return;
@@ -211,15 +288,15 @@
211 288 if ( ! $post_id ) {
212 289 return;
213 290 }
214 291 $options = self::option_name_for_specific_category_set_default( $post_id );
215 -
216 - return TemplateSettings::instance()->get_option( $options ); // get_option( $options );
292 + return TemplateSettings::instance()->get_option( $options );
217 293 }
218 294
219 295 /**
220 - * @param $template_id
296 + * Get meta key by template ID for products.
221 297 *
298 + * @param int $template_id Template ID.
222 299 * @return string
223 300 */
224 301 public static function option_name_by_template_id( $template_id ) {
225 302 $_suff = null;
@@ -230,12 +307,74 @@
230 307 return self::$view_template_for_products_meta . $_suff;
231 308 }
232 309
233 310 /**
234 - * @param $template_id
311 + * Get option name for the selected product category template.
235 312 *
236 - * @return string
313 + * @param int|string $template_id Template ID for the category.
314 + *
315 + * @return string Generated option name.
237 316 */
317 + public static function option_name_product_page_selected_cat( $template_id ) {
318 + $_suff = null;
319 + if ( $template_id ) {
320 + $_suff = '_' . $template_id;
321 + }
322 +
323 + return self::$categories_product_page_template . $_suff;
324 + }
325 +
326 + /**
327 + * Get option name for setting a specific product category template as default.
328 + *
329 + * @param int|string $post_id Template or post ID.
330 + *
331 + * @return string|null Option name or null if post ID is invalid.
332 + */
333 + public static function option_name_product_page_specific_cat_set_default( $post_id ) {
334 + if ( ! $post_id ) {
335 + return;
336 + }
337 +
338 + return 'rtsb_template_product_page_specific_category_set_default_' . $post_id;
339 + }
340 +
341 + /**
342 + * Get option name for the selected product tag template.
343 + *
344 + * @param int|string $template_id Template ID for the tag.
345 + *
346 + * @return string Generated option name.
347 + */
348 + public static function option_name_product_page_selected_tag( $template_id ) {
349 + $_suff = null;
350 + if ( $template_id ) {
351 + $_suff = '_' . $template_id;
352 + }
353 +
354 + return self::$tags_product_page_template . $_suff;
355 + }
356 + /**
357 + * Get option name for setting a specific product tag template as default.
358 + *
359 + * @param int|string $post_id Template or post ID.
360 + *
361 + * @return string|null Option name or null if post ID is not provided.
362 + */
363 + public static function option_name_product_page_specific_tag_set_default( $post_id ) {
364 + if ( ! $post_id ) {
365 + return;
366 + }
367 +
368 + return 'rtsb_template_product_page_specific_tag_set_default_' . $post_id;
369 + }
370 + /**
371 + * Get option name for the selected archive (category) template.
372 + *
373 + * @param int|string $template_id Template ID.
374 + *
375 + * @return string Generated option name.
376 + */
238 377 public static function archive_option_name_by_template_id( $template_id ) {
239 378 $_suff = null;
240 379 if ( $template_id ) {
241 380 $_suff = '_' . $template_id;
@@ -244,11 +383,11 @@
244 383 return self::$view_template_for_archive_meta . $_suff;
245 384 }
246 385
247 386 /**
248 - * Template builder
387 + * Returns meta key used to store builder type.
249 388 *
250 - * @var string
389 + * @return string
251 390 */
252 391 public static function template_type_meta_key() {
253 392 return self::$template_meta . '_type';
254 393 }
@@ -260,14 +399,16 @@
260 399 *
261 400 * @return string
262 401 */
263 402 public static function builder_type( $post_id ) {
264 - if( ! $post_id ){
265 - return ;
403 + $post_id = Fns::wpml_object_id( $post_id, self::$post_type_tb, 'default' );
404 +
405 + if ( ! $post_id ) {
406 + return;
266 407 }
267 408
268 409 $cache_key = 'rtsb_template_type_' . $post_id;
269 - if ( isset( self::$cache[ $cache_key ] ) ) {
410 + if ( ! empty( self::$cache[ $cache_key ] ) ) {
270 411 return self::$cache[ $cache_key ];
271 412 }
272 413
273 414 $type = get_post_meta( $post_id, self::template_type_meta_key(), true );
@@ -278,11 +419,11 @@
278 419 return $type;
279 420 }
280 421
281 422 /**
282 - * Template builder
423 + * Check if current page is builder preview.
283 424 *
284 - * @var boolean
425 + * @return bool
285 426 */
286 427 public static function is_builder_preview() {
287 428 return is_singular( self::$post_type_tb );
288 429 }
@@ -287,11 +428,11 @@
287 428 return is_singular( self::$post_type_tb );
288 429 }
289 430
290 431 /**
291 - * Template builder
432 + * Check if archive template should load.
292 433 *
293 - * @var boolean
434 + * @return bool
294 435 */
295 436 public static function is_archive() {
296 437 return self::is_page_builder( 'archive', is_product_taxonomy() );
297 438 }
@@ -296,11 +437,11 @@
296 437 return self::is_page_builder( 'archive', is_product_taxonomy() );
297 438 }
298 439
299 440 /**
300 - * Template builder
441 + * Check if shop template should load.
301 442 *
302 - * @var boolean
443 + * @return bool
303 444 */
304 445 public static function is_shop() {
305 446 return self::is_page_builder( 'shop', is_shop() );
306 447 }
@@ -305,11 +446,11 @@
305 446 return self::is_page_builder( 'shop', is_shop() );
306 447 }
307 448
308 449 /**
309 - * Template builder
450 + * Check if cart template should load.
310 451 *
311 - * @var boolean
452 + * @return bool
312 453 */
313 454 public static function is_cart() {
314 455 return self::is_page_builder( 'cart', is_cart() );
315 456 }
@@ -314,11 +455,11 @@
314 455 return self::is_page_builder( 'cart', is_cart() );
315 456 }
316 457
317 458 /**
318 - * Template builder
459 + * Check if checkout template should load.
319 460 *
320 - * @var boolean
461 + * @return bool
321 462 */
322 463 public static function is_checkout() {
323 464 return self::is_page_builder( 'checkout', is_checkout() && ! is_wc_endpoint_url() && ! is_order_received_page() );
324 465 }
@@ -332,34 +473,47 @@
332 473 return self::is_page_builder( 'product', is_product() );
333 474 }
334 475
335 476 /**
336 - * Builder page detector.
477 + * Check if quick view page template should load.
337 478 *
338 - * @param string $type builder Page type.
339 - * @param boolean $is_page page status.
479 + * @param bool $is_quick_view True if quick view.
480 + * @return bool
481 + */
482 + public static function is_quick_views_page( $is_quick_view = false ) {
483 + return rtsb()->has_pro() && self::is_page_builder( 'quick-view', $is_quick_view );
484 + }
485 +
486 +
487 + /**
488 + * Check if a template should replace default WooCommerce page.
340 489 *
341 - * @return boolean
490 + * @param string $type Page type.
491 + * @param bool $is_page Current page status.
492 + * @param bool $is_require_auth Require login.
493 + * @return bool
342 494 */
343 495 public static function is_page_builder( $type, $is_page, $is_require_auth = false ) {
344 - if ( self::builder_type( get_the_ID() ) === $type ) {
345 - return true;
496 + $current_builder_type = self::builder_type( get_the_ID() );
497 + $post_type = get_post_type( get_the_ID() );
498 + if ( $post_type === self::$post_type_tb ) {
499 + if ( $current_builder_type === $type ) {
500 + return true;
501 + } else {
502 + return false;
503 + }
346 504 }
347 -
348 - if( $is_require_auth && ! is_user_logged_in() ){
349 - $type = 'myaccount-auth';
505 + if ( $is_require_auth && ! is_user_logged_in() ) {
506 + $type = 'myaccount-auth';
350 507 }
351 -
352 - $builder_id = self::builder_page_id_by_type( $type );
353 - if( ! $builder_id ){
508 + $builder_id = self::builder_page_id_by_type( $type );
509 + if ( ! $builder_id ) {
354 510 return false;
355 511 }
356 -
357 512 $builder_type = self::builder_type( $builder_id );
358 513 if ( $type === $builder_type && $is_page ) {
359 514 return true;
360 515 }
361 -
362 516 return false;
363 517 }
364 518
365 519 /**
@@ -370,26 +524,8 @@
370 524 *
371 525 * @return mixed
372 526 */
373 527 public static function get_builder_content( $template_id, $with_css = false ) {
374 - // Generate a unique key for this specific request
375 - $cache_key = 'builder_content_' . $template_id . '_' . ( $with_css ? 'with_css' : 'without_css' );
376 -
377 - // Attempt to retrieve content from the cache
378 - $cached_content = wp_cache_get( $cache_key, 'get_builder_content' );
379 -
380 - if ( false === $cached_content ) {
381 - // Content not found in cache, fetch and cache it
382 - $content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $with_css );
383 -
384 - // Cache the content for 5 minutes (300 seconds)
385 - wp_cache_set( $cache_key, $content, 'get_builder_content', 300 );
386 -
387 - return $content;
388 - }
389 -
390 - // Return the cached content
391 - return $cached_content;
528 + // Don't Use cache: tickets ID -> 75376.
529 + return \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $with_css );
392 530 }
393 -
394 -
395 531 }