[wp-trac] [WordPress Trac] #31570: Infinite loop when filtering Media Library images by size in a modal (using wp_prepare_attachment_for_js)
WordPress Trac
noreply at wordpress.org
Mon Mar 9 13:48:26 UTC 2015
#31570: Infinite loop when filtering Media Library images by size in a modal (using
wp_prepare_attachment_for_js)
----------------------------------------+-----------------------------
Reporter: silb3r | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.1.1
Severity: normal | Keywords:
Focuses: javascript, administration |
----------------------------------------+-----------------------------
In an attempt to restrict a post's Featured Image dimensions to imagers
wider than 100px I implement the following code in `functions.php`:
{{{
function restrict_media_library_by_width($response, $attachment, $meta) {
if(isset($response['width']) && isset($response['height']) &&
$response['width'] > 100) {
return $response;
}
return false;
}
add_filter('wp_prepare_attachment_for_js',
'restrict_media_library_by_width', 10, 3);
}}}
I then click "Set featured image" and the Media Library modal that appears
only loads one empty thumbnail and my Network panel in Chrome Dev Tools
reveals it makes continued, repeated, infinite AJAX requests.
The only viable alternative I've found was to run a separate query within
`ajax_query_attachments_args`, which is needed because the
`_wp_attachment_metadata` key contains serialized data and that leaves no
way to compare dimensions within a `meta_query`.
Obviously running this additional query is inefficient and more resource
intensive than it should be. More details here:
http://wordpress.stackexchange.com/questions/180500/filter-media-library-
items-by-size/.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31570>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list