Make WordPress Core

Changeset 36221


Ignore:
Timestamp:
01/08/2016 05:47:18 PM (11 years ago)
Author:
obenland
Message:

Plugins: Use plugin file rather than slug as identifier

The plugin file is unique while there can be more than one plugin with the
same slug. This also allows us to simplify the way updates from the plugin
detail iframe are executed.

See [36205].
Fixes #35350.

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

Legend:

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

    r36092 r36221  
    652652                        case 'update_available':
    653653                                if ( $status['url'] ) {
    654                                         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>';
     654                                        echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) .'</a>';
    655655                                }
    656656                                break;
  • trunk/src/wp-admin/js/updates.js

    r35681 r36221  
    151151
    152152                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    153                         $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
     153                        $message = $( '[data-plugin="' + plugin + '"]' ).next().find( '.update-message' );
    154154                } else if ( 'plugin-install' === pagenow ) {
    155155                        $message = $card.find( '.update-now' );
    … …  
    208208                var $updateMessage, name, $pluginRow, newText;
    209209                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    210                         $pluginRow = $( '[data-slug="' + response.slug + '"]' ).first();
     210                        $pluginRow = $( '[data-plugin="' + response.plugin + '"]' ).first();
    211211                        $updateMessage = $pluginRow.next().find( '.update-message' );
    212212                        $pluginRow.addClass( 'updated' ).removeClass( 'update' );
    … …  
    269269
    270270                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    271                         $message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' );
     271                        $message = $( '[data-plugin="' + response.plugin + '"]' ).next().find( '.update-message' );
    272272                        $message.html( error_message ).removeClass( 'updating-message' );
    273273                } else if ( 'plugin-install' === pagenow ) {
    … …  
    432432        wp.updates.requestForCredentialsModalCancel = function() {
    433433                // no updateLock and no updateQueue means we already have cleared things up
    434                 var slug, $message;
     434                var data, $message;
    435435
    436436                if( wp.updates.updateLock === false && wp.updates.updateQueue.length === 0 ){
    … …  
    438438                }
    439439
    440                 slug = wp.updates.updateQueue[0].data.slug,
     440                data = wp.updates.updateQueue[0].data;
    441441
    442442                // remove the lock, and clear the queue
    … …  
    446446                wp.updates.requestForCredentialsModalClose();
    447447                if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    448                         $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
     448                        $message = $( '[data-plugin="' + data.plugin + '"]' ).next().find( '.update-message' );
    449449                } else if ( 'plugin-install' === pagenow ) {
    450                         $message = $( '.plugin-card-' + slug ).find( '.update-now' );
     450                        $message = $( '.plugin-card-' + data.slug ).find( '.update-now' );
    451451                }
    452452
    … …  
    517517                        var updateRow = $( e.target ).parents( '.plugin-update-tr' );
    518518                        // Return the user to the input box of the plugin's table row after closing the modal.
    519                         wp.updates.$elToReturnFocusToFromCredentialsModal = $( '#' + updateRow.data( 'slug' ) ).find( '.check-column input' );
     519                        wp.updates.$elToReturnFocusToFromCredentialsModal = updateRow.prev().find( '.check-column input' );
    520520                        wp.updates.updatePlugin( updateRow.data( 'plugin' ), updateRow.data( 'slug' ) );
    521521                } );
    … …  
    533533
    534534                $( '#plugin_update_from_iframe' ).on( 'click' , function( e ) {
    535                         var target,     data;
     535                        var target, job;
    536536
    537537                        target = window.parent == window ? null : window.parent,
    … …  
    543543                        e.preventDefault();
    544544
    545                         data = {
    546                                 'action' : 'updatePlugin',
    547                                 'slug'   : $(this).data('slug')
     545                        job = {
     546                                action: 'updatePlugin',
     547                                type: 'update-plugin',
     548                                data: {
     549                                        plugin: $( this ).data( 'plugin' ),
     550                                        slug: $( this ).data( 'slug' )
     551                                }
    548552                        };
    549553
    550                         target.postMessage( JSON.stringify( data ), window.location.origin );
     554                        target.postMessage( JSON.stringify( job ), window.location.origin );
    551555                });
    552556
    … …  
    575579                        case 'updatePlugin' :
    576580                                tb_remove();
    577                                 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
    578                                         // Return the user to the input box of the plugin's table row after closing the modal.
    579                                         $( '#' + message.slug ).find( '.check-column input' ).focus();
    580                                         // trigger the update
    581                                         $( '.plugin-update-tr[data-slug="' + message.slug + '"]' ).find( '.update-link' ).trigger( 'click' );
    582                                 } else if ( 'plugin-install' === pagenow ) {
    583                                         $( '.plugin-card-' + message.slug ).find( '.column-name a' ).focus();
    584                                         $( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
    585                                 }
     581
     582                                wp.updates.updateQueue.push( message );
     583                                wp.updates.queueChecker();
    586584                                break;
    587585                }
Note: See TracChangeset for help on using the changeset viewer.