Decrement update count bubbles as plugins/themes are updated, live.
props gcorne, mitchoyoshitaka. fixes #17703. git-svn-id: https://develop.svn.wordpress.org/trunk@27280 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
544b73ec4c
commit
9ddf03c0bb
@ -92,6 +92,23 @@ class WP_Upgrader_Skin {
|
||||
function before() {}
|
||||
function after() {}
|
||||
|
||||
/**
|
||||
* Output JavaScript that calls function to decrement the update counts.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
protected function decrement_update_count( $type ) {
|
||||
if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
|
||||
return;
|
||||
}
|
||||
echo '<script type="text/javascript">
|
||||
(function( wp ) {
|
||||
if ( wp && wp.updates.decrementCount ) {
|
||||
wp.updates.decrementCount( "' . $type . '" );
|
||||
}
|
||||
})( window.wp );
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,6 +141,8 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>';
|
||||
}
|
||||
|
||||
$this->decrement_update_count( 'plugin' );
|
||||
|
||||
$update_actions = array(
|
||||
'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
|
||||
'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
|
||||
@ -252,6 +271,22 @@ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
wp_ob_end_flush_all();
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output JavaScript that sends message to parent window to decrement the update counts.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
protected function decrement_update_count( $type ) {
|
||||
if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
|
||||
return;
|
||||
}
|
||||
echo '<script type="text/javascript">
|
||||
if ( window.postMessage && JSON ) {
|
||||
window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
|
||||
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
|
||||
@ -272,6 +307,7 @@ class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
|
||||
|
||||
function after($title = '') {
|
||||
parent::after($this->plugin_info['Title']);
|
||||
$this->decrement_update_count( 'plugin' );
|
||||
}
|
||||
function bulk_footer() {
|
||||
parent::bulk_footer();
|
||||
@ -306,6 +342,7 @@ class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
|
||||
|
||||
function after($title = '') {
|
||||
parent::after( $this->theme_info->display('Name') );
|
||||
$this->decrement_update_count( 'theme' );
|
||||
}
|
||||
|
||||
function bulk_footer() {
|
||||
@ -479,6 +516,7 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
}
|
||||
|
||||
function after() {
|
||||
$this->decrement_update_count( 'theme' );
|
||||
|
||||
$update_actions = array();
|
||||
if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
|
||||
@ -561,6 +599,7 @@ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin {
|
||||
}
|
||||
|
||||
function bulk_footer() {
|
||||
$this->decrement_update_count( 'translation' );
|
||||
$update_actions = array();
|
||||
$update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" title="' . esc_attr__( 'Go to WordPress Updates page' ) . '" target="_parent">' . __( 'Return to WordPress Updates' ) . '</a>';
|
||||
$update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
|
||||
|
@ -560,7 +560,7 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
|
||||
|
||||
if ( !isset( $current->response[ $plugin ] ) ) {
|
||||
$this->skin->set_result(true);
|
||||
$this->skin->set_result('up_to_date');
|
||||
$this->skin->before();
|
||||
$this->skin->feedback('up_to_date');
|
||||
$this->skin->after();
|
||||
@ -863,7 +863,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||
if ( !isset( $current->response[ $theme ] ) ) {
|
||||
$this->skin->before();
|
||||
$this->skin->set_result(false);
|
||||
$this->skin->error('up_to_date');
|
||||
$this->skin->error( 'up_to_date' );
|
||||
$this->skin->after();
|
||||
return false;
|
||||
}
|
||||
@ -948,7 +948,7 @@ class Theme_Upgrader extends WP_Upgrader {
|
||||
if ( !isset( $current->response[ $theme ] ) ) {
|
||||
$this->skin->set_result(true);
|
||||
$this->skin->before();
|
||||
$this->skin->feedback('up_to_date');
|
||||
$this->skin->feedback( 'up_to_date' );
|
||||
$this->skin->after();
|
||||
$results[$theme] = true;
|
||||
continue;
|
||||
|
63
src/wp-admin/js/updates.js
Normal file
63
src/wp-admin/js/updates.js
Normal file
@ -0,0 +1,63 @@
|
||||
window.wp = window.wp || {};
|
||||
|
||||
(function( $, wp ) {
|
||||
|
||||
wp.updates = {};
|
||||
|
||||
/**
|
||||
* Decrement update counts throughout the various menus
|
||||
*
|
||||
* @param {string} updateType
|
||||
*/
|
||||
wp.updates.decrementCount = function( upgradeType ) {
|
||||
var count, pluginCount, $elem;
|
||||
|
||||
$elem = $( '#wp-admin-bar-updates .ab-label' );
|
||||
count = $elem.text();
|
||||
count = parseInt( count, 10 ) - 1;
|
||||
if ( count < 0 ) {
|
||||
return;
|
||||
}
|
||||
$elem.text( count );
|
||||
|
||||
$elem = $( 'a[href="update-core.php"] .update-plugins' );
|
||||
$elem.each( function( index, elem ) {
|
||||
elem.className = elem.className.replace( /count-\d+/, 'count-' + count );
|
||||
} );
|
||||
$elem.find( '.update-count' ).text( count );
|
||||
|
||||
if ( 'plugin' === upgradeType ) {
|
||||
$elem = $( '#menu-plugins' );
|
||||
pluginCount = $elem.find( '.plugin-count' ).eq(0).text();
|
||||
pluginCount = parseInt( pluginCount, 10 ) - 1;
|
||||
if ( count < 0 ) {
|
||||
return;
|
||||
}
|
||||
$elem.find( '.plugin-count' ).text( pluginCount );
|
||||
$elem.find( '.update-plugins' ).each( function( index, elem ) {
|
||||
elem.className = elem.className.replace( /count-\d+/, 'count-' + pluginCount );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
$( window ).on( 'message', function( e ) {
|
||||
var event = e.originalEvent,
|
||||
message,
|
||||
loc = document.location,
|
||||
expectedOrigin = loc.protocol + '//' + loc.hostname;
|
||||
|
||||
if ( event.origin !== expectedOrigin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
message = $.parseJSON( event.data );
|
||||
|
||||
if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp.updates.decrementCount( message.upgradeType );
|
||||
|
||||
} );
|
||||
|
||||
})( jQuery, window.wp );
|
@ -113,6 +113,7 @@ if ( $action ) {
|
||||
$title = __( 'Update Plugins' );
|
||||
$parent_file = 'plugins.php';
|
||||
|
||||
wp_enqueue_script( 'updates' );
|
||||
require_once(ABSPATH . 'wp-admin/admin-header.php');
|
||||
|
||||
echo '<div class="wrap">';
|
||||
|
@ -11,6 +11,7 @@ require_once( dirname( __FILE__ ) . '/admin.php' );
|
||||
|
||||
wp_enqueue_style( 'plugin-install' );
|
||||
wp_enqueue_script( 'plugin-install' );
|
||||
wp_enqueue_script( 'updates' );
|
||||
add_thickbox();
|
||||
|
||||
if ( is_multisite() && ! is_network_admin() ) {
|
||||
|
@ -37,7 +37,7 @@ if ( isset($_GET['action']) ) {
|
||||
$url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
|
||||
$nonce = 'bulk-update-plugins';
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
wp_enqueue_script( 'updates' );
|
||||
iframe_header();
|
||||
|
||||
$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
@ -54,6 +54,8 @@ if ( isset($_GET['action']) ) {
|
||||
$title = __('Update Plugin');
|
||||
$parent_file = 'plugins.php';
|
||||
$submenu_file = 'plugins.php';
|
||||
|
||||
wp_enqueue_script( 'updates' );
|
||||
require_once(ABSPATH . 'wp-admin/admin-header.php');
|
||||
|
||||
$nonce = 'upgrade-plugin_' . $plugin;
|
||||
@ -154,6 +156,7 @@ if ( isset($_GET['action']) ) {
|
||||
check_admin_referer('upgrade-theme_' . $theme);
|
||||
|
||||
wp_enqueue_script( 'customize-loader' );
|
||||
wp_enqueue_script( 'updates' );
|
||||
|
||||
$title = __('Update Theme');
|
||||
$parent_file = 'themes.php';
|
||||
@ -185,7 +188,7 @@ if ( isset($_GET['action']) ) {
|
||||
$url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
|
||||
$nonce = 'bulk-update-themes';
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
wp_enqueue_script( 'updates' );
|
||||
iframe_header();
|
||||
|
||||
$upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
||||
|
@ -481,6 +481,8 @@ function wp_default_scripts( &$scripts ) {
|
||||
'ays' => __('Are you sure you want to install this plugin?')
|
||||
) );
|
||||
|
||||
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery' ) );
|
||||
|
||||
$scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
|
||||
|
||||
$scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );
|
||||
|
Loading…
Reference in New Issue
Block a user