PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.3.0
ShopBuilder – WooCommerce Builder For Elementor v3.3.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 / Controllers / Builder / BuilderCpt.php

BuilderCpt.php in ShopBuilder – WooCommerce Builder For Elementor 3.3.0, at app/Controllers/Builder/BuilderCpt.php

659 lines 22.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Builder Custom post type
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Builder;
9
10 defined( 'ABSPATH' ) || exit();
11
12 use RadiusTheme\SB\Models\TemplateSettings;
13 use WP_Query;
14 use RadiusTheme\SB\Helpers\Fns;
15 use RadiusTheme\SB\Helpers\BuilderFns;
16 use RadiusTheme\SB\Traits\SingletonTrait;
17
18 /**
19 * Builder Custom post type
20 */
21 class BuilderCpt {
22 /**
23 * Singleton
24 */
25 use SingletonTrait;
26
27 /**
28 * Final constructor.
29 */
30 private function __construct() {
31 add_action( 'init', [ $this, 'template_builder_post_type' ] );
32 add_filter( 'post_row_actions', [ $this, 'filter_post_row_actions' ], 11, 1 );
33 // Admin column.
34 add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_columns', [ $this, 'add_new_columns' ] );
35 add_action( 'manage_' . BuilderFns::$post_type_tb . '_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 );
36 add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_sortable_columns', [ $this, 'register_sortable_columns' ] );
37 add_action( 'pre_get_posts', [ $this, 'sortable_columns_query' ] );
38 add_filter( 'template_include', [ $this, 'builder_template' ], 99 );
39 add_filter( 'template_redirect', [ $this, 'restrict_preview_access' ], 99 );
40
41 add_filter( 'parse_query', [ $this, 'query_filter' ] );
42 // Add filter for search.
43 add_action( 'restrict_manage_posts', [ $this, 'add_filter' ] );
44 // Post Content Remove For Elementor Builder.
45 add_action( 'save_post_' . BuilderFns::$post_type_tb, [ $this, 'on_save_post' ], 10, 2 );
46 }
47
48 /**
49 * Hook into post save to clear post content for specific post type and editor.
50 *
51 * This method checks if the post is being updated (not newly created),
52 * and if the post type matches the target type defined in BuilderFns::$post_type_tb.
53 * If the post is edited with Elementor, it clears the post_content directly
54 * from the database and clears the post cache.
55 *
56 * @param int $post_ID ID of the post being saved.
57 * @param WP_Post $post Post object.
58 *
59 * @return void
60 */
61 public function on_save_post( $post_ID, $post ) {
62 // Only proceed on update and specific post type.
63 if ( BuilderFns::$post_type_tb !== $post->post_type ) {
64 return;
65 }
66 if ( 'elementor' !== Fns::page_edit_with( $post_ID ) ) {
67 return;
68 }
69 global $wpdb;
70 // Directly update the post_content to empty.
71 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
72 $wpdb->update(
73 $wpdb->posts,
74 [ 'post_content' => '' ],
75 [ 'ID' => $post_ID ]
76 );
77 // Clear cache so changes reflect properly.
78 clean_post_cache( $post_ID );
79 }
80
81 /**
82 * Public function add_filter.
83 * Added search filter for type of template
84 *
85 * @since 1.0.0
86 */
87 public function add_filter() {
88
89 global $typenow;
90
91 if ( BuilderFns::$post_type_tb != $typenow ) {
92 return;
93 }
94 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
95 $selected = isset( $_GET['type'] ) ? sanitize_key( $_GET['type'] ) : '';
96 $builder_page_types = BuilderFns::builder_page_types();
97 ?>
98 <select name="template_type" id="type">
99 <option value="all" <?php selected( 'all', $selected ); ?>><?php esc_html_e( 'Template Type ', 'shopbuilder' ); ?></option>
100 <?php foreach ( $builder_page_types as $key => $value ) { ?>
101 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected ); ?>><?php echo esc_html( $value ); ?></option>
102 <?php } ?>
103 </select>
104 <?php
105 }
106
107 /**
108 * Post type function
109 *
110 * @return void
111 */
112 public function template_builder_post_type() {
113 /**
114 * Template Builder Post type
115 */
116 $tb_labels = [
117 'name' => esc_html_x( 'WooCommerce Page Builder', 'Post Type General Name', 'shopbuilder' ),
118 'singular_name' => esc_html_x( 'Templates Builder', 'Post Type Singular Name', 'shopbuilder' ),
119 'menu_name' => esc_html__( 'Templates Builder', 'shopbuilder' ),
120 'name_admin_bar' => esc_html__( 'Templates Builder', 'shopbuilder' ),
121 'archives' => esc_html__( 'WC Page Archives', 'shopbuilder' ),
122 'attributes' => esc_html__( 'Page Attributes', 'shopbuilder' ),
123 'parent_item_colon' => esc_html__( 'Parent Item:', 'shopbuilder' ),
124 'all_items' => esc_html__( 'Templates Builder', 'shopbuilder' ),
125 'add_new_item' => esc_html__( 'Add New Page', 'shopbuilder' ),
126 'add_new' => esc_html__( 'Add New', 'shopbuilder' ),
127 'new_item' => esc_html__( 'New Page', 'shopbuilder' ),
128 'edit_item' => esc_html__( 'Edit Page', 'shopbuilder' ),
129 'update_item' => esc_html__( 'Update Page', 'shopbuilder' ),
130 'view_item' => esc_html__( 'View Page', 'shopbuilder' ),
131 'view_items' => esc_html__( 'View Pages', 'shopbuilder' ),
132 'search_items' => esc_html__( 'Search Pages', 'shopbuilder' ),
133 'not_found' => esc_html__( 'Not found', 'shopbuilder' ),
134 'not_found_in_trash' => esc_html__( 'Not found in Trash', 'shopbuilder' ),
135 'featured_image' => esc_html__( 'Featured Image', 'shopbuilder' ),
136 'set_featured_image' => esc_html__( 'Set featured image', 'shopbuilder' ),
137 'remove_featured_image' => esc_html__( 'Remove featured image', 'shopbuilder' ),
138 'use_featured_image' => esc_html__( 'Use as featured image', 'shopbuilder' ),
139 'insert_into_item' => esc_html__( 'Insert into page', 'shopbuilder' ),
140 'uploaded_to_this_item' => esc_html__( 'Uploaded to this page', 'shopbuilder' ),
141 'items_list' => esc_html__( 'Pages list', 'shopbuilder' ),
142 'items_list_navigation' => esc_html__( 'Pages list navigation', 'shopbuilder' ),
143 'filter_items_list' => esc_html__( 'Filter from list', 'shopbuilder' ),
144 ];
145
146 $tb_args = [
147 'label' => esc_html__( 'Templates Builder', 'shopbuilder' ),
148 'description' => esc_html__( 'Shopbuilder Template', 'shopbuilder' ),
149 'labels' => $tb_labels,
150 'supports' => [ 'title', 'editor', 'elementor', 'author', 'permalink', 'comments' ],
151 'hierarchical' => false,
152 'public' => true,
153 'show_ui' => true,
154 'show_in_menu' => 'rtsb',
155 'show_in_admin_bar' => false,
156 'show_in_nav_menus' => true,
157 'can_export' => true,
158 'has_archive' => false,
159 'rewrite' => [
160 'slug' => 'rtsb-template',
161 'pages' => false,
162 'with_front' => true,
163 'feeds' => false,
164 ],
165 'query_var' => true,
166 'publicly_queryable' => true,
167 // 'capability_type' => 'product', Will Remove this line in the future.
168 'show_in_rest' => true,
169 'rest_base' => BuilderFns::$post_type_tb,
170 ];
171
172 $tb_args = apply_filters( 'rtsb/builder/template_args', $tb_args );
173
174 register_post_type( BuilderFns::$post_type_tb, $tb_args );
175
176 // Flash rewrite rules.
177 $this->flush_rewrite_rules();
178 }
179
180 /**
181 * Flush rewrite
182 *
183 * @return void
184 */
185 public function flush_rewrite_rules() {
186 if ( get_option( 'shopbuilder_permalinks_flushed', 'no' ) !== 'yes' ) {
187 flush_rewrite_rules();
188 update_option( 'shopbuilder_permalinks_flushed', 'yes' );
189 }
190 }
191
192 /**
193 * Add new columns to the post table
194 *
195 * @param array $columns - Current columns on the list post.
196 */
197 public function add_new_columns( $columns ) {
198 $column_meta = [
199 'type' => esc_html__( 'Template Type', 'shopbuilder' ),
200 'edit_with' => esc_html__( 'Editor Type', 'shopbuilder' ),
201 'set_default' => esc_html__( 'Set as Active', 'shopbuilder' ),
202 ];
203
204 unset( $columns['comments'] );
205
206 $columns = array_merge(
207 array_slice( $columns, 0, 2 ),
208 $column_meta,
209 array_slice( $columns, 2 )
210 );
211
212 return $columns;
213 }
214
215 /**
216 * Display data in new columns
217 *
218 * @param string $column table column.
219 * @param string $post_id Post id.
220 *
221 * @return void
222 */
223 public function custom_columns( $column, $post_id ) { // phpcs:ignore Generic.Metrics.NestingLevel.TooHigh
224 $post_id = absint( $post_id );
225 $types = BuilderFns::builder_page_types();
226 $template_type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types );
227
228 switch ( $column ) {
229 case 'type':
230 $the_type = ! empty( $types[ $template_type ] ) ? '<b>' . esc_html( ucwords( $types[ $template_type ] ) ) . '</b>' : '';
231 $the_type = $this->template_type_suffix( $the_type, $template_type, $post_id );
232 Fns::print_html( apply_filters( 'rtsb/columns/template/types/text', $the_type, $template_type, $post_id ) );
233 break;
234 case 'edit_with':
235 $edit_by = Fns::page_edit_with( $post_id );
236 echo esc_html( ucfirst( $edit_by ) );
237 break;
238 case 'set_default':
239 $singleton_types = apply_filters(
240 'rtsb/builder/singleton_types',
241 array_keys( BuilderFns::builder_page_types() )
242 );
243 if ( in_array( $template_type, $singleton_types, true ) ) {
244 $is_set_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
245 } else {
246 // Pool type: read per-post meta flag — multiple templates of the same type can be enabled simultaneously.
247 $is_set_default = 'on' === get_post_meta( $post_id, '_rtsb_tb_enabled_in_pool', true ) ? $post_id : 0;
248 }
249 $is_published = 'publish' === get_post_status( $post_id );
250 $page_type_for = $template_type;
251 if ( 'product' === $template_type ) {
252 $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
253 switch ( $product_page_for ) {
254 case 'specific_products':
255 $page_type_for = 'template-' . $post_id . '-specific-products';
256 $set_default = BuilderFns::get_specific_product_as_default( $post_id );
257 if ( $set_default ) {
258 $is_set_default = $post_id;
259 }
260 if ( ! $set_default && $is_set_default === $post_id ) {
261 $is_set_default = '';
262 }
263 break;
264 case 'product_cats':
265 $page_type_for = 'product-page-template-' . $post_id . '-specific-category';
266 $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
267 $pp_cat_set_default = TemplateSettings::instance()->get_option( $set_default_option_name );
268 if ( $pp_cat_set_default ) {
269 $is_set_default = $post_id;
270 }
271 break;
272 case 'product_tags':
273 $page_type_for = 'product-page-template-' . $post_id . '-specific-tag';
274 $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
275 $pp_tag_set_default = TemplateSettings::instance()->get_option( $set_default_option_name );
276 if ( $pp_tag_set_default ) {
277 $is_set_default = $post_id;
278 }
279 break;
280 case 'product_brands':
281 $page_type_for = 'product-page-template-' . $post_id . '-specific-brand';
282 $set_default_option_name = BuilderFns::option_name_product_page_specific_brand_set_default( $post_id );
283 $pp_brand_set_default = TemplateSettings::instance()->get_option( $set_default_option_name );
284 if ( $pp_brand_set_default ) {
285 $is_set_default = $post_id;
286 }
287 break;
288 default:
289 break;
290 }
291 } elseif ( 'archive' === $template_type ) {
292 $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
293 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
294 if ( ! empty( $categories_name ) && $set_default ) {
295 $is_set_default = $post_id;
296 $page_type_for = 'template-' . $post_id . '-specific-category';
297 } else {
298 $option_name = BuilderFns::option_name( $template_type );
299 $is_set_default = TemplateSettings::instance()->get_option( $option_name );
300 $set_default = $is_set_default;
301 }
302 if ( ! $set_default && $is_set_default === $post_id ) {
303 $is_set_default = '';
304 }
305 }
306
307 $is_set_default = apply_filters( 'rtsb/builder/columns/set_default', $is_set_default, $post_id, $template_type );
308 $page_type_for = apply_filters( 'rtsb/builder/columns/page_type_for', $page_type_for, $post_id, $template_type );
309 ?>
310 <span class="rtsb-switch-wrapper page-type-<?php echo esc_attr( $page_type_for ); ?>" <?php echo ! $is_published ? 'style="pointer-events: none;"' : null; ?> title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>">
311 <label class="rtsb-switch">
312 <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $template_type, $is_set_default, $is_published ); ?>
313 <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $template_type ); ?>" style='display:none;'></div>
314 <input disabled="disabled" value="<?php echo absint( $post_id ); ?>" class="rtsb_set_default" name="set_default" type="checkbox" <?php echo esc_attr( $post_id === $is_set_default ? 'checked' : '' ); ?> >
315 <span class="rtsb-slider rtsb-round ">
316 <span class="rtsb-loader"></span>
317 </span>
318 </label>
319 </span>
320 <?php
321 break;
322 }
323 }
324
325 /**
326 * Appends template sub-type suffix and selected item details to the type column text.
327 *
328 * For product templates: shows "Template For Selected Products/Categories/Tags"
329 * with linked item names below.
330 * For archive templates: shows "Template For Selected Category" with linked names.
331 *
332 * @param string $the_type The current type column HTML.
333 * @param string $template_type The template type slug.
334 * @param int $post_id The builder post ID.
335 *
336 * @return string
337 */
338 private function template_type_suffix( $the_type, $template_type, $post_id ) {
339 if ( 'product' === $template_type ) {
340 $the_type = $this->product_template_type_suffix( $the_type, $post_id );
341 } elseif ( 'archive' === $template_type ) {
342 $the_type = $this->archive_template_type_suffix( $the_type, $post_id );
343 }
344
345 return $the_type;
346 }
347
348 /**
349 * Appends product template sub-type suffix with linked product/category/tag names.
350 *
351 * @param string $the_type The current type column HTML.
352 * @param int $post_id The builder post ID.
353 *
354 * @return string
355 */
356 private function product_template_type_suffix( $the_type, $post_id ) {
357 $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
358 $has_pro = rtsb()->has_pro();
359 $pro_label = ! $has_pro ? ' <span class="rtsb-pro-label" style="color:#fff;background:#ff5722;padding:1px 6px;border-radius:3px;font-size:11px;font-weight:600;">' . esc_html__( 'Pro', 'shopbuilder' ) . '</span>' : '';
360
361 switch ( $product_page_for ) {
362 case 'specific_products':
363 $the_type .= ' - ' . esc_html__( 'Template For Selected Products', 'shopbuilder' ) . $pro_label;
364 if ( $has_pro ) {
365 $the_type .= $this->get_selected_products_html( $post_id );
366 }
367 break;
368 case 'product_cats':
369 $the_type .= ' - ' . esc_html__( 'Template For Selected Categories', 'shopbuilder' ) . $pro_label;
370 if ( $has_pro ) {
371 $the_type .= $this->get_selected_terms_html( $post_id, 'product_cat' );
372 }
373 break;
374 case 'product_tags':
375 $the_type .= ' - ' . esc_html__( 'Template For Selected Tags', 'shopbuilder' ) . $pro_label;
376 if ( $has_pro ) {
377 $the_type .= $this->get_selected_terms_html( $post_id, 'product_tag' );
378 }
379 break;
380 }
381
382 return $the_type;
383 }
384
385 /**
386 * Appends archive template sub-type suffix with linked category names.
387 *
388 * @param string $the_type The current type column HTML.
389 * @param int $post_id The builder post ID.
390 *
391 * @return string
392 */
393 private function archive_template_type_suffix( $the_type, $post_id ) {
394 $option_name = BuilderFns::archive_option_name_by_template_id( $post_id );
395 $categories = TemplateSettings::instance()->get_option( $option_name );
396
397 if ( ! empty( $categories ) && is_array( $categories ) ) {
398 $has_pro = rtsb()->has_pro();
399 $pro_label = ! $has_pro ? ' <span class="rtsb-pro-label" style="color:#fff;background:#ff5722;padding:1px 6px;border-radius:3px;font-size:11px;font-weight:600;">' . esc_html__( 'Pro', 'shopbuilder' ) . '</span>' : '';
400 $the_type .= ' - ' . esc_html__( 'Template For Selected Category', 'shopbuilder' ) . $pro_label;
401 $the_type .= $this->get_selected_archive_categories_html( $categories );
402 }
403
404 return $the_type;
405 }
406
407 /**
408 * Gets HTML list of selected archive category names with links.
409 *
410 * @param array $category_slugs Array of term slugs.
411 *
412 * @return string
413 */
414 private function get_selected_archive_categories_html( $category_slugs ) {
415 if ( empty( $category_slugs ) || ! is_array( $category_slugs ) ) {
416 return '';
417 }
418
419 $links = [];
420
421 foreach ( $category_slugs as $cat_slug ) {
422 $term = get_term_by( 'slug', $cat_slug, 'product_cat' );
423
424 if ( is_wp_error( $term ) || ! $term ) {
425 continue;
426 }
427
428 $term_link = get_term_link( $term );
429
430 if ( is_wp_error( $term_link ) ) {
431 continue;
432 }
433
434 $links[] = '<a href="' . esc_url( $term_link ) . '" target="_blank">'
435 . esc_html( $term->name ) . '</a>';
436 }
437
438 if ( empty( $links ) ) {
439 return '';
440 }
441
442 return '<br><small>' . implode( ', ', $links ) . '</small>';
443 }
444
445 /**
446 * Gets HTML list of selected product names with links to their detail pages.
447 *
448 * @param int $post_id The builder post ID.
449 *
450 * @return string
451 */
452 private function get_selected_products_html( $post_id ) {
453 $option_name = BuilderFns::option_name_by_template_id( $post_id );
454 $product_ids = TemplateSettings::instance()->get_option( $option_name );
455
456 if ( empty( $product_ids ) || ! is_array( $product_ids ) ) {
457 return '';
458 }
459
460 $links = [];
461
462 foreach ( $product_ids as $product_id ) {
463 $product_id = absint( $product_id );
464 $product = wc_get_product( $product_id );
465
466 if ( ! $product ) {
467 continue;
468 }
469
470 $links[] = '<a href="' . esc_url( get_permalink( $product_id ) ) . '" target="_blank">'
471 . esc_html( $product->get_name() ) . '</a>';
472 }
473
474 if ( empty( $links ) ) {
475 return '';
476 }
477
478 return '<br><small>' . implode( ', ', $links ) . '</small>';
479 }
480
481 /**
482 * Gets HTML list of selected term names with links.
483 *
484 * @param int $post_id The builder post ID.
485 * @param string $taxonomy The taxonomy slug.
486 *
487 * @return string
488 */
489 private function get_selected_terms_html( $post_id, $taxonomy ) {
490 if ( 'product_cat' === $taxonomy ) {
491 $option_name = BuilderFns::option_name_product_page_selected_cat( $post_id );
492 } else {
493 $option_name = BuilderFns::option_name_product_page_selected_tag( $post_id );
494 }
495
496 $term_ids = TemplateSettings::instance()->get_option( $option_name );
497
498 if ( empty( $term_ids ) || ! is_array( $term_ids ) ) {
499 return '';
500 }
501
502 $links = [];
503
504 foreach ( $term_ids as $term_id ) {
505 $term = get_term( absint( $term_id ), $taxonomy );
506
507 if ( is_wp_error( $term ) || ! $term ) {
508 continue;
509 }
510
511 $term_link = get_term_link( $term );
512
513 if ( is_wp_error( $term_link ) ) {
514 continue;
515 }
516
517 $links[] = '<a href="' . esc_url( $term_link ) . '" target="_blank">'
518 . esc_html( $term->name ) . '</a>';
519 }
520
521 if ( empty( $links ) ) {
522 return '';
523 }
524
525 return '<br><small>' . implode( ', ', $links ) . '</small>';
526 }
527
528 /**
529 * Register sortable columns
530 *
531 * @param [type] $columns column list.
532 *
533 * @return array
534 */
535 public function register_sortable_columns( $columns ) {
536 $columns['type'] = 'type';
537
538 return $columns;
539 }
540
541 /**
542 * Meta sortable function.
543 *
544 * @param object $query query object.
545 *
546 * @return void
547 */
548 public function sortable_columns_query( $query ) {
549 if ( ! is_admin() || ! $this->is_current_screen() ) {
550 return;
551 }
552 $orderby = $query->get( 'orderby' );
553 if ( 'type' === $orderby ) {
554 $query->set( 'meta_key', BuilderFns::template_type_meta_key() );
555 $query->set( 'orderby', 'meta_value' );
556 }
557 }
558
559 /**
560 * Check template screen
561 *
562 * @return boolean
563 */
564 public function is_current_screen() {
565 global $pagenow, $typenow;
566
567 return 'edit.php' === $pagenow && BuilderFns::$post_type_tb === $typenow;
568 }
569
570 /**
571 * Manage Template filter by template type
572 *
573 * @param WP_Query $query WordPress main query.
574 *
575 * @return void
576 */
577 public function query_filter( WP_Query $query ) {
578
579 if ( ! is_admin() || ! $this->is_current_screen() || ! empty( $query->query_vars['meta_key'] ) ) {
580 return;
581 }
582 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
583 $type = isset( $_GET['template_type'] ) ? sanitize_key( $_GET['template_type'] ) : '';
584
585 if ( '' != $type && 'all' != $type ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
586 $query->query_vars['meta_key'] = BuilderFns::template_type_meta_key(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
587 $query->query_vars['meta_value'] = $type; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
588 $query->query_vars['meta_compare'] = '=';
589 }
590 }
591
592 /**
593 * Load Template.
594 *
595 * @param string $template Template File.
596 *
597 * @return string
598 */
599 public function builder_template( $template ) {
600 $builder_page_id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_page();
601 if ( defined( 'ELEMENTOR_VERSION' ) && $builder_page_id ) { // Elementor Check.
602 $page_template = get_post_meta( $builder_page_id, '_wp_page_template', true );
603 $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php';
604 if ( 'elementor_canvas' === $page_template ) {
605 $new_template = RTSB_ABSPATH . 'page-templates/elementor-canvas.php';
606 } elseif ( 'elementor_header_footer' === $page_template ) {
607 $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php';
608 }
609 if ( file_exists( $new_template ) ) {
610 $template = $new_template;
611 }
612 }
613
614 return $template;
615 }
616
617 /**
618 * Restrict the preview access.
619 *
620 * @return void
621 */
622 public function restrict_preview_access() {
623 if ( ! apply_filters( 'rtsb/builder/preview/access', true ) ) {
624 return;
625 }
626
627 if ( is_singular( 'rtsb_builder' ) ) {
628 if ( ! is_user_logged_in() ) {
629 wp_safe_redirect( home_url() );
630 }
631 }
632 }
633
634 /**
635 * Add/Remove edit link in dashboard.
636 *
637 * Add or remove an edit link to the post/page action links on the post/pages list table.
638 *
639 * Fired by `post_row_actions` and `page_row_actions` filters.
640 *
641 * @access public
642 *
643 * @param array $actions An array of row action links.
644 *
645 * @return array An updated array of row action links.
646 */
647 public function filter_post_row_actions( $actions ) {
648 if ( $this->is_current_screen() ) {
649 unset( $actions['inline hide-if-no-js'] );
650
651 if ( isset( $actions['view'] ) ) {
652 $actions['view'] = str_replace( __( 'View', 'shopbuilder' ), __( 'Preview', 'shopbuilder' ), $actions['view'] );
653 }
654 }
655
656 return $actions;
657 }
658 }
659