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.
Built from https://develop.svn.wordpress.org/trunk@38091


git-svn-id: http://core.svn.wordpress.org/trunk@38032 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-07-18 14:00:34 +00:00
parent ea38eaca7d
commit a320320ea0
4 changed files with 29 additions and 22 deletions

View File

@ -3781,18 +3781,21 @@ function wp_ajax_delete_plugin() {
*
* @since 4.6.0
*
* @global WP_List_Table $wp_list_table Current list table instance.
* @global string $hook_suffix Current admin page.
* @global string $s Search term.
*/
function wp_ajax_search_plugins() {
check_ajax_referer( 'updates' );
global $wp_list_table, $hook_suffix, $s;
$hook_suffix = 'plugins.php';
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) {
set_current_screen( $pagenow );
}
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table', array(
'screen' => get_current_screen(),
) );
$status = array();
if ( ! $wp_list_table->ajax_user_can() ) {
@ -3806,7 +3809,7 @@ function wp_ajax_search_plugins() {
'action' => null,
) ), network_admin_url( 'plugins.php', 'relative' ) );
$s = sanitize_text_field( $_POST['s'] );
$GLOBALS['s'] = wp_unslash( $_POST['s'] );
$wp_list_table->prepare_items();
@ -3822,18 +3825,20 @@ function wp_ajax_search_plugins() {
* Ajax handler for searching plugins to install.
*
* @since 4.6.0
*
* @global WP_List_Table $wp_list_table Current list table instance.
* @global string $hook_suffix Current admin page.
*/
function wp_ajax_search_install_plugins() {
check_ajax_referer( 'updates' );
global $wp_list_table, $hook_suffix;
$hook_suffix = 'plugin-install.php';
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
if ( 'plugin-install-network' === $pagenow || 'plugin-install' === $pagenow ) {
set_current_screen( $pagenow );
}
/** @var WP_Plugin_Install_List_Table $wp_list_table */
$wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table' );
$wp_list_table = _get_list_table( 'WP_Plugin_Install_List_Table', array(
'screen' => get_current_screen(),
) );
$status = array();
if ( ! $wp_list_table->ajax_user_can() ) {

View File

@ -2031,9 +2031,10 @@
var $form = $( '#plugin-filter' ).empty(),
data = _.extend( {
_ajax_nonce: wp.updates.ajaxNonce,
s: $( '<p />' ).html( $( this ).val() ).text(),
s: $( this ).val(),
tab: 'search',
type: $( '#typeselector' ).val()
type: $( '#typeselector' ).val(),
pagenow: pagenow
}, { type: 'term' } );
if ( wp.updates.searchTerm === data.s ) {
@ -2043,7 +2044,7 @@
}
if ( history.pushState ) {
history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, '_ajax_nonce' ) ) );
history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?' + $.param( _.omit( data, [ '_ajax_nonce', 'pagenow' ] ) ) );
}
if ( 'undefined' !== typeof wp.updates.searchRequest ) {
@ -2071,7 +2072,8 @@
$pluginSearch.on( 'keyup input', _.debounce( function( event ) {
var data = {
_ajax_nonce: wp.updates.ajaxNonce,
s: event.target.value
s: event.target.value,
pagenow: pagenow
};
// Clear on escape.
@ -2099,7 +2101,7 @@
wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
// Can we just ditch this whole subtitle business?
var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', data.s ) ),
var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', _.escape( data.s ) ) ),
$oldSubTitle = $( '.wrap .subtitle' );
if ( ! data.s.length ) {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-beta3-38090';
$wp_version = '4.6-beta3-38091';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.