Make WordPress Core

Ticket #63168: search_term_global.diff

File search_term_global.diff, 14.9 KB (added by westonruter, 6 months ago)
  • src/wp-admin/includes/ajax-actions.php

    diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
    index 1df84f204e..259e14d5db 100644
    a b function wp_ajax_search_plugins() { 
    48294829                network_admin_url( 'plugins.php', 'relative' )
    48304830        );
    48314831
    4832         $GLOBALS['s'] = wp_unslash( $_POST['s'] );
     4832        $GLOBALS['search_term'] = wp_unslash( $_POST['s'] );
    48334833
    48344834        $wp_list_table->prepare_items();
    48354835
  • src/wp-admin/includes/class-wp-links-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-links-list-table.php b/src/wp-admin/includes/class-wp-links-list-table.php
    index b038f79a76..d60f4dddef 100644
    a b class WP_Links_List_Table extends WP_List_Table { 
    4848         * @global string $order
    4949         */
    5050        public function prepare_items() {
    51                 global $cat_id, $s, $orderby, $order;
     51                global $cat_id, $search_term, $orderby, $order;
    5252
    53                 $cat_id  = ! empty( $_REQUEST['cat_id'] ) ? absint( $_REQUEST['cat_id'] ) : 0;
    54                 $orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
    55                 $order   = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
    56                 $s      = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
     53                $cat_id      = ! empty( $_REQUEST['cat_id'] ) ? absint( $_REQUEST['cat_id'] ) : 0;
     54                $orderby     = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
     55                $order       = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
     56                $search_term = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
    5757
    5858                $args = array(
    5959                        'hide_invisible' => 0,
    class WP_Links_List_Table extends WP_List_Table { 
    6363                if ( 'all' !== $cat_id ) {
    6464                        $args['category'] = $cat_id;
    6565                }
    66                 if ( ! empty( $s ) ) {
    67                         $args['search'] = $s;
     66                if ( ! empty( $search_term ) ) {
     67                        $args['search'] = $search_term;
    6868                }
    6969                if ( ! empty( $orderby ) ) {
    7070                        $args['orderby'] = $orderby;
  • src/wp-admin/includes/class-wp-ms-sites-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-ms-sites-list-table.php b/src/wp-admin/includes/class-wp-ms-sites-list-table.php
    index 6097f5e13e..48962e2ee3 100644
    a b class WP_MS_Sites_List_Table extends WP_List_Table { 
    6666         * @global wpdb   $wpdb WordPress database abstraction object.
    6767         */
    6868        public function prepare_items() {
    69                 global $mode, $s, $wpdb;
     69                global $mode, $search_term, $wpdb;
    7070
    7171                if ( ! empty( $_REQUEST['mode'] ) ) {
    7272                        $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    7979
    8080                $pagenum = $this->get_pagenum();
    8181
    82                 $s    = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    83                 $wild = '';
    84                 if ( str_contains( $s, '*' ) ) {
    85                         $wild = '*';
    86                         $s    = trim( $s, '*' );
     82                $search_term = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
     83                $wild        = '';
     84                if ( str_contains( $search_term, '*' ) ) {
     85                        $wild        = '*';
     86                        $search_term = trim( $search_term, '*' );
    8787                }
    8888
    8989                /*
    9090                 * If the network is large and a search is not being performed, show only
    9191                 * the latest sites with no paging in order to avoid expensive count queries.
    9292                 */
    93                 if ( ! $s && wp_is_large_network() ) {
     93                if ( ! $search_term && wp_is_large_network() ) {
    9494                        if ( ! isset( $_REQUEST['orderby'] ) ) {
    9595                                $_GET['orderby']     = '';
    9696                                $_REQUEST['orderby'] = '';
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    107107                        'network_id' => get_current_network_id(),
    108108                );
    109109
    110                 if ( empty( $s ) ) {
     110                if ( empty( $search_term ) ) {
    111111                        // Nothing to do.
    112                 } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s )
    113                         || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
    114                         || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
    115                         || preg_match( '/^[0-9]{1,3}\.$/', $s )
     112                } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $search_term )
     113                        || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $search_term )
     114                        || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $search_term )
     115                        || preg_match( '/^[0-9]{1,3}\.$/', $search_term )
    116116                ) {
    117117                        // IPv4 address.
    118118                        $reg_blog_ids = $wpdb->get_col(
    119119                                $wpdb->prepare(
    120120                                        "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s",
    121                                         $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' )
     121                                        $wpdb->esc_like( $search_term ) . ( ! empty( $wild ) ? '%' : '' )
    122122                                )
    123123                        );
    124124
    125125                        if ( $reg_blog_ids ) {
    126126                                $args['site__in'] = $reg_blog_ids;
    127127                        }
    128                 } elseif ( is_numeric( $s ) && empty( $wild ) ) {
    129                         $args['ID'] = $s;
     128                } elseif ( is_numeric( $search_term ) && empty( $wild ) ) {
     129                        $args['ID'] = $search_term;
    130130                } else {
    131                         $args['search'] = $s;
     131                        $args['search'] = $search_term;
    132132
    133133                        if ( ! is_subdomain_install() ) {
    134134                                $args['search_columns'] = array( 'path' );
  • src/wp-admin/includes/class-wp-ms-themes-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php
    index 70187f44d4..a3fb02e960 100644
    a b class WP_MS_Themes_List_Table extends WP_List_Table { 
    9797         * @global string $s
    9898         */
    9999        public function prepare_items() {
    100                 global $status, $totals, $page, $orderby, $order, $s;
     100                global $status, $totals, $page, $orderby, $order, $search_term;
    101101
    102                 $orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
    103                 $order   = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
    104                 $s      = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
     102                $orderby     = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
     103                $order       = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
     104                $search_term = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
    105105
    106106                $themes = array(
    107107                        /**
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    202202                        }
    203203                }
    204204
    205                 if ( $s ) {
     205                if ( $search_term ) {
    206206                        $status           = 'search';
    207207                        $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
    208208                }
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    545545         * @param WP_Theme $theme The current WP_Theme object.
    546546         */
    547547        public function column_name( $theme ) {
    548                 global $status, $page, $s;
     548                global $status, $page, $search_term;
    549549
    550550                $context = $status;
    551551
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    574574                                                'action' => 'enable',
    575575                                                'theme'  => $theme_key,
    576576                                                'paged'  => $page,
    577                                                 's'      => $s,
     577                                                's'      => $search_term,
    578578                                        ),
    579579                                        $url
    580580                                );
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    600600                                        'action' => 'disable',
    601601                                        'theme'  => $theme_key,
    602602                                        'paged'  => $page,
    603                                         's'      => $s,
     603                                        's'      => $search_term,
    604604                                ),
    605605                                $url
    606606                        );
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    632632                                        'checked[]'    => $theme_key,
    633633                                        'theme_status' => $context,
    634634                                        'paged'        => $page,
    635                                         's'            => $s,
     635                                        's'            => $search_term,
    636636                                ),
    637637                                'themes.php'
    638638                        );
  • src/wp-admin/includes/class-wp-plugins-list-table.php

    diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php
    index 897e46cda2..f4286af2e8 100644
    a b class WP_Plugins_List_Table extends WP_List_Table { 
    8888         * @global string $s
    8989         */
    9090        public function prepare_items() {
    91                 global $status, $plugins, $totals, $page, $orderby, $order, $s;
     91                global $status, $plugins, $totals, $page, $orderby, $order, $search_term;
    9292
    9393                $orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
    9494                $order   = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
    class WP_Plugins_List_Table extends WP_List_Table { 
    294294                        }
    295295                }
    296296
    297                 if ( strlen( $s ) ) {
     297                if ( strlen( $search_term ) ) {
    298298                        $status            = 'search';
    299299                        $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
    300300                }
    class WP_Plugins_List_Table extends WP_List_Table { 
    372372         * @return bool
    373373         */
    374374        public function _search_callback( $plugin ) {
    375                 global $s;
     375                global $search_term;
    376376
    377377                foreach ( $plugin as $value ) {
    378                         if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
     378                        if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $search_term ) ) ) {
    379379                                return true;
    380380                        }
    381381                }
    class WP_Plugins_List_Table extends WP_List_Table { 
    721721         * @param array $item
    722722         */
    723723        public function single_row( $item ) {
    724                 global $status, $page, $s, $totals;
     724                global $status, $page, $search_term, $totals;
    725725                static $plugin_id_attrs = array();
    726726
    727727                list( $plugin_file, $plugin_data ) = $item;
    class WP_Plugins_List_Table extends WP_List_Table { 
    817817                                                                '&plugin=' . urlencode( $plugin_file ) .
    818818                                                                '&plugin_status=' . $context .
    819819                                                                '&paged=' . $page .
    820                                                                 '&s=' . $s;
     820                                                                '&s=' . $search_term;
    821821
    822822                                                        $actions['deactivate'] = sprintf(
    823823                                                                '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    842842                                                                        '&amp;plugin=' . urlencode( $plugin_file ) .
    843843                                                                        '&amp;plugin_status=' . $context .
    844844                                                                        '&amp;paged=' . $page .
    845                                                                         '&amp;s=' . $s;
     845                                                                        '&amp;s=' . $search_term;
    846846
    847847                                                                $actions['activate'] = sprintf(
    848848                                                                        '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    872872                                                                '&amp;checked[]=' . urlencode( $plugin_file ) .
    873873                                                                '&amp;plugin_status=' . $context .
    874874                                                                '&amp;paged=' . $page .
    875                                                                 '&amp;s=' . $s;
     875                                                                '&amp;s=' . $search_term;
    876876
    877877                                                        $actions['delete'] = sprintf(
    878878                                                                '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    906906                                                                '&amp;plugin=' . urlencode( $plugin_file ) .
    907907                                                                '&amp;plugin_status=' . $context .
    908908                                                                '&amp;paged=' . $page .
    909                                                                 '&amp;s=' . $s;
     909                                                                '&amp;s=' . $search_term;
    910910
    911911                                                        $actions['deactivate'] = sprintf(
    912912                                                                '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    924924                                                        '&amp;plugin=' . urlencode( $plugin_file ) .
    925925                                                        '&amp;plugin_status=' . $context .
    926926                                                        '&amp;paged=' . $page .
    927                                                         '&amp;s=' . $s;
     927                                                        '&amp;s=' . $search_term;
    928928
    929929                                                $actions['resume'] = sprintf(
    930930                                                        '<a href="%s" id="resume-%s" class="resume-link" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    948948                                                                        '&amp;plugin=' . urlencode( $plugin_file ) .
    949949                                                                        '&amp;plugin_status=' . $context .
    950950                                                                        '&amp;paged=' . $page .
    951                                                                         '&amp;s=' . $s;
     951                                                                        '&amp;s=' . $search_term;
    952952
    953953                                                                $actions['activate'] = sprintf(
    954954                                                                        '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>',
    class WP_Plugins_List_Table extends WP_List_Table { 
    978978                                                                '&amp;checked[]=' . urlencode( $plugin_file ) .
    979979                                                                '&amp;plugin_status=' . $context .
    980980                                                                '&amp;paged=' . $page .
    981                                                                 '&amp;s=' . $s;
     981                                                                '&amp;s=' . $search_term;
    982982
    983983                                                        $actions['delete'] = sprintf(
    984984                                                                '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>',
  • src/wp-admin/network/sites.php

    diff --git a/src/wp-admin/network/sites.php b/src/wp-admin/network/sites.php
    index 17a072287d..208ef37c51 100644
    a b if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 
    411411        printf(
    412412                /* translators: %s: Search query. */
    413413                __( 'Search results for: %s' ),
    414                 '<strong>' . esc_html( $s ) . '</strong>'
     414                '<strong>' . esc_html( $search_term ) . '</strong>'
    415415        );
    416416        echo '</span>';
    417417}
  • src/wp-admin/network/themes.php

    diff --git a/src/wp-admin/network/themes.php b/src/wp-admin/network/themes.php
    index 9794c08f8f..1a5e7180db 100644
    a b $pagenum = $wp_list_table->get_pagenum(); 
    1919
    2020$action = $wp_list_table->current_action();
    2121
    22 $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
     22$search_term = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    2323
    2424// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    2525$temp_args = array(
    if ( $action ) { 
    226226                                        array(
    227227                                                'deleted' => count( $themes ),
    228228                                                'paged'   => $paged,
    229                                                 's'       => $s,
     229                                                's'       => $search_term,
    230230                                        ),
    231231                                        network_admin_url( 'themes.php' )
    232232                                )
    if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 
    372372        printf(
    373373                /* translators: %s: Search query. */
    374374                __( 'Search results for: %s' ),
    375                 '<strong>' . esc_html( $s ) . '</strong>'
     375                '<strong>' . esc_html( $search_term ) . '</strong>'
    376376        );
    377377        echo '</span>';
    378378}
  • tests/phpunit/tests/admin/wpPluginsListTable.php

    diff --git a/tests/phpunit/tests/admin/wpPluginsListTable.php b/tests/phpunit/tests/admin/wpPluginsListTable.php
    index e75a473e2b..aec3ebf536 100644
    a b class Tests_Admin_wpPluginsListTable extends WP_UnitTestCase { 
    4848         * Creates an admin user before any tests run and backs up the `$s` global.
    4949         */
    5050        public static function set_up_before_class() {
    51                 global $s;
     51                global $search_term;
    5252
    5353                parent::set_up_before_class();
    5454
    class Tests_Admin_wpPluginsListTable extends WP_UnitTestCase { 
    6060                                'user_email' => 'testadmin@example.com',
    6161                        )
    6262                );
    63                 self::$original_s = $s;
     63                self::$original_s = $search_term;
    6464        }
    6565
    6666        public function set_up() {
    class Tests_Admin_wpPluginsListTable extends WP_UnitTestCase { 
    7272         * Restores the `$s` global after each test.
    7373         */
    7474        public function tear_down() {
    75                 global $s;
     75                global $search_term;
    7676
    77                 $s = self::$original_s;
     77                $search_term = self::$original_s;
    7878
    7979                parent::tear_down();
    8080        }
    class Tests_Admin_wpPluginsListTable extends WP_UnitTestCase { 
    307307         * @covers WP_Plugins_List_Table::prepare_items
    308308         */
    309309        public function test_plugins_list_filter() {
    310                 global $status, $s;
     310                global $status, $search_term;
    311311
    312                 $old_status = $status;
    313                 $status     = 'mustuse';
    314                 $s          = '';
     312                $old_status  = $status;
     313                $status      = 'mustuse';
     314                $search_term = '';
    315315
    316316                add_filter( 'plugins_list', array( $this, 'plugins_list_filter' ), 10, 1 );
    317317                $this->table->prepare_items();