Upgrade/Install: Refresh update counts after page load.
By enqueuing the updates script in the footer and passing the number of available updates to it after page load, the update bubbles will be more accurate. Props ocean90, swissspidy. Fixes #13071. Built from https://develop.svn.wordpress.org/trunk@38827 git-svn-id: http://core.svn.wordpress.org/trunk@38770 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
deda5d9796
commit
e4d7dd2b8a
|
@ -150,7 +150,8 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
||||||
$total_this_page = $totals[ $status ];
|
$total_this_page = $totals[ $status ];
|
||||||
|
|
||||||
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
'totals' => $totals,
|
'themes' => $totals,
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
if ( $orderby ) {
|
if ( $orderby ) {
|
||||||
|
|
|
@ -253,6 +253,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
|
||||||
|
|
||||||
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
'plugins' => $js_plugins,
|
'plugins' => $js_plugins,
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
if ( ! $orderby ) {
|
if ( ! $orderby ) {
|
||||||
|
|
|
@ -21,10 +21,12 @@
|
||||||
* @param {Array} settings.plugins.inactive Base names of inactive plugins.
|
* @param {Array} settings.plugins.inactive Base names of inactive plugins.
|
||||||
* @param {Array} settings.plugins.upgrade Base names of plugins with updates available.
|
* @param {Array} settings.plugins.upgrade Base names of plugins with updates available.
|
||||||
* @param {Array} settings.plugins.recently_activated Base names of recently activated plugins.
|
* @param {Array} settings.plugins.recently_activated Base names of recently activated plugins.
|
||||||
* @param {object=} settings.totals Plugin/theme status information or null.
|
* @param {object=} settings.themes Plugin/theme status information or null.
|
||||||
* @param {number} settings.totals.all Amount of all plugins or themes.
|
* @param {number} settings.themes.all Amount of all themes.
|
||||||
* @param {number} settings.totals.upgrade Amount of plugins or themes with updates available.
|
* @param {number} settings.themes.upgrade Amount of themes with updates available.
|
||||||
* @param {number} settings.totals.disabled Amount of disabled themes.
|
* @param {number} settings.themes.disabled Amount of disabled themes.
|
||||||
|
* @param {object=} settings.totals Combined information for available update counts.
|
||||||
|
* @param {number} settings.totals.count Holds the amount of available updates.
|
||||||
*/
|
*/
|
||||||
(function( $, wp, settings ) {
|
(function( $, wp, settings ) {
|
||||||
var $document = $( document );
|
var $document = $( document );
|
||||||
|
@ -260,6 +262,70 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes update counts everywhere on the screen.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
*/
|
||||||
|
wp.updates.refreshCount = function() {
|
||||||
|
var $adminBarUpdates = $( '#wp-admin-bar-updates' ),
|
||||||
|
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
|
||||||
|
$pluginsNavMenuUpdateCount = $( 'a[href="plugins.php"] .update-plugins' ),
|
||||||
|
$appearanceNavMenuUpdateCount = $( 'a[href="themes.php"] .update-plugins' ),
|
||||||
|
itemCount;
|
||||||
|
|
||||||
|
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
|
||||||
|
$adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total );
|
||||||
|
|
||||||
|
// Remove the update count from the toolbar if it's zero.
|
||||||
|
if ( 0 === settings.totals.counts.total ) {
|
||||||
|
$adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the "Updates" menu item.
|
||||||
|
$dashboardNavMenuUpdateCount.each( function( index, element ) {
|
||||||
|
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.total );
|
||||||
|
} );
|
||||||
|
if ( settings.totals.counts.total > 0 ) {
|
||||||
|
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
|
||||||
|
} else {
|
||||||
|
$dashboardNavMenuUpdateCount.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the "Plugins" menu item.
|
||||||
|
$pluginsNavMenuUpdateCount.each( function( index, element ) {
|
||||||
|
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins );
|
||||||
|
} );
|
||||||
|
if ( settings.totals.counts.total > 0 ) {
|
||||||
|
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
|
||||||
|
} else {
|
||||||
|
$pluginsNavMenuUpdateCount.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the "Appearance" menu item.
|
||||||
|
$appearanceNavMenuUpdateCount.each( function( index, element ) {
|
||||||
|
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes );
|
||||||
|
} );
|
||||||
|
if ( settings.totals.counts.total > 0 ) {
|
||||||
|
$appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
|
||||||
|
} else {
|
||||||
|
$appearanceNavMenuUpdateCount.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update list table filter navigation.
|
||||||
|
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
|
||||||
|
itemCount = settings.totals.counts.plugins;
|
||||||
|
} else if ( 'themes' === pagenow || 'themes-network' === pagenow ) {
|
||||||
|
itemCount = settings.totals.counts.themes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( itemCount > 0 ) {
|
||||||
|
$( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
|
||||||
|
} else {
|
||||||
|
$( '.subsubsub .upgrade' ).remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the update counts throughout the various menus.
|
* Decrements the update counts throughout the various menus.
|
||||||
*
|
*
|
||||||
|
@ -272,62 +338,15 @@
|
||||||
* Can be 'plugin', 'theme'.
|
* Can be 'plugin', 'theme'.
|
||||||
*/
|
*/
|
||||||
wp.updates.decrementCount = function( type ) {
|
wp.updates.decrementCount = function( type ) {
|
||||||
var $adminBarUpdates = $( '#wp-admin-bar-updates' ),
|
settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
|
||||||
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
|
|
||||||
count = $adminBarUpdates.find( '.ab-label' ).text(),
|
|
||||||
$menuItem, $itemCount, itemCount;
|
|
||||||
|
|
||||||
count = parseInt( count, 10 ) - 1;
|
|
||||||
|
|
||||||
if ( count < 0 || isNaN( count ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
|
|
||||||
$adminBarUpdates.find( '.ab-label' ).text( count );
|
|
||||||
|
|
||||||
// Remove the update count from the toolbar if it's zero.
|
|
||||||
if ( ! count ) {
|
|
||||||
$adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the "Updates" menu item.
|
|
||||||
$dashboardNavMenuUpdateCount.each( function( index, element ) {
|
|
||||||
element.className = element.className.replace( /count-\d+/, 'count-' + count );
|
|
||||||
} );
|
|
||||||
|
|
||||||
$dashboardNavMenuUpdateCount.removeAttr( 'title' );
|
|
||||||
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( count );
|
|
||||||
|
|
||||||
if ( 'plugin' === type ) {
|
if ( 'plugin' === type ) {
|
||||||
$menuItem = $( '#menu-plugins' );
|
settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 );
|
||||||
$itemCount = $menuItem.find( '.plugin-count' );
|
|
||||||
} else if ( 'theme' === type ) {
|
} else if ( 'theme' === type ) {
|
||||||
$menuItem = $( '#menu-appearance' );
|
settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
|
||||||
$itemCount = $menuItem.find( '.theme-count' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrement the counter of the other menu items.
|
wp.updates.refreshCount( type );
|
||||||
if ( $itemCount ) {
|
|
||||||
itemCount = $itemCount.eq( 0 ).text();
|
|
||||||
itemCount = parseInt( itemCount, 10 ) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( itemCount < 0 || isNaN( itemCount ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( itemCount > 0 ) {
|
|
||||||
$( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
|
|
||||||
|
|
||||||
$itemCount.text( itemCount );
|
|
||||||
$menuItem.find( '.update-plugins' ).each( function( index, element ) {
|
|
||||||
element.className = element.className.replace( /count-\d+/, 'count-' + itemCount );
|
|
||||||
} );
|
|
||||||
} else {
|
|
||||||
$( '.subsubsub .upgrade' ).remove();
|
|
||||||
$menuItem.find( '.update-plugins' ).remove();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1251,7 +1270,7 @@
|
||||||
$themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() {
|
$themeRows.css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() {
|
||||||
var $views = $( '.subsubsub' ),
|
var $views = $( '.subsubsub' ),
|
||||||
$themeRow = $( this ),
|
$themeRow = $( this ),
|
||||||
totals = settings.totals,
|
totals = settings.themes,
|
||||||
deletedRow = wp.template( 'item-deleted-row' );
|
deletedRow = wp.template( 'item-deleted-row' );
|
||||||
|
|
||||||
if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) {
|
if ( ! $themeRow.hasClass( 'plugin-update-tr' ) ) {
|
||||||
|
@ -1689,6 +1708,12 @@
|
||||||
$pluginSearch = $( '.plugins-php .wp-filter-search' ),
|
$pluginSearch = $( '.plugins-php .wp-filter-search' ),
|
||||||
$pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' );
|
$pluginInstallSearch = $( '.plugin-install-php .wp-filter-search' );
|
||||||
|
|
||||||
|
settings = _.extend( settings, window._wpUpdatesItemCounts || {} );
|
||||||
|
|
||||||
|
if ( settings.totals ) {
|
||||||
|
wp.updates.refreshCount();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Whether a user needs to submit filesystem credentials.
|
* Whether a user needs to submit filesystem credentials.
|
||||||
*
|
*
|
||||||
|
@ -2412,4 +2437,4 @@
|
||||||
*/
|
*/
|
||||||
$( window ).on( 'beforeunload', wp.updates.beforeunload );
|
$( window ).on( 'beforeunload', wp.updates.beforeunload );
|
||||||
} );
|
} );
|
||||||
})( jQuery, window.wp, _.extend( window._wpUpdatesSettings, window._wpUpdatesItemCounts || {} ) );
|
})( jQuery, window.wp, window._wpUpdatesSettings );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -38,7 +38,7 @@ if ( ! is_multisite() ) {
|
||||||
$cap = 'update_plugins';
|
$cap = 'update_plugins';
|
||||||
else
|
else
|
||||||
$cap = 'update_themes';
|
$cap = 'update_themes';
|
||||||
$submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), $cap, 'update-core.php');
|
$submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), $cap, 'update-core.php');
|
||||||
unset( $cap );
|
unset( $cap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ $submenu['index.php'][0] = array( __( 'Home' ), 'read', 'index.php' );
|
||||||
|
|
||||||
$update_data = wp_get_update_data();
|
$update_data = wp_get_update_data();
|
||||||
if ( $update_data['counts']['total'] ) {
|
if ( $update_data['counts']['total'] ) {
|
||||||
$submenu['index.php'][10] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n( $update_data['counts']['total'] ) . "</span></span>" ), 'update_core', 'update-core.php' );
|
$submenu['index.php'][10] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-{$update_data['counts']['total']}'><span class='update-count'>" . number_format_i18n( $update_data['counts']['total'] ) . "</span></span>" ), 'update_core', 'update-core.php' );
|
||||||
} else {
|
} else {
|
||||||
$submenu['index.php'][10] = array( __( 'Updates' ), 'update_core', 'update-core.php' );
|
$submenu['index.php'][10] = array( __( 'Updates' ), 'update_core', 'update-core.php' );
|
||||||
}
|
}
|
||||||
|
|
|
@ -490,4 +490,8 @@ wp_print_request_filesystem_credentials_modal();
|
||||||
wp_print_admin_notice_templates();
|
wp_print_admin_notice_templates();
|
||||||
wp_print_update_row_templates();
|
wp_print_update_row_templates();
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
require( ABSPATH . 'wp-admin/admin-footer.php' );
|
require( ABSPATH . 'wp-admin/admin-footer.php' );
|
||||||
|
|
|
@ -618,6 +618,11 @@ if ( 'upgrade-core' == $action ) {
|
||||||
*/
|
*/
|
||||||
do_action( 'core_upgrade_preamble' );
|
do_action( 'core_upgrade_preamble' );
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
include(ABSPATH . 'wp-admin/admin-footer.php');
|
include(ABSPATH . 'wp-admin/admin-footer.php');
|
||||||
|
|
||||||
} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
|
} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
|
||||||
|
@ -642,6 +647,10 @@ if ( 'upgrade-core' == $action ) {
|
||||||
if ( isset( $_POST['upgrade'] ) )
|
if ( isset( $_POST['upgrade'] ) )
|
||||||
do_core_upgrade($reinstall);
|
do_core_upgrade($reinstall);
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
include(ABSPATH . 'wp-admin/admin-footer.php');
|
include(ABSPATH . 'wp-admin/admin-footer.php');
|
||||||
|
|
||||||
} elseif ( 'do-plugin-upgrade' == $action ) {
|
} elseif ( 'do-plugin-upgrade' == $action ) {
|
||||||
|
@ -670,6 +679,11 @@ if ( 'upgrade-core' == $action ) {
|
||||||
echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
|
echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
|
||||||
echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
|
echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
include(ABSPATH . 'wp-admin/admin-footer.php');
|
include(ABSPATH . 'wp-admin/admin-footer.php');
|
||||||
|
|
||||||
} elseif ( 'do-theme-upgrade' == $action ) {
|
} elseif ( 'do-theme-upgrade' == $action ) {
|
||||||
|
@ -700,6 +714,11 @@ if ( 'upgrade-core' == $action ) {
|
||||||
<iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
|
<iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
include(ABSPATH . 'wp-admin/admin-footer.php');
|
include(ABSPATH . 'wp-admin/admin-footer.php');
|
||||||
|
|
||||||
} elseif ( 'do-translation-upgrade' == $action ) {
|
} elseif ( 'do-translation-upgrade' == $action ) {
|
||||||
|
@ -720,6 +739,10 @@ if ( 'upgrade-core' == $action ) {
|
||||||
$upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
|
$upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
|
||||||
$result = $upgrader->bulk_upgrade();
|
$result = $upgrader->bulk_upgrade();
|
||||||
|
|
||||||
|
wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
|
||||||
|
'totals' => wp_get_update_data(),
|
||||||
|
) );
|
||||||
|
|
||||||
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
|
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -611,7 +611,7 @@ function wp_default_scripts( &$scripts ) {
|
||||||
'ays' => __('Are you sure you want to install this plugin?')
|
'ays' => __('Are you sure you want to install this plugin?')
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ) );
|
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
|
||||||
did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array(
|
did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array(
|
||||||
'ajax_nonce' => wp_create_nonce( 'updates' ),
|
'ajax_nonce' => wp_create_nonce( 'updates' ),
|
||||||
'l10n' => array(
|
'l10n' => array(
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-alpha-38826';
|
$wp_version = '4.7-alpha-38827';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue