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

Fix bug with Wordpress 5.8 - media library grid mode infinite loading was replaced by button load #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions wp-media-categories/includes/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,40 @@ function wp_media_categories_ajax_update_attachment_taxonomies() {

wp_send_json_success( $attachment );
}

function wp_media_categories_ajax_filter_query( $query ) {

// Get names of media taxonomies
$taxonomies = get_object_taxonomies( 'attachment', 'names' );

$query[ 'tax_query' ] = array( 'relation' => 'AND' );

foreach ( $taxonomies as $taxonomy ) {
if ( isset( $query[ $taxonomy ] ) ) {

// Filter a specific category
if ( is_numeric( $query[ $taxonomy ] ) ) {
array_push( $query[ 'tax_query' ], array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $query[ $taxonomy ]
) );
}

// Filter No category
if ( $query[ $taxonomy ] == 'no_category' ) {
$all_terms_ids = wp_media_categories_get_terms_values( 'ids' );
array_push( $query[ 'tax_query' ], array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $all_terms_ids,
'operator' => 'NOT IN',
) );
}
}

unset( $query[ $taxonomy ] );
}

return $query;
}
5 changes: 4 additions & 1 deletion wp-media-categories/includes/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
add_filter( 'attachment_fields_to_edit', 'wp_media_attachment_fields', 10, 2 );

// filter the attachments from user dropdown
add_action( 'wp_ajax_query-attachments', 'wp_media_categories_ajax_query_attachments', 0 );
//add_action( 'wp_ajax_query-attachments', 'wp_media_categories_ajax_query_attachments', 0 );

// filter the attachments from user dropdown by only filter query
add_filter( 'ajax_query_attachments_args', 'wp_media_categories_ajax_filter_query' );

// update the categories
add_action( 'wp_ajax_save-attachment-compat', 'wp_media_categories_ajax_update_attachment_taxonomies', 0 );
Expand Down