[wp-trac] [WordPress Trac] #30520: Adding mime-type-filter failed at Media

WordPress Trac noreply at wordpress.org
Thu Nov 27 02:46:39 UTC 2014


#30520: Adding mime-type-filter failed at Media
----------------------------+-----------------------------
 Reporter:  hogetan         |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 Hello.

 I posted this article at support forum but no reply.
 https://wordpress.org/support/topic/adding-mime-type-filter-failed-at-
 media?replies=1

 {{{
 add_filter('post_mime_types', 'my_post_mime_types' );
 function my_post_mime_types($post_mime_types) {
     $post_mime_types['application/zip'] = array(__('ZIP'), __('Manage
 ZIP'), _n_noop('ZIP <span class="count">(%s)</span>', 'ZIP <span
 class="count">(%s)</span>'));
     $post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage
 PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span
 class="count">(%s)</span>' ) );
     return $post_mime_types;
 }
 }}}

 (This code is from someone's code. I get this code by google)
 This code can filter out at Media only grid mode.
 Media has 2 views, list and grid. I expect this code can work out both
 mode.

 The reason why this code fails at list mode is list mode sends filtering
 data with html escaping.

 At list view, GET query has double escaped slash, then it failed.
 "/wp-admin/upload.php?mode=list&attachment-
 filter=post_mime_type%3Aapplication%252Fzip"

 "%25" means "%"
 At HTML, "application/zip" was encoded to "application%2Fzip"
 Then sending this query, it will be
 "post_mime_type%3Aapplication%252Fzip""

 At grid view, POST query string has correct slash
 "query[post_mime_type]:application/zip"

 I added a patch to prevent this double escaping.

 {{{
 --- includes/class-wp-media-list-table.php      2014-11-21
 14:04:40.000000000 +0900
 +++ ../wp-admin_/includes/class-wp-media-list-table.php 2014-11-21
 13:36:18.000000000 +0900
 @@ -70,7 +70,7 @@
                         if ( !empty( $_GET['attachment-filter'] ) &&
 strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 &&
 wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET
 ['attachment-filter'] ) ) )
                                 $selected = ' selected="selected"';
                         if ( !empty( $num_posts[$mime_type] ) )
 -                               $type_links[$mime_type] = '<option
 value="post_mime_type:' . $mime_type. '"' . $selected . '>' . sprintf(
 translate_nooped_plural( $label[2], $num_posts[$mime_type] ),
 number_format_i18n( $num_posts[$mime_type] )) . '</option>';
 +                               $type_links[$mime_type] = '<option
 value="post_mime_type:' . urlencode( $mime_type ) . '"' . $selected . '>'
 . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ),
 number_format_i18n( $num_posts[$mime_type] )) . '</option>';
                 }
                 $type_links['detached'] = '<option value="detached"' . (
 $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx(
 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ),
 number_format_i18n( $total_orphans ) ) . '</option>';
 }}}

 I guess this should be fixed at core file.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30520>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list