Make WordPress Core


Ignore:
Timestamp:
06/11/2024 02:12:52 AM (13 months ago)
Author:
peterwilsoncc
Message:

Administration: Prevent an orderby array throwing a notice.

Prevent WP_List_Table::search_box() from throwing an array to string conversion notice when post list tables are loaded with an array of orderby parameters in the URL, eg: /wp-admin/edit.php?post_type=page&orderby[menu_order]=ASC&orderby[title]=ASC.

Follow up to [29027].

Props leonidasmilossis, rajinsharwar, swissspidy, NomNom99, pls78, SergeyBiryukov.
Fixes #59494.
See #17065.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r58374 r58379  
    389389
    390390        if ( ! empty( $_REQUEST['orderby'] ) ) {
    391             echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
     391            if ( is_array( $_REQUEST['orderby'] ) ) {
     392                foreach ( $_REQUEST['orderby'] as $key => $value ) {
     393                    /*
     394                     * Orderby can be either an associative array or non-associative array.
     395                     * In the latter case, this makes sure the key is a string before calling esc_attr().
     396                     */
     397                    $key = (string) $key;
     398                    echo '<input type="hidden" name="orderby[' . esc_attr( $key ) . ']" value="' . esc_attr( $value ) . '" />';
     399                }
     400            } else {
     401                echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
     402            }
    392403        }
    393404        if ( ! empty( $_REQUEST['order'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.