Strange crasher in wp_just_in_time_script_localization(), stranger workaround
-
I upgraded a web site to 2.5 this evening, and I found a crasher that I traced back to one of the wp_head hooks ( wp_just_in_time_script_localization() , defined in wp-includes/script-loader.php ). This crasher happened on my custom template, but not the default one. This line crashes before the wp_localize_script() is entered:
wp-includes/script-loader.php (wp_just_in_time_script_localization): wp_localize_script( 'autosave', 'autosaveL10n', array( 'autosaveInterval' => AUTOSAVE_INTERVAL, 'previewPageText' => __('Preview this Page'), 'previewPostText' => __('Preview this Post'), 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 'savingText' => __('Saving Draft…') ) );
However, the strangest workaround fixed it. Changing it to this now works:
wp-includes/script-loader.php (wp_just_in_time_script_localization): $locArray = array( 'autosaveInterval' => AUTOSAVE_INTERVAL, 'previewPageText' => __('Preview this Page'), 'previewPostText' => __('Preview this Post'), 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', 'savingText' => __('Saving Draft…')); wp_localize_script( 'autosave', 'autosaveL10n', $locArray );
So defining the array in a variable first works. Defining it inline as one of the function arguments causes a 100% repeatable crash when using my template. I don’t get what the difference is. (With this one change, my template appears to be 100% compatible with 2.5.)
The one major difference I can think of between my template and the default one is that my template calls wp_head() from inside a function, while the default template calls it outside of a function. Maybe it’s an issue of variable scope?
- The topic ‘Strange crasher in wp_just_in_time_script_localization(), stranger workaround’ is closed to new replies.