Make WordPress Core

Ticket #17703: 17703-05.patch

File 17703-05.patch, 8.3 KB (added by gcorne, 10 years ago)
  • src/wp-admin/includes/class-wp-upgrader-skins.php

    diff --git src/wp-admin/includes/class-wp-upgrader-skins.php src/wp-admin/includes/class-wp-upgrader-skins.php
    index 71a1293..f3183c6 100644
    class WP_Upgrader_Skin { 
    1919        var $upgrader;
    2020        var $done_header = false;
    2121        var $result = false;
     22        var $upgrade_type = false;
    2223
    2324        function __construct($args = array()) {
    2425                $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
    class WP_Upgrader_Skin { 
    9293        function before() {}
    9394        function after() {}
    9495
     96        /**
     97         * Output javascript that calls function to decrement the update counts
     98         *
     99         * @since 3.9.0
     100         */
     101        function decrement_update_count() {
     102
     103                if ( ! in_array( $this->upgrade_type, array( 'plugin', 'theme' ) ) ) {
     104                        return;
     105                }
     106
     107                echo '<script type="text/javascript">
     108                                (function( wp ) {
     109                                        if ( wp && wp.decrementUpdateCount ) {
     110                                                wp.decrementUpdateCount( "' . esc_js( $this->upgrade_type ) . '" );
     111                                        }
     112                                })( window.wp );
     113                        </script>';
     114
     115        }
     116
    95117}
    96118
    97119/**
    class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { 
    105127        var $plugin = '';
    106128        var $plugin_active = false;
    107129        var $plugin_network_active = false;
     130        var $upgrade_type = 'plugin';
    108131
    109132        function __construct($args = array()) {
    110133                $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') );
    class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { 
    252275                wp_ob_end_flush_all();
    253276                flush();
    254277        }
     278
     279        /**
     280         * Output javascript that sends message to parent window to decrement the update counts
     281         *
     282         * @since 3.9.0
     283         */
     284        function decrement_update_count() {
     285
     286                if ( ! in_array( $this->upgrade_type, array( 'plugin', 'theme' ) ) ) {
     287                        return;
     288                }
     289
     290                echo '<script type="text/javascript">
     291                                if ( window.postMessage && JSON ) {
     292                                        window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . esc_js( $this->upgrade_type ) . '" } ), window.location.protocol + "//" + window.location.hostname );
     293                                }
     294                        </script>';
     295        }
    255296}
    256297
    257298class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
    258299        var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
     300        var $upgrade_type = 'plugin';
    259301
    260302        function __construct($args = array()) {
    261303                parent::__construct($args);
    class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { 
    290332
    291333class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
    292334        var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
     335        var $upgrade_type = 'theme';
    293336
    294337        function __construct($args = array()) {
    295338                parent::__construct($args);
    class Theme_Installer_Skin extends WP_Upgrader_Skin { 
    468511 */
    469512class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
    470513        var $theme = '';
     514        var $upgrade_type = 'theme';
    471515
    472516        function __construct($args = array()) {
    473517                $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') );
  • src/wp-admin/includes/class-wp-upgrader.php

    diff --git src/wp-admin/includes/class-wp-upgrader.php src/wp-admin/includes/class-wp-upgrader.php
    index 664595a..514f281 100644
    class WP_Upgrader { 
    368368                } else {
    369369                        //Install Succeeded
    370370                        $this->skin->feedback('process_success');
     371                        $this->skin->decrement_update_count();
    371372                }
    372373
    373374                $this->skin->after();
  • new file src/wp-admin/js/updates.js

    diff --git src/wp-admin/js/updates.js src/wp-admin/js/updates.js
    new file mode 100644
    index 0000000..20c5278
    - +  
     1window.wp = window.wp || {};
     2
     3(function( $, wp ) {
     4
     5        /**
     6         * Decrement update counts throughout the various menus
     7         *
     8         * @param {string} updateType
     9         */
     10        wp.decrementUpdateCount = function( upgradeType ) {
     11                var count, pluginCount, $elem;
     12
     13                $elem = $( '#wp-admin-bar-updates .ab-label');
     14                count = $elem.text();
     15                count = parseInt( count, 10 ) - 1;
     16                $elem.text( count );
     17
     18                $elem = $('a[href="update-core.php"] .update-plugins');
     19                $elem.each( function( index, elem ) {
     20                        elem.className = elem.className.replace( /count-\d+/, 'count-' + count );
     21                } );
     22                $elem.find( '.update-count' ).text( count );
     23
     24                if ( 'plugin' === upgradeType ) {
     25                        $elem = $( '#menu-plugins' );
     26                        pluginCount = $elem.find( '.plugin-count' ).eq(0).text();
     27                        pluginCount = parseInt( pluginCount, 10 ) - 1;
     28                        $elem.find( '.plugin-count' ).text( pluginCount );
     29                        $elem.find( '.update-plugins' ).each( function( index, elem ) {
     30                                elem.className = elem.className.replace( /count-\d+/, 'count-' + pluginCount );
     31                        } );
     32                }
     33        };
     34
     35        $( window ).on( 'message', function( e ) {
     36                var event = e.originalEvent,
     37                        message,
     38                        loc = document.location,
     39                        expectedOrigin = loc.protocol + '//' + loc.hostname;
     40
     41                if ( event.origin !== expectedOrigin ) {
     42                        return;
     43                }
     44
     45                message = $.parseJSON( event.data );
     46
     47                if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) {
     48                        return;
     49                }
     50
     51                wp.decrementUpdateCount( message.upgradeType );
     52
     53        } );
     54
     55})( jQuery, window.wp );
  • src/wp-admin/plugins.php

    diff --git src/wp-admin/plugins.php src/wp-admin/plugins.php
    index 61efcf5..8b1e4a0 100644
    if ( $action ) { 
    113113                        $title = __( 'Update Plugins' );
    114114                        $parent_file = 'plugins.php';
    115115
     116                        wp_enqueue_script('updates');
    116117                        require_once(ABSPATH . 'wp-admin/admin-header.php');
    117118
    118119                        echo '<div class="wrap">';
  • src/wp-admin/update-core.php

    diff --git src/wp-admin/update-core.php src/wp-admin/update-core.php
    index 5b84ec4..aa2d19b 100644
    require_once( dirname( __FILE__ ) . '/admin.php' ); 
    1111
    1212wp_enqueue_style( 'plugin-install' );
    1313wp_enqueue_script( 'plugin-install' );
     14wp_enqueue_script( 'updates' );
    1415add_thickbox();
    1516
    1617if ( is_multisite() && ! is_network_admin() ) {
  • src/wp-admin/update.php

    diff --git src/wp-admin/update.php src/wp-admin/update.php
    index e70d9c2..551da8e 100644
    if ( isset($_GET['action']) ) { 
    3737                $url = 'update.php?action=update-selected&amp;plugins=' . urlencode(implode(',', $plugins));
    3838                $nonce = 'bulk-update-plugins';
    3939
    40                 wp_enqueue_script('jquery');
     40                wp_enqueue_script('updates');
    4141                iframe_header();
    4242
    4343                $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
    if ( isset($_GET['action']) ) { 
    5454                $title = __('Update Plugin');
    5555                $parent_file = 'plugins.php';
    5656                $submenu_file = 'plugins.php';
     57
     58                wp_enqueue_script('updates');
    5759                require_once(ABSPATH . 'wp-admin/admin-header.php');
    5860
    5961                $nonce = 'upgrade-plugin_' . $plugin;
    if ( isset($_GET['action']) ) { 
    154156                check_admin_referer('upgrade-theme_' . $theme);
    155157
    156158                wp_enqueue_script( 'customize-loader' );
     159                wp_enqueue_script( 'updates' );
    157160
    158161                $title = __('Update Theme');
    159162                $parent_file = 'themes.php';
    if ( isset($_GET['action']) ) { 
    185188                $url = 'update.php?action=update-selected-themes&amp;themes=' . urlencode(implode(',', $themes));
    186189                $nonce = 'bulk-update-themes';
    187190
    188                 wp_enqueue_script('jquery');
     191                wp_enqueue_script('updates');
    189192                iframe_header();
    190193
    191194                $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
  • src/wp-includes/admin-bar.php

    diff --git src/wp-includes/admin-bar.php src/wp-includes/admin-bar.php
    index 67e6a1a..3f68673 100644
    function wp_admin_bar_updates_menu( $wp_admin_bar ) { 
    693693        $wp_admin_bar->add_menu( array(
    694694                'id'    => 'updates',
    695695                'title' => $title,
    696                 'href'  => network_admin_url( 'update-core.php' ),
    697                 'meta'  => array(
    698                         'title' => $update_data['title'],
    699                 ),
     696                'href'  => network_admin_url( 'update-core.php' )
    700697        ) );
    701698}
    702699
  • src/wp-includes/script-loader.php

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index 6414760..649f95b 100644
    function wp_default_scripts( &$scripts ) { 
    477477                        'ays' => __('Are you sure you want to install this plugin?')
    478478                ) );
    479479
     480                $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery' ) );
     481
    480482                $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
    481483
    482484                $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );