PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.0
ShopBuilder – WooCommerce Builder For Elementor v2.0.0
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
shopbuilder / app / Helpers / BuilderFns.php

BuilderFns.php in ShopBuilder – WooCommerce Builder For Elementor 2.0.0, at app/Helpers/BuilderFns.php

518 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * BuilderFns class
4 *
5 * The builder.
6 *
7 * @package RadiusTheme\SB
8 * @since 1.0.0
9 */
10
11 namespace RadiusTheme\SB\Helpers;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * BuilderFns class
20 */
21 class BuilderFns {
22
23 /**
24 * Template builder post type
25 *
26 * @var string
27 */
28 public static $post_type_tb = 'rtsb_builder';
29 /**
30 * Template builder
31 *
32 * @var string
33 */
34 public static $template_meta = 'rtsb_tb_template';
35 /**
36 * Template builder
37 *
38 * @var string
39 */
40 public static $product_template_meta = 'rtsb_selected_product_template';
41 /**
42 * Template builder
43 *
44 * @var string
45 */
46 public static $view_template_for_products_meta = 'rtsb_template_for_selected_products';
47 /**
48 * Template builder
49 *
50 * @var string
51 */
52 public static $view_template_for_archive_meta = 'rtsb_template_for_selected_category';
53
54 /**
55 * Page builder id.
56 *
57 * @return init
58 */
59 public static function builder_page_id_by_type( $type ) {
60 if ( array_key_exists( $type, self::builder_page_types() ) ) {
61 $post_id = get_option( self::option_name( $type ) );
62
63 switch ( $type ) {
64 case 'product':
65 if ( 'product' === get_post_type( get_the_ID() ) ) {
66 $builder_id = get_post_meta( get_the_ID(), self::$view_template_for_products_meta, true );
67 $set_default = self::get_specific_product_as_default( $builder_id );
68 if ( 'publish' === get_post_status( $builder_id ) ) {
69 $post_id = $builder_id && $set_default ? $builder_id : $post_id;
70 }
71 }
72 break;
73 case 'archive':
74 $queried_object = get_queried_object();
75 if ( ! empty( $queried_object->taxonomy ) && 'product_cat' === $queried_object->taxonomy ) {
76 $builder_id = get_term_meta( $queried_object->term_id, self::$view_template_for_archive_meta, true);
77 $set_default = self::get_specific_category_as_default( $builder_id );
78 if ( 'publish' === get_post_status( $builder_id ) ) {
79 $post_id = $builder_id && $set_default ? $builder_id : $post_id;
80 }
81 }
82 break;
83
84 default:
85
86 }
87 if ( 'publish' === get_post_status( $post_id ) && self::builder_type( $post_id ) === $type ) {
88 return $post_id;
89 }
90 }
91
92 return 0;
93 }
94
95 /**
96 * Page builder id.
97 *
98 * @return init
99 */
100 public static function builder_page_id_by_page() {
101 $type = apply_filters( 'rtsb/builder/set/current/page/type', '' );
102 if ( ! $type ) {
103 return;
104 }
105
106 return self::builder_page_id_by_type( $type );
107 }
108
109 /**
110 * Page builder Page for.
111 *
112 * @return array
113 */
114 public static function builder_page_types() {
115 $page_types = [
116 'shop' => esc_html__( 'Shop', 'shopbuilder' ),
117 'archive' => esc_html__( 'Category Archive', 'shopbuilder' ),
118 'product' => esc_html__( 'Product Page', 'shopbuilder' ),
119 'cart' => esc_html__( 'Cart', 'shopbuilder' ),
120 'checkout' => esc_html__( 'Checkout', 'shopbuilder' ),
121 ];
122
123 return apply_filters( 'rtsb/builder/register/page/types', $page_types );
124 }
125
126 /**
127 * Option name.
128 *
129 * @param string $type Builder type.
130 *
131 * @return string
132 */
133 public static function option_name( $type ) {
134 $type = str_replace( [ '-', ' ' ], '_', $type );
135
136 return self::$template_meta . '_default_' . $type;
137 }
138
139 /**
140 * @param $post_id
141 *
142 * @return string|void
143 */
144 public static function option_name_for_specific_product_set_default( $post_id ) {
145 if ( ! $post_id ) {
146 return;
147 }
148
149 return 'rtsb_template_specific_product_set_default_' . $post_id;
150 }
151
152 /**
153 * @param $post_id
154 *
155 * @return false|mixed|void|null
156 */
157 public static function get_specific_product_as_default( $post_id ) {
158 if ( ! $post_id ) {
159 return;
160 }
161 $options = self::option_name_for_specific_product_set_default( $post_id );
162
163 return get_option( $options );
164 }
165
166 /**
167 * @param $post_id
168 *
169 * @return string|void
170 */
171 public static function option_name_for_specific_category_set_default( $post_id ) {
172 if ( ! $post_id ) {
173 return;
174 }
175
176 return 'rtsb_template_specific_category_set_default_' . $post_id;
177 }
178
179 /**
180 * @param $post_id
181 *
182 * @return false|mixed|void|null
183 */
184 public static function get_specific_category_as_default( $post_id ) {
185 if ( ! $post_id ) {
186 return;
187 }
188 $options = self::option_name_for_specific_category_set_default( $post_id );
189
190 return get_option( $options );
191 }
192
193 /**
194 * @param $template_id
195 *
196 * @return string
197 */
198 public static function option_name_by_template_id( $template_id ) {
199 $_suff = null;
200 if ( $template_id ) {
201 $_suff = '_' . $template_id;
202 }
203
204 return self::$view_template_for_products_meta . $_suff;
205 }
206
207 /**
208 * @param $template_id
209 *
210 * @return string
211 */
212 public static function archive_option_name_by_template_id( $template_id ) {
213 $_suff = null;
214 if ( $template_id ) {
215 $_suff = '_' . $template_id;
216 }
217
218 return self::$view_template_for_archive_meta . $_suff;
219 }
220
221 /**
222 * Template builder
223 *
224 * @var string
225 */
226 public static function template_type_meta_key() {
227 return self::$template_meta . '_type';
228 }
229
230 /**
231 * Get builder type.
232 *
233 * @param [type] $post_id Post id.
234 *
235 * @return string
236 */
237 public static function builder_type( $post_id ) {
238 return get_post_meta( $post_id, self::template_type_meta_key(), true );
239 }
240
241 /**
242 * Template builder
243 *
244 * @var boolean
245 */
246 public static function is_builder_preview() {
247 return is_singular( self::$post_type_tb );
248 }
249
250 /**
251 * Template builder
252 *
253 * @var boolean
254 */
255 public static function is_archive() {
256 return self::is_page_builder( 'archive', is_product_taxonomy() );
257 }
258
259 /**
260 * Template builder
261 *
262 * @var boolean
263 */
264 public static function is_shop() {
265 return self::is_page_builder( 'shop', is_shop() );
266 }
267
268 /**
269 * Template builder
270 *
271 * @var boolean
272 */
273 public static function is_cart() {
274 return self::is_page_builder( 'cart', is_cart() );
275 }
276
277 /**
278 * Template builder
279 *
280 * @var boolean
281 */
282 public static function is_checkout() {
283 return self::is_page_builder( 'checkout', is_checkout() && ! is_wc_endpoint_url() && ! is_order_received_page() );
284 }
285
286 /**
287 * Single Page builder Detection
288 *
289 * @return boolean
290 */
291 public static function is_product() {
292 return self::is_page_builder( 'product', is_product() );
293 }
294
295 /**
296 * Builder page detector.
297 *
298 * @param string $type builder Page type.
299 * @param boolean $is_page page status.
300 *
301 * @return boolean
302 */
303 public static function is_page_builder( $type, $is_page ) {
304 if ( self::builder_type( get_the_ID() ) === $type ) {
305 return true;
306 }
307 $builder_id = self::builder_page_id_by_type( $type );
308 $builder_type = self::builder_type( $builder_id );
309 if ( $type === $builder_type && $is_page ) {
310 return true;
311 }
312
313 return false;
314 }
315
316 /**
317 * Get builder content function
318 *
319 * @param [type] $template_id builder Template id.
320 * @param boolean $with_css with css.
321 *
322 * @return mixed
323 */
324 public static function get_builder_content( $template_id, $with_css = false ) {
325 return \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, $with_css );
326 }
327
328 /**
329 * Page builder Page for.
330 *
331 * @return array
332 */
333 // TODO :: This Function Will remove.
334 public static function default_layout() {
335 $demo_root_url = 'https://shopbuilderwp.com';
336 $page_layout = [
337 'default' => [
338 [
339 'text_label' => __( 'Blank', 'shopbuilder' ),
340 'image' => rtsb()->get_assets_uri( 'images/layout-preview/placeholder.png' ),
341 ],
342 ],
343 'product' => [
344 // [
345 // 'text_label' => __( 'Product Layout 1', 'shopbuilder' ),
346 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/product-single-demo-1.jpg' ),
347 // 'live_preview' => $demo_root_url . '/rtsb-template/product-single-demo-1/',
348 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/products/product-single-demo-1.json',
349 // ],
350 // [
351 // 'text_label' => __( 'Product Layout 2', 'shopbuilder' ),
352 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/product-single-demo-2.jpg' ),
353 // 'live_preview' => $demo_root_url . '/rtsb-template/product-single-demo-2',
354 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/products/product-single-demo-2.json',
355 // ],
356 // [
357 // 'text_label' => __( 'Product Layout 3', 'shopbuilder' ),
358 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/product-single-demo-3.jpg' ),
359 // 'live_preview' => $demo_root_url . '/rtsb-template/product-single-demo-3/',
360 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/products/product-single-demo-3.json',
361 // ],
362 // [
363 // 'text_label' => __( 'Product Layout 4', 'shopbuilder' ),
364 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/product-single-demo-4.jpg' ),
365 // 'live_preview' => $demo_root_url . '/rtsb-template/product-single-demo-4/',
366 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/products/product-single-demo-4.json',
367 // ],
368 // [
369 // 'text_label' => __( 'Product Layout 5', 'shopbuilder' ),
370 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/product-single-demo-5.jpg' ),
371 // 'live_preview' => $demo_root_url . '/rtsb-template/product-single-demo-5/',
372 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/products/product-single-demo-5.json',
373 // ],
374
375 ],
376 'shop' => [
377 'template-1' => [
378 "elementor" => [
379 'text_label' => __( 'Shop – Theme Default', 'shopbuilder' ),
380 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-theme-default.jpg' ),
381 'live_preview' => $demo_root_url . '/shop/',
382 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop–fullWidth-theme-default.json',
383 ],
384 // "gutenberg" => [
385 // 'text_label' => __( 'Gutenberg Shop – Theme Default', 'shopbuilder' ),
386 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-theme-default.jpg' ),
387 // 'live_preview' => $demo_root_url . '/shop/',
388 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-theme-default.json',
389 // ]
390 ],
391 'template-2' => [
392 "elementor" => [
393 'text_label' => __( 'Shop – Left Sidebar', 'shopbuilder' ),
394 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-left-sidebar.jpg' ),
395 'live_preview' => $demo_root_url . '/rtsb-template/shop-left-sidebar-shop-builder-custom/',
396 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-left-sidebar.json',
397 ],
398 // "gutenberg" => [
399 // 'text_label' => __( 'Gutenberg Shop – Theme Default', 'shopbuilder' ),
400 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-theme-default.jpg' ),
401 // 'live_preview' => $demo_root_url . '/shop/',
402 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-theme-default.json',
403 // ]
404 ],
405
406 // [
407 // 'text_label' => __( 'Shop - Custom Layout 1', 'shopbuilder' ),
408 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-1.jpg' ),
409 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-1/',
410 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-1.json',
411 // ],
412 // [
413 // 'text_label' => __( 'Shop - Custom Layout 2', 'shopbuilder' ),
414 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-2.jpg' ),
415 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-2/',
416 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop–builder-custom-layout-2.json',
417 // ],
418 // [
419 // 'text_label' => __( 'Shop - List View', 'shopbuilder' ),
420 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-list-view-1.jpg' ),
421 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-list-view-1/',
422 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-list-view-1.json',
423 // ],
424 // [
425 // 'text_label' => __( 'Shop - List View 2', 'shopbuilder' ),
426 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-list-view-2.jpg' ),
427 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-list-view-2/',
428 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-list-view-2.json',
429 // ],
430 ],
431 'archive' => [
432 // [
433 // 'text_label' => __( 'Archive – Theme Default', 'shopbuilder' ),
434 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-theme-default.jpg' ),
435 // 'live_preview' => $demo_root_url . '/shop/',
436 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-theme-default.json',
437 // ],
438 // [
439 // 'text_label' => __( 'Archive – Left Sidebar', 'shopbuilder' ),
440 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-left-sidebar.jpg' ),
441 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-left-sidebar-shop-builder-custom/',
442 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-left-sidebar.json',
443 // ],
444 // [
445 // 'text_label' => __( 'Archive - Custom Layout 1', 'shopbuilder' ),
446 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-1.jpg' ),
447 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-1/',
448 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-1.json',
449 // ],
450 // [
451 // 'text_label' => __( 'Archive - Custom Layout 2', 'shopbuilder' ),
452 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-2.jpg' ),
453 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-2/',
454 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop–builder-custom-layout-2.json',
455 // ],
456 // [
457 // 'text_label' => __( 'Archive - List View 1', 'shopbuilder' ),
458 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-list-view-1.jpg' ),
459 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-list-view-1/',
460 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-list-view–1.json',
461 // ],
462 // [
463 // 'text_label' => __( 'Archive - List View 2', 'shopbuilder' ),
464 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/shop-custom-layout-list-view-2.jpg' ),
465 // 'live_preview' => $demo_root_url . '/rtsb-template/shop-builder-custom-layout-list-view-2/',
466 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/shop/shop-custom-layout-list-view-2.json',
467 // ],
468
469 ],
470 'cart' => [
471 // [
472 // 'text_label' => __( 'Cart - View 1', 'shopbuilder' ),
473 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/cart-view-1.jpg' ),
474 // 'live_preview' => $demo_root_url . '/rtsb-template/cart-page-demo-1/',
475 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/cart/cart-view-1.json',
476 // ],
477 // [
478 // 'text_label' => __( 'Cart - View 2', 'shopbuilder' ),
479 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/cart-view-2.jpg' ),
480 // 'live_preview' => $demo_root_url . '/rtsb-template/cart-page-demo-2/',
481 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/cart/cart-view-2.json',
482 // ],
483 ],
484 'checkout' => [
485 // [
486 // 'text_label' => __( 'Checkout - View 1', 'shopbuilder' ),
487 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/checkout-demo-1.jpg' ),
488 // 'live_preview' => $demo_root_url . '/rtsb-template/checkout-page-layout-1/',
489 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/checkout/checkout-view-1.json',
490 // ],
491 // [
492 // 'text_label' => __( 'Checkout - View 2', 'shopbuilder' ),
493 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/checkout-demo-2.jpg' ),
494 // 'live_preview' => $demo_root_url . '/rtsb-template/checkout-page-demo-2/',
495 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/checkout/checkout-view-2.json',
496 // ],
497 // [
498 // 'text_label' => __( 'Checkout - View 3', 'shopbuilder' ),
499 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/checkout-demo-3.jpg' ),
500 // 'live_preview' => $demo_root_url . '/rtsb-template/checkout-page-demo-3/',
501 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/checkout/checkout-view-3.json',
502 // ],
503 // [
504 // 'text_label' => __( 'Checkout - View 4', 'shopbuilder' ),
505 // 'image' => rtsb()->get_assets_uri( 'images/layout-preview/checkout-demo-4.jpg' ),
506 // 'live_preview' => $demo_root_url . '/rtsb-template/checkout-page-demo-4/',
507 // 'import_file' => rtsb()->plugin_path() . '/sample-layout/checkout/checkout-view-4.json',
508 // ],
509
510 ],
511 ];
512 $page_layout = apply_filters( 'rtsb/page/default/layout', $page_layout );
513
514 return $page_layout;
515 }
516
517 }
518