Make WordPress Core


Ignore:
Timestamp:
02/26/2014 06:54:26 AM (11 years ago)
Author:
nacin
Message:

Decrement update count bubbles as plugins/themes are updated, live.

props gcorne, mitchoyoshitaka.
fixes #17703.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader-skins.php

    r26518 r27280  
    9393    function after() {}
    9494
     95    /**
     96     * Output JavaScript that calls function to decrement the update counts.
     97     *
     98     * @since 3.9.0
     99     */
     100    protected function decrement_update_count( $type ) {
     101        if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
     102            return;
     103        }
     104        echo '<script type="text/javascript">
     105                (function( wp ) {
     106                    if ( wp && wp.updates.decrementCount ) {
     107                        wp.updates.decrementCount( "' . $type . '" );
     108                    }
     109                })( window.wp );
     110            </script>';
     111    }
    95112}
    96113
     
    124141            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>';
    125142        }
     143
     144        $this->decrement_update_count( 'plugin' );
    126145
    127146        $update_actions =  array(
     
    253272        flush();
    254273    }
     274
     275    /**
     276     * Output JavaScript that sends message to parent window to decrement the update counts.
     277     *
     278     * @since 3.9.0
     279     */
     280    protected function decrement_update_count( $type ) {
     281        if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
     282            return;
     283        }
     284        echo '<script type="text/javascript">
     285                if ( window.postMessage && JSON ) {
     286                    window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname );
     287                }
     288            </script>';
     289    }
    255290}
    256291
     
    273308    function after($title = '') {
    274309        parent::after($this->plugin_info['Title']);
     310        $this->decrement_update_count( 'plugin' );
    275311    }
    276312    function bulk_footer() {
     
    307343    function after($title = '') {
    308344        parent::after( $this->theme_info->display('Name') );
     345        $this->decrement_update_count( 'theme' );
    309346    }
    310347
     
    480517
    481518    function after() {
     519        $this->decrement_update_count( 'theme' );
    482520
    483521        $update_actions = array();
     
    562600
    563601    function bulk_footer() {
     602        $this->decrement_update_count( 'translation' );
    564603        $update_actions = array();
    565604        $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>';
Note: See TracChangeset for help on using the changeset viewer.