-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
Have you validated we don't need these filters? I also, think, we do not need to add a unit test here. These menu endpoints are still in development and not stable yet, so removing filters doesn't need a unit test. |
// 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'] ) ) ); | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
Yes, I've validated that. Please see
We don't want to apply the same filters twice, and my unit test ensures that it will not happen again. It's a regression unit test. |
I was the one who originally added the filter and wrote this whole endpoint. I am happy to remove them. But the unit test is pointless and should be removed. The only way that the filter would be double applied, if someone adds it. Remove the tests, I will approve the PR. |
Code changes look good to me, thanks for the fix @anton-vlasenko! I agree the unit tests here aren't strictly necessary, but I don't think there is much of a cost to having them. I'll leave the final decision up to @spacedmonkey as he's been the main driver of this endpoint. |
Can you remove the tests for now @anton-vlasenko. I have created a breakout issue, #34992 for improving test coverage for these endpoints. If it makes sense, we can add these tests back in that ticket. Agreed? |
…e, content_save_pre) as they get applied later inside the wp_insert_post function.
…acks more than once.
…acks more than once when updating a menu item.
f30f0eb
to
5b6c2d2
Compare
Let me disagree with that. It's a valid regression unit test and it's not pointless.
Yes, and it can happen again.
Yes, I will remove it, but I haven't heard clear arguments against it. |
Description
This PR fixes an issue with the filters in the
WP_REST_Menu_Items_Controller::prepare_item_for_database
method.We explicitly apply
title_save_pre
,exceprt_save_pre
,content_save_pre
filters in there.But later, we apply the same filters in the
wp_insert_post
function, so we don't need to apply them in theWP_REST_Menu_Items_Controller::prepare_item_for_database
method.Fixes #25095
How has this been tested?
Two regression unit tests have been written to cover this case. So I would say no testing is needed.
However, If you still want/need to test this, you can do it as described below.
Prerequisite: you will need XDebug to test it.
Navigation screen
feature./wp-includes/plugin.php
file in your IDE and place a conditional breakpoint at the beginning of theapply_filters
function (somewhere around line 166).apply_filters
function gets called only once (with $hook_name === 'content_save_pre').Screenshots
No screenshots are needed for this issue.
Types of changes
Bug fix.
Checklist:
*.native.js
files for terms that need renaming or removal).