Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters are incorrectly applied in the __experimental/menu-items controller #34857

Merged
merged 7 commits into from
Sep 21, 2021
11 changes: 0 additions & 11 deletions lib/class-wp-rest-menu-items-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) );

Comment on lines -546 to -556
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from here.

Do you know why they are there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why they are there?

I guess they are there to call apply_filters function before saving values to the database.
But that is not needed in lib/class-wp-rest-menu-items-controller.php file because we apply those filters later (yes, I've checked that, please see How has this been tested? section).

// Valid url.
if ( '' !== $prepared_nav_item['menu-item-url'] ) {
$prepared_nav_item['menu-item-url'] = esc_url_raw( $prepared_nav_item['menu-item-url'] );
Expand Down