WordPress.org

Make WordPress Core

Changeset 32062


Ignore:
Timestamp:
04/07/2015 03:08:38 AM (4 years ago)
Author:
jorbin
Message:

Enable users to initiate a shiny update from plugin detail modal

The plugin detail modal can contain a link to update a plugin. When it does, we should initiate a shiny update.

This relies upon postMessage which isn't available in all browsers, specifically it isn't in IE versions below 8 so this is going to be a progressive enhancement that some small percentage of users will miss out on. These are the same users that can't use the customizer.

Fixes #31739

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin-install.php

    r31990 r32062  
    562562            case 'update_available':
    563563                if ( $status['url'] ) {
    564                     echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
     564                    echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
    565565                }
    566566                break;
  • trunk/src/wp-admin/js/updates.js

    r32061 r32062  
     1/* global tb_remove */
    12window.wp = window.wp || {};
    23
     
    474475        } );
    475476
     477        //
     478        $( '#plugin_update_from_iframe' ).on( 'click' , function( e ) {
     479            var target, data;
     480
     481            target = window.parent == window ? null : window.parent,
     482            $.support.postMessage = !! window.postMessage;
     483
     484            if ( $.support.postMessage === false || target === null )
     485                return;
     486
     487            e.preventDefault();
     488
     489            data = {
     490                'action' : 'updatePlugin',
     491                'slug'   : $(this).data('slug')
     492            };
     493
     494            target.postMessage( JSON.stringify( data ), window.location.origin );
     495        });
     496
    476497    } );
    477498
     
    488509        message = $.parseJSON( event.data );
    489510
    490         if ( typeof message.action === 'undefined' || message.action !== 'decrementUpdateCount' ) {
    491             return;
    492         }
    493 
    494         wp.updates.decrementCount( message.upgradeType );
     511        if ( typeof message.action === 'undefined' ) {
     512            return;
     513        }
     514
     515        switch (message.action){
     516            case 'decrementUpdateCount' :
     517                wp.updates.decrementCount( message.upgradeType );
     518                break;
     519            case 'updatePlugin' :
     520                tb_remove();
     521                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
     522                    // Return the user to the input box of the plugin's table row after closing the modal.
     523                    $( '#' + message.slug ).find( '.check-column input' ).focus();
     524                    // trigger the update
     525                    $( '.plugin-update-tr[data-slug="' + message.slug + '"]' ).find( '.update-link' ).trigger( 'click' );
     526                } else if ( 'plugin-install' === pagenow ) {
     527                    $( '.plugin-card-' + message.slug ).find( 'h4 a' ).focus();
     528                    $( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
     529                }
     530                break;
     531        }
     532
     533
    495534
    496535    } );
Note: See TracChangeset for help on using the changeset viewer.