PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.1.3
ShopBuilder – WooCommerce Builder For Elementor v3.1.3
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/Controllers/Builder/BuilderCpt.php +115 -45 2.0.2 → 3.1.3 View file →
@@ -8,11 +8,13 @@
8 8 namespace RadiusTheme\SB\Controllers\Builder;
9 9
10 10 defined( 'ABSPATH' ) || exit();
11 11
12 -use RadiusTheme\SB\Traits\SingletonTrait;
12 +use RadiusTheme\SB\Models\TemplateSettings;
13 +use WP_Query;
13 14 use RadiusTheme\SB\Helpers\Fns;
14 15 use RadiusTheme\SB\Helpers\BuilderFns;
16 +use RadiusTheme\SB\Traits\SingletonTrait;
15 17
16 18 /**
17 19 * Builder Custom post type
18 20 */
@@ -33,18 +35,50 @@
33 35 add_action( 'manage_' . BuilderFns::$post_type_tb . '_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 );
34 36 add_filter( 'manage_edit-' . BuilderFns::$post_type_tb . '_sortable_columns', [ $this, 'register_sortable_columns' ] );
35 37 add_action( 'pre_get_posts', [ $this, 'sortable_columns_query' ] );
36 38 add_filter( 'template_include', [ $this, 'builder_template' ], 99 );
39 + add_filter( 'template_redirect', [ $this, 'restrict_preview_access' ], 99 );
37 40
38 41 add_filter( 'parse_query', [ $this, 'query_filter' ] );
39 - // add filter for search
42 + // Add filter for search.
40 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 + }
41 47
42 - add_action( 'in_admin_header', [ $this, 'remove_all_notices' ], 1000 );
43 -
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 );
44 79 }
45 80
46 -
47 81 /**
48 82 * Public function add_filter.
49 83 * Added search filter for type of template
50 84 *
@@ -53,12 +87,12 @@
53 87 public function add_filter() {
54 88
55 89 global $typenow;
56 90
57 - if ( $typenow != BuilderFns::$post_type_tb ) {
91 + if ( BuilderFns::$post_type_tb != $typenow ) {
58 92 return;
59 93 }
60 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended. No need nonce.
94 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
61 95 $selected = isset( $_GET['type'] ) ? sanitize_key( $_GET['type'] ) : '';
62 96 $builder_page_types = BuilderFns::builder_page_types();
63 97 ?>
64 98 <select name="template_type" id="type">
@@ -67,9 +101,8 @@
67 101 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $selected ); ?>><?php echo esc_html( $value ); ?></option>
68 102 <?php } ?>
69 103 </select>
70 104 <?php
71 -
72 105 }
73 106
74 107 /**
75 108 * Post type function
@@ -130,20 +163,19 @@
130 163 'feeds' => false,
131 164 ],
132 165 'query_var' => true,
133 166 'publicly_queryable' => true,
134 - 'capability_type' => 'product',
167 + // 'capability_type' => 'product', Will Remove this line in the future.
135 168 'show_in_rest' => true,
136 169 'rest_base' => BuilderFns::$post_type_tb,
137 170 ];
138 171
139 - $tb_args = apply_filters( 'rtsb_register_template_builder_args', $tb_args );
172 + $tb_args = apply_filters( 'rtsb/builder/template_args', $tb_args );
140 173
141 174 register_post_type( BuilderFns::$post_type_tb, $tb_args );
142 175
143 176 // Flash rewrite rules.
144 177 $this->flush_rewrite_rules();
145 -
146 178 }
147 179
148 180 /**
149 181 * Flush rewrite
@@ -187,17 +219,17 @@
187 219 * @param string $post_id Post id.
188 220 *
189 221 * @return void
190 222 */
191 - public function custom_columns( $column, $post_id ) {
192 - $post_id = absint( $post_id );
193 - $types = BuilderFns::builder_page_types();
194 - $type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types );
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 );
195 227
196 228 switch ( $column ) {
197 229 case 'type':
198 - $the_type = ! empty( $types[ $type ] ) ? esc_html( ucwords( $types[ $type ] ) ) : '';
199 - echo apply_filters( 'rtsb/columns/template/types/text', $the_type, $type, $post_id );
230 + $the_type = ! empty( $types[ $template_type ] ) ? '<b>' . esc_html( ucwords( $types[ $template_type ] ) ) . '</b>' : '';
231 + Fns::print_html( apply_filters( 'rtsb/columns/template/types/text', $the_type, $template_type, $post_id ) );
200 232 break;
201 233 case 'edit_with':
202 234 $edit_by = Fns::page_edit_with( $post_id );
203 235 echo esc_html( ucfirst( $edit_by ) );
@@ -202,31 +234,59 @@
202 234 $edit_by = Fns::page_edit_with( $post_id );
203 235 echo esc_html( ucfirst( $edit_by ) );
204 236 break;
205 237 case 'set_default':
206 - $is_set_default = absint( BuilderFns::builder_page_id_by_type( $type ) );
238 + $is_set_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
207 239 $is_published = 'publish' === get_post_status( $post_id );
208 - $page_type_for = $type;
209 - if ( 'product' === $type ) {
210 - $product_ids = apply_filters( 'rtsb/product/page/builder/selected/products', [], $post_id );
211 - $set_default = BuilderFns::get_specific_product_as_default( $post_id );
212 - if ( ! empty( $product_ids ) && $set_default ) {
213 - $is_set_default = $post_id;
214 - $page_type_for = 'template-' . $post_id . '-specific-products';
240 + $page_type_for = $template_type;
241 + if ( 'product' === $template_type ) {
242 + $product_page_for = get_post_meta( $post_id, '_is_product_page_template_for', true );
243 + switch ( $product_page_for ) {
244 + case 'specific_products':
245 + $page_type_for = 'template-' . $post_id . '-specific-products';
246 + $set_default = BuilderFns::get_specific_product_as_default( $post_id );
247 + if ( $set_default ) {
248 + $is_set_default = $post_id;
249 + }
250 + if ( ! $set_default && $is_set_default === $post_id ) {
251 + $is_set_default = '';
252 + }
253 + break;
254 + case 'product_cats':
255 + $page_type_for = 'product-page-template-' . $post_id . '-specific-category';
256 + $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id );
257 + $pp_cat_set_default = TemplateSettings::instance()->get_option( $set_default_option_name );
258 + if ( $pp_cat_set_default ) {
259 + $is_set_default = $post_id;
260 + }
261 + break;
262 + case 'product_tags':
263 + $page_type_for = 'product-page-template-' . $post_id . '-specific-tag';
264 + $set_default_option_name = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id );
265 + $pp_tag_set_default = TemplateSettings::instance()->get_option( $set_default_option_name );
266 + if ( $pp_tag_set_default ) {
267 + $is_set_default = $post_id;
268 + }
269 + break;
270 + default:
271 + break;
215 272 }
216 - } elseif ( 'archive' === $type ) {
217 - $categories_name = apply_filters( 'rtsb/archive/page/builder/selected/categories', [], $post_id );
273 + } elseif ( 'archive' === $template_type ) {
274 + $categories_name = apply_filters( 'rtsb/template/builder/selected/categories', [], $post_id, $template_type );
218 275 $set_default = BuilderFns::get_specific_category_as_default( $post_id );
219 276 if ( ! empty( $categories_name ) && $set_default ) {
220 277 $is_set_default = $post_id;
221 278 $page_type_for = 'template-' . $post_id . '-specific-category';
222 279 }
280 + if ( ! $set_default && $is_set_default === $post_id ) {
281 + $is_set_default = '';
282 + }
223 283 }
224 284 ?>
225 285 <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' ); ?>">
226 286 <label class="rtsb-switch">
227 - <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $type, $is_set_default, $is_published ); ?>
228 - <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $type ); ?>" style='display:none;'></div>
287 + <?php do_action( 'rtsb/set/default/column/extra/field', $post_id, $template_type, $is_set_default, $is_published ); ?>
288 + <div class="rtsb_template_type" data-template_type="<?php echo esc_attr( $template_type ); ?>" style='display:none;'></div>
229 289 <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' : '' ); ?> >
230 290 <span class="rtsb-slider rtsb-round ">
231 291 <span class="rtsb-loader"></span>
232 292 </span>
@@ -281,22 +341,23 @@
281 341
282 342 /**
283 343 * Manage Template filter by template type
284 344 *
285 - * @param \WP_Query $query WordPress main query.
345 + * @param WP_Query $query WordPress main query.
286 346 *
287 347 * @return void
288 348 */
289 - public function query_filter( \WP_Query $query ) {
349 + public function query_filter( WP_Query $query ) {
290 350
291 351 if ( ! is_admin() || ! $this->is_current_screen() || ! empty( $query->query_vars['meta_key'] ) ) {
292 352 return;
293 353 }
354 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
294 355 $type = isset( $_GET['template_type'] ) ? sanitize_key( $_GET['template_type'] ) : '';
295 356
296 357 if ( '' != $type && 'all' != $type ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
297 358 $query->query_vars['meta_key'] = BuilderFns::template_type_meta_key(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
298 - $query->query_vars['meta_value'] = $type;
359 + $query->query_vars['meta_value'] = $type; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
299 360 $query->query_vars['meta_compare'] = '=';
300 361 }
301 362 }
302 363
@@ -308,9 +369,9 @@
308 369 * @return string
309 370 */
310 371 public function builder_template( $template ) {
311 372 $builder_page_id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_page();
312 - if ( $builder_page_id ) {
373 + if ( defined( 'ELEMENTOR_VERSION' ) && $builder_page_id ) { // Elementor Check.
313 374 $page_template = get_post_meta( $builder_page_id, '_wp_page_template', true );
314 375 $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php';
315 376 if ( 'elementor_canvas' === $page_template ) {
316 377 $new_template = RTSB_ABSPATH . 'page-templates/elementor-canvas.php';
@@ -325,8 +386,25 @@
325 386 return $template;
326 387 }
327 388
328 389 /**
390 + * Restrict the preview access.
391 + *
392 + * @return void
393 + */
394 + public function restrict_preview_access() {
395 + if ( ! apply_filters( 'rtsb/builder/preview/access', true ) ) {
396 + return;
397 + }
398 +
399 + if ( is_singular( 'rtsb_builder' ) ) {
400 + if ( ! is_user_logged_in() ) {
401 + wp_safe_redirect( home_url() );
402 + }
403 + }
404 + }
405 +
406 + /**
329 407 * Add/Remove edit link in dashboard.
330 408 *
331 409 * Add or remove an edit link to the post/page action links on the post/pages list table.
332 410 *
@@ -339,22 +417,14 @@
339 417 * @return array An updated array of row action links.
340 418 */
341 419 public function filter_post_row_actions( $actions ) {
342 420 if ( $this->is_current_screen() ) {
343 - // unset( $actions['view'] );
344 421 unset( $actions['inline hide-if-no-js'] );
422 +
423 + if ( isset( $actions['view'] ) ) {
424 + $actions['view'] = str_replace( __( 'View', 'shopbuilder' ), __( 'Preview', 'shopbuilder' ), $actions['view'] );
425 + }
345 426 }
346 427
347 428 return $actions;
348 - }
349 -
350 - /**
351 - * Remove admin notices
352 - */
353 - public function remove_all_notices() {
354 - $screen = get_current_screen();
355 - if ( 'edit-rtsb_builder' === $screen->id ) {
356 - remove_all_actions( 'admin_notices' );
357 - remove_all_actions( 'all_admin_notices' );
358 - }
359 429 }
360 430 }