Make WordPress Core

Ticket #61899: 61899.diff

File 61899.diff, 2.5 KB (added by xipasduarte, 19 months ago)

Add search_box_custom_args filter

  • src/wp-admin/includes/class-wp-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php
    index 253bcca800b2..3f361e491297 100644
    a b public function search_box( $text, $input_id ) { 
    387387
    388388                $input_id = $input_id . '-search-input';
    389389
    390                 if ( ! empty( $_REQUEST['orderby'] ) ) {
    391                         if ( is_array( $_REQUEST['orderby'] ) ) {
    392                                 foreach ( $_REQUEST['orderby'] as $key => $value ) {
    393                                         echo '<input type="hidden" name="orderby[' . esc_attr( $key ) . ']" value="' . esc_attr( $value ) . '" />';
     390                $builtin_hidden_fields = array(
     391                        'orderby',
     392                        'order',
     393                        'post_mime_type',
     394                        'detached',
     395                );
     396
     397                /**
     398                 * Filters the list of hidden custom query variables.
     399                 * This filter should be used to add custom query variables that are hidden from the search query.
     400                 *
     401                 * @since unreleased
     402                 *
     403                 * @param string[] $custom_hidden_fields An array of hidden custom query variables.
     404                 * @param string   $class_name The class name of the current list table.
     405                 */
     406                $custom_hidden_fields = apply_filters( 'search_box_custom_args', [], get_class( $this ) );
     407
     408                $hidden_fields = array_merge(
     409                        $builtin_hidden_fields,
     410                        array_filter( $custom_hidden_fields, function ( $query_arg ) {
     411                                return is_string( $query_arg );
     412                        } )
     413                );
     414
     415                foreach ( $hidden_fields as $name ) {
     416                        if ( ! empty( $_REQUEST[ $name ] ) ) {
     417                                if ( is_array( $_REQUEST[ $name ] ) ) {
     418                                        foreach ( $_REQUEST[ $name ] as $key => $value ) {
     419                                                echo '<input type="hidden" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']" value="' . esc_attr( $value ) . '" />';
     420                                        }
     421                                } else {
     422                                        echo '<input type="hidden" name="' . esc_attr( $name ) . '" value="' . esc_attr( $_REQUEST[ $name ] ) . '" />';
    394423                                }
    395                         } else {
    396                                 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
    397424                        }
    398425                }
    399                 if ( ! empty( $_REQUEST['order'] ) ) {
    400                         echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
    401                 }
    402                 if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
    403                         echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
    404                 }
    405                 if ( ! empty( $_REQUEST['detached'] ) ) {
    406                         echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
    407                 }
    408426                ?>
    409427<p class="search-box">
    410428        <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>