Make WordPress Core

Changeset 21134


Ignore:
Timestamp:
06/26/2012 06:28:59 AM (14 years ago)
Author:
nacin
Message:

If a plugin triggers the WP_Scripts constructor prior to init, fire wp_default_scripts()
then and again on init.

Only add our localized strings once we've fired init, in case we do have the situation
where we fire wp_default_scripts() twice.

Fixes issues where plugins or themes try to enqueue a default script handle prior to
init. Does not allow #19959 to regress.

fixes #20971 for 3.4.

Location:
branches/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.4/wp-admin/load-scripts.php

    r19684 r21134  
    5151 */
    5252function add_action() {}
     53
     54/**
     55 * @ignore
     56 */
     57function did_action() {}
    5358
    5459/**
  • branches/3.4/wp-includes/class.wp-scripts.php

    r20000 r21134  
    3232
    3333        function __construct() {
    34                 if ( ! function_exists( 'did_action' ) || did_action( 'init' ) )
    35                         $this->init();
    36                 else
    37                         add_action( 'init', array( $this, 'init' ), 0 );
     34                $this->init();
     35                add_action( 'init', array( $this, 'init' ), 0 );
    3836        }
    3937
  • branches/3.4/wp-includes/script-loader.php

    r21031 r21134  
    6363
    6464        $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 );
    65         $scripts->localize( 'common', 'commonL10n', array(
     65        did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array(
    6666                'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete.")
    6767        ) );
     
    7070
    7171        $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
    72         $scripts->localize( 'quicktags', 'quicktagsL10n', array(
     72        did_action( 'init' ) && $scripts->localize( 'quicktags', 'quicktagsL10n', array(
    7373                'wordLookup' => __('Enter a word to look up:'),
    7474                'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
     
    9494
    9595        $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), false, 1 );
    96         $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
     96        did_action( 'init' ) && $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
    9797                'noPerm' => __('You do not have permission to do that.'),
    9898                'broken' => __('An unidentified error has occurred.')
     
    100100
    101101        $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20111129a', 1 );
    102         $scripts->localize( 'wp-pointer', 'wpPointerL10n', array(
     102        did_action( 'init' ) && $scripts->localize( 'wp-pointer', 'wpPointerL10n', array(
    103103                'dismiss' => __('Dismiss'),
    104104        ) );
     
    171171
    172172        $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20111117', 1 );
    173         $scripts->localize( 'thickbox', 'thickboxL10n', array(
     173        did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array(
    174174                        'next' => __('Next >'),
    175175                        'prev' => __('< Prev'),
     
    228228
    229229        $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array('plupload-all', 'jquery') );
    230         $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
     230        did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
    231231
    232232        $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array('plupload-all', 'jquery', 'json2') );
    233         $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
     233        did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
    234234
    235235        // keep 'swfupload' for back-compat.
     
    247247
    248248        $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
    249         $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
     249        did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
    250250
    251251        $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js" );
     
    256256
    257257        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
    258         $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
     258        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    259259                'empty' => __('Strength indicator'),
    260260                'short' => __('Very weak'),
     
    273273
    274274        $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), false, 1 );
    275         $scripts->localize( 'wplink', 'wpLinkL10n', array(
     275        did_action( 'init' ) && $scripts->localize( 'wplink', 'wpLinkL10n', array(
    276276                'title' => __('Insert/edit link'),
    277277                'update' => __('Update'),
     
    286286
    287287        $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), false, 1 );
    288         $scripts->localize( 'word-count', 'wordCountL10n', array(
     288        did_action( 'init' ) && $scripts->localize( 'word-count', 'wordCountL10n', array(
    289289                /* translators: If your word count is based on single characters (East Asian characters),
    290290                   enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
     
    300300        $scripts->add( 'customize-preview',  "/wp-includes/js/customize-preview$suffix.js",  array( 'customize-base' ), false, 1 );
    301301        $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base' ), false, 1 );
    302         $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
     302        did_action( 'init' ) && $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
    303303                'activate'  => __( 'Save & Activate' ),
    304304                'save'      => __( 'Save & Publish' ),
     
    312312                $scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ) );
    313313                $scripts->add_data( 'ajaxcat', 'group', 1 );
    314                 $scripts->localize( 'ajaxcat', 'catL10n', array(
     314                did_action( 'init' ) && $scripts->localize( 'ajaxcat', 'catL10n', array(
    315315                        'add' => esc_attr(__('Add')),
    316316                        'how' => __('Separate multiple categories with commas.')
     
    320320
    321321                $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('jquery', 'wp-ajax-response'), false, 1 );
    322                 $scripts->localize( 'admin-tags', 'tagsl10n', array(
     322                did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array(
    323323                        'noPerm' => __('You do not have permission to do that.'),
    324324                        'broken' => __('An unidentified error has occurred.')
     
    328328
    329329                $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'quicktags', 'jquery-query'), false, 1 );
    330                 $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
     330                did_action( 'init' ) && $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
    331331                        'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
    332332                        'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
     
    340340
    341341                $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 );
    342                 $scripts->localize( 'post', 'postL10n', array(
     342                did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
    343343                        'ok' => __('OK'),
    344344                        'cancel' => __('Cancel'),
     
    366366                $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery') );
    367367                $scripts->add_data( 'comment', 'group', 1 );
    368                 $scripts->localize( 'comment', 'commentL10n', array(
     368                did_action( 'init' ) && $scripts->localize( 'comment', 'commentL10n', array(
    369369                        'submittedOn' => __('Submitted on:')
    370370                ) );
     
    380380
    381381                $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
    382                 $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
     382                did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
    383383                        'error' => __('Error while saving the changes.'),
    384384                        'ntdeltitle' => __('Remove From Bulk Edit'),
     
    388388
    389389                $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery' ), false, 1 );
    390                 $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
     390                did_action( 'init' ) && $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
    391391                        'error' => __('Error while saving the changes.')
    392392                ) );
    393393
    394394                $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'thickbox' ), false, 1 );
    395                 $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
     395                did_action( 'init' ) && $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
    396396                        'plugin_information' => __('Plugin Information:'),
    397397                        'ays' => __('Are you sure you want to install this plugin?')
     
    407407
    408408                $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), false, 1 );
    409                 $scripts->localize( 'image-edit', 'imageEditL10n', array(
     409                did_action( 'init' ) && $scripts->localize( 'image-edit', 'imageEditL10n', array(
    410410                        'error' => __( 'Could not load the preview image. Please reload the page and try again.' )
    411411                ));
    412412
    413413                $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
    414                 $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
     414                did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
    415415                        'setThumbnail' => __( 'Use as featured image' ),
    416416                        'saving' => __( 'Saving...' ),
     
    421421                // Navigation Menus
    422422                $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array('jquery-ui-sortable') );
    423                 $scripts->localize( 'nav-menu', 'navMenuL10n', array(
     423                did_action( 'init' ) && $scripts->localize( 'nav-menu', 'navMenuL10n', array(
    424424                        'noResultsFound' => _x('No results found.', 'search results'),
    425425                        'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
Note: See TracChangeset for help on using the changeset viewer.