I have added new mime types with the ‘post_mime_types’ filter eg. PDF, doc, mp3 etc…

Filtering by custom mime type on the upload.php page in media grid view works as expected but in list view it doesn’t.

The problem is that WordPress passes the mime types through urlencode as it builds the html (wp-admin/includes/class-wp-media-list-table.php:73) and so

post_mime_type:application/pdf 

becomes

post_mime_type:application%2Fpdf

for the drop down value.

When the filter form is submitted the encoded “https://wordpress.stackexchange.com/” is ignored and doesn’t filter properly.

Changing the ‘%2F’ back to a “https://wordpress.stackexchange.com/” with JS would work but I’d like to know if anyone has a solution to decode the string before its processed and the page reloaded.

1 Answer
1

Here’s a workaround you can put in a plugin or your theme’s functions.php file. So far no problems.

/*
* Workaround Bug 30123
* Affects WP 4.0+, should be fixed in WP 4.1
* https://core.trac.wordpress.org/ticket/30123
*/
function bugfix30123__action__admin_init() {
    if ( isset( $_GET['attachment-filter'] ) && is_string( $_GET['attachment-filter'] ) ) {
        $_GET['attachment-filter'] = $_REQUEST['attachment-filter'] = str_replace( '%2F', "https://wordpress.stackexchange.com/", $_GET['attachment-filter'] );
    }
}
add_action( 'admin_init', 'bugfix30123__action__admin_init' );

Leave a Reply

Your email address will not be published. Required fields are marked *