PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.5
ShopBuilder – WooCommerce Builder For Elementor v2.6.5
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 +129 -29 2.1.12 → 2.6.5 View file →
@@ -59,8 +59,20 @@
59 59 */
60 60 public static $view_template_for_archive_meta = 'rtsb_template_for_selected_category';
61 61
62 62 /**
63 + * Template builder
64 + *
65 + * @var string
66 + */
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 + /**
63 75 * Page builder id.
64 76 *
65 77 * @return int
66 78 */
@@ -69,16 +81,14 @@
69 81
70 82 if ( ! array_key_exists( $type, self::builder_page_types() ) ) {
71 83 return 0;
72 84 }
73 -
74 85 // Wpml Supported.
75 86 $options = self::option_name( $type );
76 87 $post_id = TemplateSettings::instance()->get_option( $options );
77 88 if ( empty( $post ) ) {
78 - return $post_id;
89 + return 0;
79 90 }
80 -
81 91 if ( empty( $post_id ) ) {
82 92 $options = self::option_name( $type, true );
83 93 $post_id = TemplateSettings::instance()->get_option( $options );
84 94 }
@@ -86,40 +96,87 @@
86 96 $cache_key = 'rtsb_builder_page_id_by_type_' . $type;
87 97 if ( isset( self::$cache[ $cache_key ] ) ) {
88 98 return self::$cache[ $cache_key ];
89 99 }
100 +
90 101 switch ( $type ) {
91 102 case 'product':
92 - if ( 'product' === $post->post_type ) {
93 - $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true );
94 - $set_default = self::get_specific_product_as_default( $builder_id );
103 + if ( 'product' !== $post->post_type ) {
104 + break;
105 + }
106 + $cache_key_product = 'template_for_product_page_' . get_the_ID();
107 + $template = get_transient( $cache_key_product );
108 + if ( $template && 'publish' === get_post_status( $template ) ) {
109 + $post_id = $template;
110 + break;
111 + }
112 + Cache::set_transient_cache_key( $cache_key_product );
113 + $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true );
95 114
96 - if ( 'publish' === $post->post_status ) {
97 - $post_id = $builder_id && $set_default ? $builder_id : $post_id;
115 + if ( self::get_specific_product_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) {
116 + $post_id = $builder_id;
117 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
118 + break;
119 + }
120 +
121 + $terms = get_the_terms( get_the_ID(), 'product_cat' );
122 + if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
123 + foreach ( $terms as $term ) {
124 + $template_id = get_term_meta( $term->term_id, self::$categories_product_page_template, true );
125 + if ( empty( $template_id ) || 'publish' !== get_post_status( $template_id ) ) {
126 + continue;
127 + }
128 + $set_default_option_name = self::option_name_product_page_specific_cat_set_default( $template_id );
129 + if ( TemplateSettings::instance()->get_option( $set_default_option_name ) ) {
130 + $post_id = $template_id;
131 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
132 + break 2;
133 + }
98 134 }
99 135 }
136 + $tags = get_the_terms( get_the_ID(), 'product_tag' );
137 + if ( ! is_wp_error( $tags ) && ! empty( $tags ) ) {
138 + foreach ( $tags as $term ) {
139 + $template_id = get_term_meta( $term->term_id, self::$tags_product_page_template, true );
140 + if ( empty( $template_id ) || 'publish' !== get_post_status( $template_id ) ) {
141 + continue;
142 + }
143 + $set_default_option_name = self::option_name_product_page_specific_tag_set_default( $template_id );
144 + if ( TemplateSettings::instance()->get_option( $set_default_option_name ) ) {
145 + $post_id = $template_id;
146 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
147 + break 2;
148 + }
149 + }
150 + }
151 + set_transient( $cache_key_product, $post_id, 12 * HOUR_IN_SECONDS );
100 152 break;
101 153 case 'archive':
102 154 $queried_object = get_queried_object();
103 -
104 155 if ( ! empty( $queried_object->taxonomy ) && 'product_cat' === $queried_object->taxonomy ) {
105 - $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true );
106 - $set_default = self::get_specific_category_as_default( $builder_id );
107 -
108 - if ( 'publish' === $post->post_status ) {
109 - $post_id = $builder_id && $set_default ? $builder_id : $post_id;
156 + $cache_key_archive = 'template_for_archive_page_' . $queried_object->term_id;
157 + $template = get_transient( $cache_key_archive );
158 + if ( $template && 'publish' === get_post_status( $template ) ) {
159 + $post_id = $template;
160 + break;
110 161 }
162 + Cache::set_transient_cache_key( $cache_key_archive );
163 + $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true );
164 + if ( self::get_specific_category_as_default( $builder_id ) && 'publish' === get_post_status( $builder_id ) ) {
165 + $post_id = $builder_id;
166 + set_transient( $cache_key_archive, $post_id, 12 * HOUR_IN_SECONDS ); // Cache duration: 12 hours.
167 + }
111 168 }
112 169 break;
113 170
114 171 default:
115 172 }
116 - if ( 'publish' === $post->post_status && self::builder_type( $post_id ) === $type ) {
173 + if ( 'publish' === get_post_status( $post_id ) && self::builder_type( $post_id ) === $type ) {
117 174 self::$cache[ $cache_key ] = $post_id;
118 175 return $post_id;
119 176 }
120 177
121 - return $post_id;
178 + return 0;
122 179 }
123 180
124 181 /**
125 182 * Page builder id.
@@ -128,9 +185,9 @@
128 185 */
129 186 public static function builder_page_id_by_page() {
130 187 $type = apply_filters( 'rtsb/builder/set/current/page/type', '' );
131 188 if ( ! $type ) {
132 - return;
189 + return 0;
133 190 }
134 191
135 192 return self::builder_page_id_by_type( $type );
136 193 }
@@ -199,9 +256,9 @@
199 256 return;
200 257 }
201 258 $options = self::option_name_for_specific_product_set_default( $post_id );
202 259
203 - return TemplateSettings::instance()->get_option( $options ); // get_option( $options );
260 + return TemplateSettings::instance()->get_option( $options );
204 261 }
205 262
206 263 /**
207 264 * @param $post_id
@@ -248,8 +305,60 @@
248 305 * @param $template_id
249 306 *
250 307 * @return string
251 308 */
309 + public static function option_name_product_page_selected_cat( $template_id ) {
310 + $_suff = null;
311 + if ( $template_id ) {
312 + $_suff = '_' . $template_id;
313 + }
314 +
315 + return self::$categories_product_page_template . $_suff;
316 + }
317 +
318 + /**
319 + * @param $post_id
320 + *
321 + * @return string|void
322 + */
323 + public static function option_name_product_page_specific_cat_set_default( $post_id ) {
324 + if ( ! $post_id ) {
325 + return;
326 + }
327 +
328 + return 'rtsb_template_product_page_specific_category_set_default_' . $post_id;
329 + }
330 +
331 + /**
332 + * @param $template_id
333 + *
334 + * @return string
335 + */
336 + public static function option_name_product_page_selected_tag( $template_id ) {
337 + $_suff = null;
338 + if ( $template_id ) {
339 + $_suff = '_' . $template_id;
340 + }
341 +
342 + return self::$tags_product_page_template . $_suff;
343 + }
344 + /**
345 + * @param $post_id
346 + *
347 + * @return string|void
348 + */
349 + public static function option_name_product_page_specific_tag_set_default( $post_id ) {
350 + if ( ! $post_id ) {
351 + return;
352 + }
353 +
354 + return 'rtsb_template_product_page_specific_tag_set_default_' . $post_id;
355 + }
356 + /**
357 + * @param $template_id
358 + *
359 + * @return string
360 + */
252 361 public static function archive_option_name_by_template_id( $template_id ) {
253 362 $_suff = null;
254 363 if ( $template_id ) {
255 364 $_suff = '_' . $template_id;
@@ -274,17 +383,16 @@
274 383 *
275 384 * @return string
276 385 */
277 386 public static function builder_type( $post_id ) {
278 -
279 387 $post_id = Fns::wpml_object_id( $post_id, self::$post_type_tb, 'default' );
280 388
281 389 if ( ! $post_id ) {
282 - return;
390 + return;
283 391 }
284 392
285 393 $cache_key = 'rtsb_template_type_' . $post_id;
286 - if ( isset( self::$cache[ $cache_key ] ) ) {
394 + if ( ! empty( self::$cache[ $cache_key ] ) ) {
287 395 return self::$cache[ $cache_key ];
288 396 }
289 397
290 398 $type = get_post_meta( $post_id, self::template_type_meta_key(), true );
@@ -366,16 +474,8 @@
366 474 *
367 475 * @return boolean
368 476 */
369 477 public static function is_page_builder( $type, $is_page, $is_require_auth = false ) {
370 - // if ( 'myaccount-dashboard' === $type ) {
371 - // $current_url = esc_url_raw( home_url( add_query_arg( null, null ) ) );
372 - //
373 - // if ( wc_get_account_endpoint_url( 'dashboard' ) !== $current_url ) {
374 - // return false;
375 - // }
376 - // }
377 -
378 478 if ( self::builder_type( get_the_ID() ) === $type ) {
379 479 return true;
380 480 }
381 481