Make WordPress Core

Changeset 38091


Ignore:
Timestamp:
07/18/2016 01:59:17 PM (10 years ago)
Author:
ocean90
Message:

Plugins: Use the correct admin screen when searching for plugins via Ajax.

Both list tables provide different actions based on where they are loaded, regular admin or network admin. Since there is only one Ajax handler for both screens we have to set the current screen before using the list tables.

Props swissspidy, ocean90.
Fixes #37373.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r38057 r38091  
    37823782 * @since 4.6.0
    37833783 *
    3784  * @global WP_List_Table $wp_list_table Current list table instance.
    3785  * @global string        $hook_suffix   Current admin page.
    3786  * @global string        $s             Search term.
     3784 * @global string $s Search term.
    37873785 */
    37883786function wp_ajax_search_plugins() {
    37893787        check_ajax_referer( 'updates' );
    37903788
    3791         global $wp_list_table, $hook_suffix, $s;
    3792         $hook_suffix = 'plugins.php';
     3789        $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
     3790        if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) {
     3791                set_current_screen( $pagenow );
     3792        }
    37933793
    37943794        /** @var WP_Plugins_List_Table $wp_list_table */
    3795         $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
    3796         $status        = array();
     3795        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array(
     3796                'screen' => get_current_screen(),
     3797        ) );
     3798
     3799        $status = array();
    37973800
    37983801        if ( ! $wp_list_table->ajax_user_can() ) {
     
    38073810        ) ), network_admin_url( 'plugins.php', 'relative' ) );
    38083811
    3809         $s = sanitize_text_field( $_POST['s'] );
     3812        $GLOBALS['s'] = wp_unslash( $_POST['s'] );
    38103813
    38113814        $wp_list_table->prepare_items();
     
    38233826 *
    38243827 * @since 4.6.0
    3825  *
    3826  * @global WP_List_Table $wp_list_table Current list table instance.
    3827  * @global string        $hook_suffix   Current admin page.
    38283828 */
    38293829function wp_ajax_search_install_plugins() {
    38303830        check_ajax_referer( 'updates' );
    38313831
    3832         global $wp_list_table, $hook_suffix;
    3833         $hook_suffix = 'plugin-install.php';
     3832        $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
     3833        if ( 'plugin-install-network' === $pagenow || 'plugin-install' === $pagenow ) {
     3834                set_current_screen( $pagenow );
     3835        }
    38343836
    38353837        /** @var WP_Plugin_Install_List_Table $wp_list_table */
    3836         $wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table' );
    3837         $status        = array();
     3838        $wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table', array(
     3839                'screen' => get_current_screen(),
     3840        ) );
     3841
     3842        $status = array();
    38383843
    38393844        if ( ! $wp_list_table->ajax_user_can() ) {
  • trunk/src/wp-admin/js/updates.js

    r38075 r38091  
    20322032                                data  = _.extend( {
    20332033                                        _ajax_nonce: wp.updates.ajaxNonce,
    2034                                         s:           $( '<p />' ).html( $( this ).val() ).text(),
     2034                                        s:           $( this ).val(),
    20352035                                        tab:         'search',
    2036                                         type:        $( '#typeselector' ).val()
     2036                                        type:        $( '#typeselector' ).val(),
     2037                                        pagenow:     pagenow
    20372038                                }, { type: 'term' } );
    20382039
     
    20442045
    20452046                        if ( history.pushState ) {
    2046                                 history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, '_ajax_nonce' ) ) );
     2047                                history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ) );
    20472048                        }
    20482049
     
    20722073                        var data = {
    20732074                                _ajax_nonce: wp.updates.ajaxNonce,
    2074                                 s:           event.target.value
     2075                                s:           event.target.value,
     2076                                pagenow:     pagenow
    20752077                        };
    20762078
     
    21002102
    21012103                                // Can we just ditch this whole subtitle business?
    2102                                 var $subTitle    = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', data.s ) ),
     2104                                var $subTitle    = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', _.escape( data.s ) ) ),
    21032105                                        $oldSubTitle = $( '.wrap .subtitle' );
    21042106
Note: See TracChangeset for help on using the changeset viewer.