Permalink
Browse files

If a plugin triggers the WP_Scripts constructor prior to init, fire w…

…p_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.



git-svn-id: http://core.svn.wordpress.org/branches/3.4@21134 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent 7508d49 commit 52a69faf1815ea66081a4b8f1029b52271fdcf00 nacin committed Jun 26, 2012
Showing with 30 additions and 27 deletions.
  1. +5 −0 wp-admin/load-scripts.php
  2. +2 −4 wp-includes/class.wp-scripts.php
  3. +23 −23 wp-includes/script-loader.php
View
5 wp-admin/load-scripts.php
@@ -54,6 +54,11 @@ function add_action() {}
/**
* @ignore
*/
+function did_action() {}
+
+/**
+ * @ignore
+ */
function do_action_ref_array() {}
/**
View
6 wp-includes/class.wp-scripts.php
@@ -31,10 +31,8 @@ class WP_Scripts extends WP_Dependencies {
var $default_dirs;
function __construct() {
- if ( ! function_exists( 'did_action' ) || did_action( 'init' ) )
- $this->init();
- else
- add_action( 'init', array( $this, 'init' ), 0 );
+ $this->init();
+ add_action( 'init', array( $this, 'init' ), 0 );
}
function init() {
View
46 wp-includes/script-loader.php
@@ -62,14 +62,14 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'utils', "/wp-admin/js/utils$suffix.js" );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 );
- $scripts->localize( 'common', 'commonL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array(
'warnDelete' => __("You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete.")
) );
$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
$scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
- $scripts->localize( 'quicktags', 'quicktagsL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'quicktags', 'quicktagsL10n', array(
'wordLookup' => __('Enter a word to look up:'),
'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
'lookup' => esc_attr(__('lookup')),
@@ -93,13 +93,13 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'prototype', '/wp-includes/js/prototype.js', array(), '1.6.1');
$scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), false, 1 );
- $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
+ did_action( 'init' ) && $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
'noPerm' => __('You do not have permission to do that.'),
'broken' => __('An unidentified error has occurred.')
) );
$scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20111129a', 1 );
- $scripts->localize( 'wp-pointer', 'wpPointerL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'wp-pointer', 'wpPointerL10n', array(
'dismiss' => __('Dismiss'),
) );
@@ -170,7 +170,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
$scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20111117', 1 );
- $scripts->localize( 'thickbox', 'thickboxL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array(
'next' => __('Next >'),
'prev' => __('< Prev'),
'image' => __('Image'),
@@ -227,10 +227,10 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'plupload-all', false, array('plupload', 'plupload-html5', 'plupload-flash', 'plupload-silverlight', 'plupload-html4'), '1.5.4' );
$scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array('plupload-all', 'jquery') );
- $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
+ did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
$scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array('plupload-all', 'jquery', 'json2') );
- $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
+ did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
// keep 'swfupload' for back-compat.
$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113');
@@ -246,7 +246,7 @@ function wp_default_scripts( &$scripts ) {
}
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
- $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
+ did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
$scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js" );
@@ -255,7 +255,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
- $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
'empty' => __('Strength indicator'),
'short' => __('Very weak'),
'bad' => __('Weak'),
@@ -272,7 +272,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
$scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), false, 1 );
- $scripts->localize( 'wplink', 'wpLinkL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'wplink', 'wpLinkL10n', array(
'title' => __('Insert/edit link'),
'update' => __('Update'),
'save' => __('Add Link'),
@@ -285,7 +285,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'wpdialogs-popup', "/wp-includes/js/tinymce/plugins/wpdialogs/js/popup$suffix.js", array( 'wpdialogs' ), false, 1 );
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), false, 1 );
- $scripts->localize( 'word-count', 'wordCountL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'word-count', 'wordCountL10n', array(
/* translators: If your word count is based on single characters (East Asian characters),
enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
'type' => 'characters' == _x( 'words', 'word count: words or characters?' ) ? 'c' : 'w',
@@ -299,7 +299,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'customize-base' ), false, 1 );
$scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base' ), false, 1 );
- $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
'activate' => __( 'Save & Activate' ),
'save' => __( 'Save & Publish' ),
'saved' => __( 'Saved' ),
@@ -311,23 +311,23 @@ function wp_default_scripts( &$scripts ) {
if ( is_admin() ) {
$scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ) );
$scripts->add_data( 'ajaxcat', 'group', 1 );
- $scripts->localize( 'ajaxcat', 'catL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'ajaxcat', 'catL10n', array(
'add' => esc_attr(__('Add')),
'how' => __('Separate multiple categories with commas.')
) );
$scripts->add( 'admin-categories', "/wp-admin/js/categories$suffix.js", array('wp-lists'), false, 1 );
$scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('jquery', 'wp-ajax-response'), false, 1 );
- $scripts->localize( 'admin-tags', 'tagsl10n', array(
+ did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array(
'noPerm' => __('You do not have permission to do that.'),
'broken' => __('An unidentified error has occurred.')
));
$scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), false, 1 );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'quicktags', 'jquery-query'), false, 1 );
- $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
'replyApprove' => __( 'Approve and Reply' ),
@@ -339,7 +339,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 );
- $scripts->localize( 'post', 'postL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
'ok' => __('OK'),
'cancel' => __('Cancel'),
'publishOn' => __('Publish on:'),
@@ -365,7 +365,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery') );
$scripts->add_data( 'comment', 'group', 1 );
- $scripts->localize( 'comment', 'commentL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'comment', 'commentL10n', array(
'submittedOn' => __('Submitted on:')
) );
@@ -379,20 +379,20 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 );
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
- $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.'),
'ntdeltitle' => __('Remove From Bulk Edit'),
'notitle' => __('(no title)'),
'comma' => _x( ',', 'tag delimiter' ),
) );
$scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery' ), false, 1 );
- $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
'error' => __('Error while saving the changes.')
) );
$scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'thickbox' ), false, 1 );
- $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
'plugin_information' => __('Plugin Information:'),
'ays' => __('Are you sure you want to install this plugin?')
) );
@@ -406,12 +406,12 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery-ui-draggable' ), false, 1 );
$scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array('jquery', 'json2', 'imgareaselect'), false, 1 );
- $scripts->localize( 'image-edit', 'imageEditL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'image-edit', 'imageEditL10n', array(
'error' => __( 'Could not load the preview image. Please reload the page and try again.' )
));
$scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
- $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
'setThumbnail' => __( 'Use as featured image' ),
'saving' => __( 'Saving...' ),
'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ),
@@ -420,7 +420,7 @@ function wp_default_scripts( &$scripts ) {
// Navigation Menus
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array('jquery-ui-sortable') );
- $scripts->localize( 'nav-menu', 'navMenuL10n', array(
+ did_action( 'init' ) && $scripts->localize( 'nav-menu', 'navMenuL10n', array(
'noResultsFound' => _x('No results found.', 'search results'),
'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
'saveAlert' => __('The changes you made will be lost if you navigate away from this page.')

0 comments on commit 52a69fa

Please sign in to comment.