From d13c6484c8dd025b6fd94de4963285e42aade0ed Mon Sep 17 00:00:00 2001 From: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:32:23 +0200 Subject: [PATCH] Filters are incorrectly applied in the __experimental/menu-items controller (#34857) * We don't need to apply these filters (title_save_pre, exceprt_save_pre, content_save_pre) as they get applied later inside the wp_insert_post function. * Implement a regression test to check that we don't call fiilter callbacks more than once. * Revert accidental change. * Implement a regression test to check that we don't call fiilter callbacks more than once when updating a menu item. * Refactor the method name. * Fix code style. * Remove the unit tests as suggested here: https://github.com/WordPress/gutenberg/pull/34857#issuecomment-923821994 --- lib/class-wp-rest-menu-items-controller.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/class-wp-rest-menu-items-controller.php b/lib/class-wp-rest-menu-items-controller.php index 84f0c48d42d49..aeae2bb8706d9 100644 --- a/lib/class-wp-rest-menu-items-controller.php +++ b/lib/class-wp-rest-menu-items-controller.php @@ -543,17 +543,6 @@ protected function prepare_item_for_database( $request ) { $prepared_nav_item[ $key ] = implode( ' ', array_map( 'sanitize_html_class', $value ) ); } - // Apply the same filters as when calling wp_insert_post(). - - /** This filter is documented in wp-includes/post.php */ - $prepared_nav_item['menu-item-title'] = wp_unslash( apply_filters( 'title_save_pre', wp_slash( $prepared_nav_item['menu-item-title'] ) ) ); - - /** This filter is documented in wp-includes/post.php */ - $prepared_nav_item['menu-item-attr-title'] = wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $prepared_nav_item['menu-item-attr-title'] ) ) ); - - /** This filter is documented in wp-includes/post.php */ - $prepared_nav_item['menu-item-description'] = wp_unslash( apply_filters( 'content_save_pre', wp_slash( $prepared_nav_item['menu-item-description'] ) ) ); - // Valid url. if ( '' !== $prepared_nav_item['menu-item-url'] ) { $prepared_nav_item['menu-item-url'] = esc_url_raw( $prepared_nav_item['menu-item-url'] );