-
Notifications
You must be signed in to change notification settings - Fork 178
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
Media: Improve plugin compatibility of taxonomy query #13208
Media: Improve plugin compatibility of taxonomy query #13208
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@chirag2208 Could you please sign the Contributor License Agreement (CLA) over at https://cla.developers.google.com/? We can't accept your contribution otherwise. |
I have signed CLA |
Thanks a lot! So I had a quick look and it indeed looks like the tax query nesting is not really correct. The It would be more accurate to do something like this: /**
* Merge with existing tax query if needed,
* in a nested way so WordPress will run them
* with an 'AND' relation. Example:
*
* [
* 'relation' => 'AND', // implicit.
* [ this query ],
* [ [ any ], [ existing ], [ tax queries] ]
* ]
*/
$new_tax_query = [
'relation' => 'AND',
[
'taxonomy' => $this->taxonomy_slug,
'field' => 'slug',
'terms' => [
self::TERM_POSTER_GENERATION,
self::TERM_SOURCE_VIDEO,
self::TERM_SOURCE_IMAGE,
self::TERM_PAGE_TEMPLATE,
],
'operator' => 'NOT IN',
],
];
if ( ! empty( $tax_query ) ) {
$new_tax_query[] = [ $tax_query ];
}
return $new_tax_query; Second, to make this work more accurately, we should increase the filter priorities so that it truly runs after all existing tax queries: // Hide video posters from Media grid view.
add_filter( 'ajax_query_attachments_args', [ $this, 'filter_ajax_query_attachments_args' ], PHP_INT_MAX );
// Hide video posters from Media list view.
add_action( 'pre_get_posts', [ $this, 'filter_generated_media_attachments' ], PHP_INT_MAX );
// Hide video posters from web-stories/v1/media REST API requests.
add_filter( 'web_stories_rest_attachment_query', [ $this, 'filter_rest_generated_media_attachments' ], PHP_INT_MAX ); cc @ayushnirwal |
Hi @swissspidy This is great. What is the next step now in order for this fix to go live? |
This still needs testing and tests to verify this fixes bugs and doesn‘t cause regressions. |
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.
@swissspidy LGTM ✅
Tested the PR in every possible way to make sure it doesn't have any conflicts.
Context
We are using folders plugin to structure media files in folders, web stories plugin creates invalid SQL query which does not provide any results
Summary
When eb Stories plugin is active and there is no any
$tax_query
inWP_Query
object it adds0 = 1
in SQL query which is always wrong so not returning any results inWP_Query
, Please check this video for more details: https://tinyurl.com/2anx49r9Relevant Technical Choices
We have fixed issue in this file:
/wp-content/plugins/web-stories/includes/Media/Media_Source_Taxonomy.php
added this code after line number: 382To-do
Any filter functionality on WP media page
User-facing changes
Before: https://tinyurl.com/25j68dyu
After: https://tinyurl.com/23c7k7kd
Testing Instructions
Install Folders plugin from wordpress.org (https://wordpress.org/plugins/folders/)
After Installing folders on your wordpress website, go to media and create folders and assign some media items to that folders (check this video for how to create folders and assign media items to it) - https://tinyurl.com/2anx49r9 then click on any Folders it is not showing any results
This PR can be tested by following these steps:
Reviews
Does this PR have a security-related impact?
No
Does this PR change what data or activity we track or use?
No
Does this PR have a legal-related impact?
No
Checklist
Type: XYZ
label to the PR