Make WordPress Core


Ignore:
Timestamp:
07/18/2016 01:59:17 PM (8 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.

File:
1 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() ) {
Note: See TracChangeset for help on using the changeset viewer.