<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27280] trunk/src: Decrement update count bubbles as plugins/themes are updated, live.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27280">27280</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-02-26 06:54:26 +0000 (Wed, 26 Feb 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Decrement update count bubbles as plugins/themes are updated, live.
props gcorne, mitchoyoshitaka.
fixes <a href="http://core.trac.wordpress.org/ticket/17703">#17703</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderskinsphp">trunk/src/wp-admin/includes/class-wp-upgrader-skins.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
<li><a href="#trunksrcwpadminpluginsphp">trunk/src/wp-admin/plugins.php</a></li>
<li><a href="#trunksrcwpadminupdatecorephp">trunk/src/wp-admin/update-core.php</a></li>
<li><a href="#trunksrcwpadminupdatephp">trunk/src/wp-admin/update.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjsupdatesjs">trunk/src/wp-admin/js/updates.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderskinsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader-skins.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -92,6 +92,23 @@
</span><span class="cx"> function before() {}
</span><span class="cx"> function after() {}
</span><span class="cx">
</span><ins>+ /**
+ * 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>';
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -124,6 +141,8 @@
</span><span class="cx"> 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>';
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ $this->decrement_update_count( 'plugin' );
+
</ins><span class="cx"> $update_actions = array(
</span><span class="cx"> '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>',
</span><span class="cx"> 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
</span><span class="lines">@@ -252,6 +271,22 @@
</span><span class="cx"> wp_ob_end_flush_all();
</span><span class="cx"> flush();
</span><span class="cx"> }
</span><ins>+
+ /**
+ * 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>';
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
</span><span class="lines">@@ -272,6 +307,7 @@
</span><span class="cx">
</span><span class="cx"> function after($title = '') {
</span><span class="cx"> parent::after($this->plugin_info['Title']);
</span><ins>+ $this->decrement_update_count( 'plugin' );
</ins><span class="cx"> }
</span><span class="cx"> function bulk_footer() {
</span><span class="cx"> parent::bulk_footer();
</span><span class="lines">@@ -306,6 +342,7 @@
</span><span class="cx">
</span><span class="cx"> function after($title = '') {
</span><span class="cx"> parent::after( $this->theme_info->display('Name') );
</span><ins>+ $this->decrement_update_count( 'theme' );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bulk_footer() {
</span><span class="lines">@@ -479,6 +516,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function after() {
</span><ins>+ $this->decrement_update_count( 'theme' );
</ins><span class="cx">
</span><span class="cx"> $update_actions = array();
</span><span class="cx"> if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) {
</span><span class="lines">@@ -561,6 +599,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bulk_footer() {
</span><ins>+ $this->decrement_update_count( 'translation' );
</ins><span class="cx"> $update_actions = array();
</span><span class="cx"> $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>';
</span><span class="cx"> $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
</span></span></pre></div>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -560,7 +560,7 @@
</span><span class="cx"> $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
</span><span class="cx">
</span><span class="cx"> if ( !isset( $current->response[ $plugin ] ) ) {
</span><del>- $this->skin->set_result(true);
</del><ins>+ $this->skin->set_result('up_to_date');
</ins><span class="cx"> $this->skin->before();
</span><span class="cx"> $this->skin->feedback('up_to_date');
</span><span class="cx"> $this->skin->after();
</span><span class="lines">@@ -863,7 +863,7 @@
</span><span class="cx"> if ( !isset( $current->response[ $theme ] ) ) {
</span><span class="cx"> $this->skin->before();
</span><span class="cx"> $this->skin->set_result(false);
</span><del>- $this->skin->error('up_to_date');
</del><ins>+ $this->skin->error( 'up_to_date' );
</ins><span class="cx"> $this->skin->after();
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -948,7 +948,7 @@
</span><span class="cx"> if ( !isset( $current->response[ $theme ] ) ) {
</span><span class="cx"> $this->skin->set_result(true);
</span><span class="cx"> $this->skin->before();
</span><del>- $this->skin->feedback('up_to_date');
</del><ins>+ $this->skin->feedback( 'up_to_date' );
</ins><span class="cx"> $this->skin->after();
</span><span class="cx"> $results[$theme] = true;
</span><span class="cx"> continue;
</span></span></pre></div>
<a id="trunksrcwpadminjsupdatesjs"></a>
<div class="addfile"><h4>Added: trunk/src/wp-admin/js/updates.js (0 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/updates.js (rev 0)
+++ trunk/src/wp-admin/js/updates.js 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -0,0 +1,63 @@
</span><ins>+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 );
</ins></span></pre></div>
<a id="trunksrcwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/plugins.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/plugins.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-admin/plugins.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -113,6 +113,7 @@
</span><span class="cx"> $title = __( 'Update Plugins' );
</span><span class="cx"> $parent_file = 'plugins.php';
</span><span class="cx">
</span><ins>+ wp_enqueue_script( 'updates' );
</ins><span class="cx"> require_once(ABSPATH . 'wp-admin/admin-header.php');
</span><span class="cx">
</span><span class="cx"> echo '<div class="wrap">';
</span></span></pre></div>
<a id="trunksrcwpadminupdatecorephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/update-core.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/update-core.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-admin/update-core.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -11,6 +11,7 @@
</span><span class="cx">
</span><span class="cx"> wp_enqueue_style( 'plugin-install' );
</span><span class="cx"> wp_enqueue_script( 'plugin-install' );
</span><ins>+wp_enqueue_script( 'updates' );
</ins><span class="cx"> add_thickbox();
</span><span class="cx">
</span><span class="cx"> if ( is_multisite() && ! is_network_admin() ) {
</span></span></pre></div>
<a id="trunksrcwpadminupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/update.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/update.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-admin/update.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx"> $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
</span><span class="cx"> $nonce = 'bulk-update-plugins';
</span><span class="cx">
</span><del>- wp_enqueue_script('jquery');
</del><ins>+ wp_enqueue_script( 'updates' );
</ins><span class="cx"> iframe_header();
</span><span class="cx">
</span><span class="cx"> $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
</span><span class="lines">@@ -54,6 +54,8 @@
</span><span class="cx"> $title = __('Update Plugin');
</span><span class="cx"> $parent_file = 'plugins.php';
</span><span class="cx"> $submenu_file = 'plugins.php';
</span><ins>+
+ wp_enqueue_script( 'updates' );
</ins><span class="cx"> require_once(ABSPATH . 'wp-admin/admin-header.php');
</span><span class="cx">
</span><span class="cx"> $nonce = 'upgrade-plugin_' . $plugin;
</span><span class="lines">@@ -154,6 +156,7 @@
</span><span class="cx"> check_admin_referer('upgrade-theme_' . $theme);
</span><span class="cx">
</span><span class="cx"> wp_enqueue_script( 'customize-loader' );
</span><ins>+ wp_enqueue_script( 'updates' );
</ins><span class="cx">
</span><span class="cx"> $title = __('Update Theme');
</span><span class="cx"> $parent_file = 'themes.php';
</span><span class="lines">@@ -185,7 +188,7 @@
</span><span class="cx"> $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
</span><span class="cx"> $nonce = 'bulk-update-themes';
</span><span class="cx">
</span><del>- wp_enqueue_script('jquery');
</del><ins>+ wp_enqueue_script( 'updates' );
</ins><span class="cx"> iframe_header();
</span><span class="cx">
</span><span class="cx"> $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/script-loader.php (27279 => 27280)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/script-loader.php 2014-02-26 04:53:21 UTC (rev 27279)
+++ trunk/src/wp-includes/script-loader.php 2014-02-26 06:54:26 UTC (rev 27280)
</span><span class="lines">@@ -481,6 +481,8 @@
</span><span class="cx"> 'ays' => __('Are you sure you want to install this plugin?')
</span><span class="cx"> ) );
</span><span class="cx">
</span><ins>+ $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery' ) );
+
</ins><span class="cx"> $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
</span><span class="cx">
</span><span class="cx"> $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );
</span></span></pre>
</div>
</div>
</body>
</html>