| @@ -38,15 +38,47 @@ | ||
| 38 | 38 | add_filter( 'template_include', [ $this, 'builder_template' ], 99 ); |
| 39 | 39 | add_filter( 'template_redirect', [ $this, 'restrict_preview_access' ], 99 ); |
| 40 | 40 | |
| 41 | 41 | add_filter( 'parse_query', [ $this, 'query_filter' ] ); |
| 42 | - // add filter for search. | |
| 42 | + // Add filter for search. | |
| 43 | 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 | + } | |
| 44 | 47 | |
| 45 | - add_action( 'in_admin_header', [ $this, 'remove_all_notices' ], 1000 ); | |
| 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 ); | |
| 46 | 79 | } |
| 47 | 80 | |
| 48 | - | |
| 49 | 81 | /** |
| 50 | 82 | * Public function add_filter. |
| 51 | 83 | * Added search filter for type of template |
| 52 | 84 | * |
| @@ -131,9 +163,9 @@ | ||
| 131 | 163 | 'feeds' => false, |
| 132 | 164 | ], |
| 133 | 165 | 'query_var' => true, |
| 134 | 166 | 'publicly_queryable' => true, |
| 135 | - 'capability_type' => 'product', | |
| 167 | + // 'capability_type' => 'product', Will Remove this line in the future. | |
| 136 | 168 | 'show_in_rest' => true, |
| 137 | 169 | 'rest_base' => BuilderFns::$post_type_tb, |
| 138 | 170 | ]; |
| 139 | 171 | |
| @@ -187,9 +219,9 @@ | ||
| 187 | 219 | * @param string $post_id Post id. |
| 188 | 220 | * |
| 189 | 221 | * @return void |
| 190 | 222 | */ |
| 191 | - public function custom_columns( $column, $post_id ) { | |
| 223 | + public function custom_columns( $column, $post_id ) { // phpcs:ignore Generic.Metrics.NestingLevel.TooHigh | |
| 192 | 224 | $post_id = absint( $post_id ); |
| 193 | 225 | $types = BuilderFns::builder_page_types(); |
| 194 | 226 | $template_type = BuilderFns::builder_type( $post_id ) ? BuilderFns::builder_type( $post_id ) : array_key_first( $types ); |
| 195 | 227 | |
| @@ -214,8 +246,11 @@ | ||
| 214 | 246 | $set_default = BuilderFns::get_specific_product_as_default( $post_id ); |
| 215 | 247 | if ( $set_default ) { |
| 216 | 248 | $is_set_default = $post_id; |
| 217 | 249 | } |
| 250 | + if ( ! $set_default && $is_set_default === $post_id ) { | |
| 251 | + $is_set_default = ''; | |
| 252 | + } | |
| 218 | 253 | break; |
| 219 | 254 | case 'product_cats': |
| 220 | 255 | $page_type_for = 'product-page-template-' . $post_id . '-specific-category'; |
| 221 | 256 | $set_default_option_name = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id ); |
| @@ -240,9 +275,16 @@ | ||
| 240 | 275 | $set_default = BuilderFns::get_specific_category_as_default( $post_id ); |
| 241 | 276 | if ( ! empty( $categories_name ) && $set_default ) { |
| 242 | 277 | $is_set_default = $post_id; |
| 243 | 278 | $page_type_for = 'template-' . $post_id . '-specific-category'; |
| 279 | + } else { | |
| 280 | + $option_name = BuilderFns::option_name( $template_type ); | |
| 281 | + $is_set_default = TemplateSettings::instance()->get_option( $option_name ); | |
| 282 | + $set_default = $is_set_default; | |
| 244 | 283 | } |
| 284 | + if ( ! $set_default && $is_set_default === $post_id ) { | |
| 285 | + $is_set_default = ''; | |
| 286 | + } | |
| 245 | 287 | } |
| 246 | 288 | ?> |
| 247 | 289 | <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' ); ?>"> |
| 248 | 290 | <label class="rtsb-switch"> |
| @@ -331,9 +373,9 @@ | ||
| 331 | 373 | * @return string |
| 332 | 374 | */ |
| 333 | 375 | public function builder_template( $template ) { |
| 334 | 376 | $builder_page_id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_page(); |
| 335 | - if ( $builder_page_id ) { | |
| 377 | + if ( defined( 'ELEMENTOR_VERSION' ) && $builder_page_id ) { // Elementor Check. | |
| 336 | 378 | $page_template = get_post_meta( $builder_page_id, '_wp_page_template', true ); |
| 337 | 379 | $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php'; |
| 338 | 380 | if ( 'elementor_canvas' === $page_template ) { |
| 339 | 381 | $new_template = RTSB_ABSPATH . 'page-templates/elementor-canvas.php'; |
| @@ -379,9 +421,8 @@ | ||
| 379 | 421 | * @return array An updated array of row action links. |
| 380 | 422 | */ |
| 381 | 423 | public function filter_post_row_actions( $actions ) { |
| 382 | 424 | if ( $this->is_current_screen() ) { |
| 383 | - // unset( $actions['view'] ); | |
| 384 | 425 | unset( $actions['inline hide-if-no-js'] ); |
| 385 | 426 | |
| 386 | 427 | if ( isset( $actions['view'] ) ) { |
| 387 | 428 | $actions['view'] = str_replace( __( 'View', 'shopbuilder' ), __( 'Preview', 'shopbuilder' ), $actions['view'] ); |
| @@ -388,17 +429,6 @@ | ||
| 388 | 429 | } |
| 389 | 430 | } |
| 390 | 431 | |
| 391 | 432 | return $actions; |
| 392 | - } | |
| 393 | - | |
| 394 | - /** | |
| 395 | - * Remove admin notices | |
| 396 | - */ | |
| 397 | - public function remove_all_notices() { | |
| 398 | - $screen = get_current_screen(); | |
| 399 | - if ( 'edit-rtsb_builder' === $screen->id ) { | |
| 400 | - remove_all_actions( 'admin_notices' ); | |
| 401 | - remove_all_actions( 'all_admin_notices' ); | |
| 402 | - } | |
| 403 | 433 | } |
| 404 | 434 | } |