| @@ -38,15 +38,48 @@ | ||
| 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 | + * @param bool $update Whether this is an existing post being updated. | |
| 59 | + * | |
| 60 | + * @return void | |
| 61 | + */ | |
| 62 | + public function on_save_post( $post_ID, $post ) { | |
| 63 | + // Only proceed on update and specific post type. | |
| 64 | + if ( BuilderFns::$post_type_tb !== $post->post_type ) { | |
| 65 | + return; | |
| 66 | + } | |
| 67 | + if ( 'elementor' !== Fns::page_edit_with( $post_ID ) ) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + global $wpdb; | |
| 71 | + // Directly update the post_content to empty. | |
| 72 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 73 | + $wpdb->update( | |
| 74 | + $wpdb->posts, | |
| 75 | + [ 'post_content' => '' ], | |
| 76 | + [ 'ID' => $post_ID ] | |
| 77 | + ); | |
| 78 | + // Clear cache so changes reflect properly. | |
| 79 | + clean_post_cache( $post_ID ); | |
| 46 | 80 | } |
| 47 | 81 | |
| 48 | - | |
| 49 | 82 | /** |
| 50 | 83 | * Public function add_filter. |
| 51 | 84 | * Added search filter for type of template |
| 52 | 85 | * |
| @@ -131,9 +164,9 @@ | ||
| 131 | 164 | 'feeds' => false, |
| 132 | 165 | ], |
| 133 | 166 | 'query_var' => true, |
| 134 | 167 | 'publicly_queryable' => true, |
| 135 | - 'capability_type' => 'product', | |
| 168 | + // 'capability_type' => 'product', Will Remove this line in the future. | |
| 136 | 169 | 'show_in_rest' => true, |
| 137 | 170 | 'rest_base' => BuilderFns::$post_type_tb, |
| 138 | 171 | ]; |
| 139 | 172 | |
| @@ -331,9 +364,9 @@ | ||
| 331 | 364 | * @return string |
| 332 | 365 | */ |
| 333 | 366 | public function builder_template( $template ) { |
| 334 | 367 | $builder_page_id = BuilderFns::is_builder_preview() ? get_the_ID() : BuilderFns::builder_page_id_by_page(); |
| 335 | - if ( $builder_page_id ) { | |
| 368 | + if ( defined( 'ELEMENTOR_VERSION' ) && $builder_page_id ) { // Elementor Check. | |
| 336 | 369 | $page_template = get_post_meta( $builder_page_id, '_wp_page_template', true ); |
| 337 | 370 | $new_template = RTSB_ABSPATH . 'page-templates/builder-template.php'; |
| 338 | 371 | if ( 'elementor_canvas' === $page_template ) { |
| 339 | 372 | $new_template = RTSB_ABSPATH . 'page-templates/elementor-canvas.php'; |
| @@ -388,17 +421,6 @@ | ||
| 388 | 421 | } |
| 389 | 422 | } |
| 390 | 423 | |
| 391 | 424 | 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 | 425 | } |
| 404 | 426 | } |