Make WordPress Core

Ticket #33345: 33345-updates.diff

File 33345-updates.diff, 8.3 KB (added by A5hleyRich, 9 years ago)
  • new file src/wp-admin/js/check-updates.js

    diff --git src/wp-admin/js/check-updates.js src/wp-admin/js/check-updates.js
    new file mode 100644
    index 0000000..4b82716
    - +  
     1(function( $, wp, settings ) {
     2        wp = wp || {};
     3
     4        /**
     5         * The WP checkUpdates object.
     6         *
     7         * @type {object}
     8         */
     9        wp.checkUpdates = {};
     10
     11        /**
     12         * Current update counts.
     13         *
     14         * @type {object}
     15         */
     16        wp.checkUpdates.currentCounts = settings.current_updates.counts;
     17
     18        /**
     19         * Current update string.
     20         *
     21         * @type {string}
     22         */
     23        wp.checkUpdates.currentTitle = settings.current_updates.title;
     24
     25        /**
     26         * Perform check.
     27         */
     28        wp.checkUpdates.performCheck = function() {
     29                wp.ajax.post( 'check-updates', settings ).done( function( response ) {
     30                        wp.checkUpdates.updateAdminBar( response );
     31                        wp.checkUpdates.updateDashboardMenu( response );
     32                        wp.checkUpdates.updatePluginsMenu( response );
     33                        wp.checkUpdates.updateFooter( response );
     34                });
     35        };
     36
     37        /**
     38         * Update admin bar.
     39         *
     40         * @param {object} response Response from the server.
     41         */
     42        wp.checkUpdates.updateAdminBar = function( response ) {
     43                if ( response.counts.total === wp.checkUpdates.currentCounts.total ) {
     44                        return;
     45                }
     46
     47                var $menu = $( '#wp-admin-bar-updates' );
     48
     49                $menu.find( '.ab-label' ).text( response.counts.total );
     50                $menu.removeClass( 'hide-if-no-updates' );
     51        };
     52
     53        /**
     54         * Update dashboard menu.
     55         *
     56         * @param {object} response Response from the server.
     57         */
     58        wp.checkUpdates.updateDashboardMenu = function ( response ) {
     59                if ( response.counts.total === wp.checkUpdates.currentCounts.total ) {
     60                        return;
     61                }
     62
     63                var $menu = $( '#menu-dashboard' );
     64
     65                $menu.find( '.update-count' ).text( response.counts.total );
     66                $menu.find( '.update-plugins' ).addClass( 'count-' + response.counts.total ).removeClass( 'count-' + wp.checkUpdates.currentCounts.total );
     67        };
     68
     69        /**
     70         * Update plugins menu.
     71         *
     72         * @param {object} response Response from the server.
     73         */
     74        wp.checkUpdates.updatePluginsMenu = function( response ) {
     75                if ( response.counts.plugins === wp.checkUpdates.currentCounts.plugins ) {
     76                        return;
     77                }
     78
     79                var $menu = $( '#menu-plugins' );
     80
     81                $menu.find( '.plugin-count' ).text( response.counts.plugins );
     82                $menu.find( '.update-plugins' ).addClass( 'count-' + response.counts.plugins ).removeClass( 'count-' + wp.checkUpdates.currentCounts.plugins );
     83        };
     84
     85        /**
     86         * Update footer.
     87         *
     88         * @param {object} response Response from the server.
     89         */
     90        wp.checkUpdates.updateFooter = function( response ) {
     91                if ( response.counts.wordpress === wp.checkUpdates.currentCounts.wordpress ) {
     92                        return;
     93                }
     94
     95                $( '#footer-upgrade' ).html( response.message );
     96        };
     97
     98        $( function() {
     99                // Perform update check
     100                wp.checkUpdates.performCheck();
     101        } );
     102
     103})( jQuery, window.wp, window.wpCheckUpdates );
     104 No newline at end of file
  • src/wp-includes/admin-bar.php

    diff --git src/wp-includes/admin-bar.php src/wp-includes/admin-bar.php
    index e87ac14..62efd44 100644
    function wp_admin_bar_appearance_menu( $wp_admin_bar ) { 
    807807 * @param WP_Admin_Bar $wp_admin_bar
    808808 */
    809809function wp_admin_bar_updates_menu( $wp_admin_bar ) {
    810 
    811810        $update_data = wp_get_update_data();
    812811
    813         if ( !$update_data['counts']['total'] )
    814                 return;
    815 
    816812        $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
    817813        $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
    818814
    function wp_admin_bar_updates_menu( $wp_admin_bar ) { 
    821817                'title' => $title,
    822818                'href'  => network_admin_url( 'update-core.php' ),
    823819                'meta'  => array(
     820                        'class' => $update_data['counts']['total'] ? '' : 'hide-if-no-updates',
    824821                        'title' => $update_data['title'],
    825822                ),
    826823        ) );
  • src/wp-includes/css/admin-bar.css

    diff --git src/wp-includes/css/admin-bar.css src/wp-includes/css/admin-bar.css
    index e108a8e..b134d4e 100644
    html:lang(he-il) .rtl #wpadminbar * { 
    593593        top: 2px;
    594594}
    595595
     596#wpadminbar .hide-if-no-updates {
     597        display: none;
     598}
     599
    596600/**
    597601 * Search
    598602 */
  • src/wp-includes/script-loader.php

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index e67997a..73942cc 100644
    function wp_default_scripts( &$scripts ) { 
    694694                        ),
    695695                ) );
    696696
     697                $scripts->add( 'check-updates', "/wp-admin/js/check-updates$suffix.js", array( 'jquery', 'wp-util' ), false, 1 );
     698                did_action( 'init' ) && $scripts->localize( 'check-updates', 'wpCheckUpdates', array(
     699                        'ajax_nonce' => wp_create_nonce( 'check-updates' ),
     700                        'current_updates' => wp_get_update_data(),
     701                ) );
     702
    697703                $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
    698704
    699705                $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 );
  • src/wp-includes/update.php

    diff --git src/wp-includes/update.php src/wp-includes/update.php
    index 5f074dc..0be3a4a 100644
    function wp_get_update_data() { 
    600600 * @since 2.8.0
    601601 *
    602602 * @global string $wp_version
     603 *
     604 * @return bool
    603605 */
    604606function _maybe_update_core() {
    605607        // include an unmodified $wp_version
    function _maybe_update_core() { 
    610612        if ( isset( $current->last_checked, $current->version_checked ) &&
    611613                12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
    612614                $current->version_checked == $wp_version ) {
    613                 return;
     615
     616                return false;
    614617        }
    615         wp_version_check();
     618
     619        return true;
    616620}
     621
    617622/**
    618623 * Check the last time plugins were run before checking plugin versions.
    619624 *
    function _maybe_update_core() { 
    623628 *
    624629 * @since 2.7.0
    625630 * @access private
     631 *
     632 * @return bool
    626633 */
    627634function _maybe_update_plugins() {
    628635        $current = get_site_transient( 'update_plugins' );
    629         if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
    630                 return;
    631         wp_update_plugins();
     636        if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) {
     637                return false;
     638        }
     639
     640        return true;
    632641}
    633642
    634643/**
    function _maybe_update_plugins() { 
    639648 *
    640649 * @since 2.7.0
    641650 * @access private
     651 *
     652 * @return bool
    642653 */
    643654function _maybe_update_themes() {
    644655        $current = get_site_transient( 'update_themes' );
    645         if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
     656        if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) {
     657                return false;
     658        }
     659
     660        return true;
     661}
     662
     663/**
     664 * Maybe trigger core, plugin and theme updates.
     665 */
     666function maybe_trigger_updates() {
     667        if ( ! _maybe_update_core() && ! _maybe_update_plugins() && ! _maybe_update_themes() ) {
    646668                return;
    647         wp_update_themes();
     669        }
     670
     671        wp_enqueue_script( 'check-updates' );
     672}
     673
     674/**
     675 * Maybe check core, plugin and theme updates.
     676 */
     677function ajax_check_update_apis() {
     678        check_ajax_referer( 'check-updates', 'ajax_nonce' );
     679
     680        if ( _maybe_update_core() ) {
     681                wp_version_check();
     682        }
     683
     684        if ( _maybe_update_plugins() ) {
     685                wp_update_plugins();
     686        }
     687
     688        if ( _maybe_update_themes() ) {
     689                wp_update_themes();
     690        }
     691
     692        $response = wp_get_update_data();
     693        $response['message'] = core_update_footer();
     694
     695        wp_send_json_success( $response );
    648696}
    649697
    650698/**
    function wp_clean_update_cache() { 
    678726        delete_site_transient( 'update_core' );
    679727}
    680728
     729add_action( 'wp_ajax_check-updates', 'ajax_check_update_apis' );
     730
    681731if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
    682732        return;
    683733}
    684734
    685 add_action( 'admin_init', '_maybe_update_core' );
     735add_action( 'admin_init', 'maybe_trigger_updates' );
     736
    686737add_action( 'wp_version_check', 'wp_version_check' );
    687738
    688739add_action( 'load-plugins.php', 'wp_update_plugins' );
    689740add_action( 'load-update.php', 'wp_update_plugins' );
    690741add_action( 'load-update-core.php', 'wp_update_plugins' );
    691 add_action( 'admin_init', '_maybe_update_plugins' );
    692742add_action( 'wp_update_plugins', 'wp_update_plugins' );
    693743
    694744add_action( 'load-themes.php', 'wp_update_themes' );
    695745add_action( 'load-update.php', 'wp_update_themes' );
    696746add_action( 'load-update-core.php', 'wp_update_themes' );
    697 add_action( 'admin_init', '_maybe_update_themes' );
    698747add_action( 'wp_update_themes', 'wp_update_themes' );
    699748
    700749add_action( 'update_option_WPLANG', 'wp_clean_update_cache' , 10, 0 );