[wp-trac] [WordPress Trac] #39406: Make callback_args filterable in WP_Terms_List_Table

WordPress Trac noreply at wordpress.org
Tue Dec 27 15:25:24 UTC 2016


#39406: Make callback_args filterable in WP_Terms_List_Table
-------------------------+-----------------------------
 Reporter:  tifosi       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Taxonomy     |    Version:  4.7
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The callback_args variable is specific to the WP_Terms_List_Table class.
 It defines a set of core variables that are passed to the get_terms
 function, and thereby to the generated WP_Term_Query instance.

 They can't be modified so restricting the default terms displayed to the
 paginated display of all terms for that post-type / taxonomy association.

 The reason for this enhancement request is to easily allow the development
 of drill-down filtering for custom columns, which are added via the
 filters:

 {{{
 add_action( 'manage_edit-{$taxonomy}_columns', 'add_column' );
 add_action( 'manage_{$taxonomy}_custom_column', 'add_column_content, 10, 3
 );

 // Add the meta data column sortable
 add_filter( 'manage_edit-{$taxonomy}_sortable_columns',
 'add_column_sortable' ] );
 }}}

 It is possible to do this at a lower level in get_terms - from 4.6 at
 least - using the 'pre_get_terms action' and injecting / over-riding the
 WP_Meta_Query query_vars['meta_query'] value e.g. with:

 {{{
 add_action( 'pre_get_terms', 'get_terms_meta' );
 function get_terms_meta($query) {
     // store current query vars
     $query_vars = $query->query_vars;
     $args = [];

     $args['meta_query'] = [
        [
         'key'       => 'meta_key',
         'value'     => 'meta_value',
         'compare'   => 'LIKE'
        ]
     ];

    if ( !empty( $args ) ) {
       $query->query_vars = array_merge( $query_vars, $args );
    }
 }
 }}}

 That requires a deep understanding of core funtions - as well as some core
 digging! It would be much more flexible if there was an entry point filter
 that could be used to modify the get_terms args to manipulate by custom
 field, e.g.

 {{{
 add_filter( 'manage_edit-{$taxonomy}_column_filter', 'column_filter' );

 function column_filter( $args ) {

 // conditions met e.g. $_GET['meta_key']
 $args['meta_query'] = [
     [
         'key'       => 'meta_key',
         'value'     => 'meta_value',
         'compare'   => 'LIKE'
     ]
 ];

 return $args;

 }}}


 The column field value could be modified to add the query arg for the
 meta_key via the column filter detailed earlier.

 I've hacked it in a test version of the class and it's pretty functional.

 {{{
 $args = array(
     'search' => $search,
     'page' => $this->get_pagenum(),
     'number' => $tags_per_page,
 );
 }}}

 to

 {{{
 $args = array(
     'search' => $search,
     'page' => $this->get_pagenum(),
     'number' => $tags_per_page,
 );
 $args = apply_filters( 'manage_edit-' . $this->screen->taxonomy
 .'_column_filter, $args );
 }}}

 Thanks

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


More information about the wp-trac mailing list