WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/25/2011 12:36:06 AM (8 years ago)
Author:
azaozz
Message:

Use json_encode() for adding script data (formerly l10n). Add the same functionality to WP_Styles for adding inline css after a stylesheet has been outputted. See #11520

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/script-loader.php

    r18453 r18464  
    5959    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
    6060
    61     // Always ensure that we have the convertEntities function
    62     $scripts->add( 'l10n', "/wp-includes/js/l10n$suffix.js", false, '20101110' );
    63     $scripts->enqueue( 'l10n' );
    64 
    6561    $scripts->add( 'utils', "/wp-admin/js/utils$suffix.js", false, '20101110' );
    6662
    6763    $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), '20110711' );
    6864    $scripts->add_data( 'common', 'group', 1 );
    69     $scripts->localize( 'common', 'commonL10n', array(
    70         'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete."),
    71         'l10n_print_after' => 'try{convertEntities(commonL10n);}catch(e){};'
     65    $scripts->add_script_data( 'common', 'commonL10n', array(
     66        'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete.")
    7267    ) );
    7368
     
    7772    $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110502' );
    7873    $scripts->add_data( 'quicktags', 'group', 1 );
    79     $scripts->localize( 'quicktags', 'quicktagsL10n', array(
     74    $scripts->add_script_data( 'quicktags', 'quicktagsL10n', array(
    8075        'quickLinks' => __('(Quick Links)'),
    8176        'wordLookup' => __('Enter a word to look up:'),
     
    8883        'enterImageDescription' => __('Enter a description of the image'),
    8984        'fullscreen' => __('fullscreen'),
    90         'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ),
    91         'l10n_print_after' => 'try{convertEntities(quicktagsL10n);}catch(e){};'
     85        'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') )
    9286    ) );
    9387
     
    10498    $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), '20091119' );
    10599    $scripts->add_data( 'wp-ajax-response', 'group', 1 );
    106     $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
     100    $scripts->add_script_data( 'wp-ajax-response', 'wpAjax', array(
    107101        'noPerm' => __('You do not have permission to do that.'),
    108         'broken' => __('An unidentified error has occurred.'),
    109         'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};'
     102        'broken' => __('An unidentified error has occurred.')
    110103    ) );
    111104
     
    193186    $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20110528');
    194187    $scripts->add_data( 'thickbox', 'group', 1 );
    195     $scripts->localize( 'thickbox', 'thickboxL10n', array(
     188    $scripts->add_script_data( 'thickbox', 'thickboxL10n', array(
    196189            'next' => __('Next >'),
    197190            'prev' => __('< Prev'),
     
    201194            'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
    202195            'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'),
    203             'closeImage' => includes_url('js/thickbox/tb-close.png'),
    204             'l10n_print_after' => 'try{convertEntities(thickboxL10n);}catch(e){};'
     196            'closeImage' => includes_url('js/thickbox/tb-close.png')
    205197    ) );
    206198
     
    226218        $max_upload_size = __('not configured');
    227219    // these error messages came from the sample swfupload js, they might need changing.
    228     $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', array(
     220    $scripts->add_script_data( 'swfupload-handlers', 'swfuploadL10n', array(
    229221            'queue_limit_exceeded' => __('You have attempted to queue too many files.'),
    230222            'file_exceeds_size_limit' => __('This file exceeds the maximum upload size for this site.'),
     
    243235            'crunching' => __('Crunching…'),
    244236            'deleted' => __('moved to the trash.'),
    245             'error_uploading' => __('“%s” has failed to upload due to an error'),
    246             'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};',
     237            'error_uploading' => __('“%s” has failed to upload due to an error')
    247238    ) );
    248239
     
    256247    $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), '20101027' );
    257248    $scripts->add_data( 'password-strength-meter', 'group', 1 );
    258     $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
     249    $scripts->add_script_data( 'password-strength-meter', 'pwsL10n', array(
    259250        'empty' => __('Strength indicator'),
    260251        'short' => __('Very weak'),
     
    263254        'good' => _x('Medium', 'password strength'),
    264255        'strong' => __('Strong'),
    265         'mismatch' => __('Mismatch'),
    266         'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};'
     256        'mismatch' => __('Mismatch')
    267257    ) );
    268258
     
    275265    $scripts->add( 'wplink', "/wp-includes/js/tinymce/plugins/wplink/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), '20110528' );
    276266    $scripts->add_data( 'wplink', 'group', 1 );
    277     $scripts->localize( 'wplink', 'wpLinkL10n', array(
     267    $scripts->add_script_data( 'wplink', 'wpLinkL10n', array(
    278268        'title' => __('Insert/edit link'),
    279269        'update' => __('Update'),
    280270        'save' => __('Add Link'),
    281271        'noTitle' => __('(no title)'),
    282         'noMatchesFound' => __('No matches found.'),
    283         'l10n_print_after' => 'try{convertEntities(wpLinkL10n);}catch(e){};',
     272        'noMatchesFound' => __('No matches found.')
    284273    ) );
    285274
     
    293282        $scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ), '20090102' );
    294283        $scripts->add_data( 'ajaxcat', 'group', 1 );
    295         $scripts->localize( 'ajaxcat', 'catL10n', array(
     284        $scripts->add_script_data( 'ajaxcat', 'catL10n', array(
    296285            'add' => esc_attr(__('Add')),
    297             'how' => __('Separate multiple categories with commas.'),
    298             'l10n_print_after' => 'try{convertEntities(catL10n);}catch(e){};'
     286            'how' => __('Separate multiple categories with commas.')
    299287        ) );
    300288
     
    304292        $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('jquery', 'wp-ajax-response'), '20110429' );
    305293        $scripts->add_data( 'admin-tags', 'group', 1 );
    306         $scripts->localize( 'admin-tags', 'tagsl10n', array(
     294        $scripts->add_script_data( 'admin-tags', 'tagsl10n', array(
    307295            'noPerm' => __('You do not have permission to do that.'),
    308             'broken' => __('An unidentified error has occurred.'),
    309             'l10n_print_after' => 'try{convertEntities(tagsl10n);}catch(e){};'
     296            'broken' => __('An unidentified error has occurred.')
    310297        ));
    311298
     
    315302        $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110602' );
    316303        $scripts->add_data( 'admin-comments', 'group', 1 );
    317         $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
     304        $scripts->add_script_data( 'admin-comments', 'adminCommentsL10n', array(
    318305            'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
    319306            'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
     
    330317        $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20110524' );
    331318        $scripts->add_data( 'post', 'group', 1 );
    332         $scripts->localize( 'post', 'postL10n', array(
     319        $scripts->add_script_data( 'post', 'postL10n', array(
    333320            'tagsUsed' =>  __('Tags used on this post:'),
    334321            'add' => esc_attr(__('Add')),
     
    353340            'password' => __('Password Protected'),
    354341            'privatelyPublished' => __('Privately Published'),
    355             'published' => __('Published'),
    356             'l10n_print_after' => 'try{convertEntities(postL10n);}catch(e){};'
     342            'published' => __('Published')
    357343        ) );
    358344
     
    362348        $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery'), '20110429' );
    363349        $scripts->add_data( 'comment', 'group', 1 );
    364         $scripts->localize( 'comment', 'commentL10n', array(
     350        $scripts->add_script_data( 'comment', 'commentL10n', array(
    365351            'cancel' => __('Cancel'),
    366352            'edit' => __('Edit'),
    367             'submittedOn' => __('Submitted on:'),
    368             'l10n_print_after' => 'try{convertEntities(commentL10n);}catch(e){};'
     353            'submittedOn' => __('Submitted on:')
    369354        ) );
    370355
     
    388373        $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), '20110609' );
    389374        $scripts->add_data( 'inline-edit-post', 'group', 1 );
    390         $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
     375        $scripts->add_script_data( 'inline-edit-post', 'inlineEditL10n', array(
    391376            'error' => __('Error while saving the changes.'),
    392377            'ntdeltitle' => __('Remove From Bulk Edit'),
    393             'notitle' => __('(no title)'),
    394             'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
     378            'notitle' => __('(no title)')
    395379        ) );
    396380
    397381        $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery' ), '20110609' );
    398382        $scripts->add_data( 'inline-edit-tax', 'group', 1 );
    399         $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
    400             'error' => __('Error while saving the changes.'),
    401             'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
     383        $scripts->add_script_data( 'inline-edit-tax', 'inlineEditL10n', array(
     384            'error' => __('Error while saving the changes.')
    402385        ) );
    403386
    404387        $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'thickbox' ), '20110113' );
    405388        $scripts->add_data( 'plugin-install', 'group', 1 );
    406         $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
     389        $scripts->add_script_data( 'plugin-install', 'plugininstallL10n', array(
    407390            'plugin_information' => __('Plugin Information:'),
    408             'ays' => __('Are you sure you want to install this plugin?'),
    409             'l10n_print_after' => 'try{convertEntities(plugininstallL10n);}catch(e){};'
     391            'ays' => __('Are you sure you want to install this plugin?')
    410392        ) );
    411393
     
    428410        $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), '20100518' );
    429411        $scripts->add_data( 'set-post-thumbnail', 'group', 1 );
    430         $scripts->localize( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
     412        $scripts->add_script_data( 'set-post-thumbnail', 'setPostThumbnailL10n', array(
    431413            'setThumbnail' => __( 'Use as featured image' ),
    432414            'saving' => __( 'Saving...' ),
    433415            'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ),
    434             'done' => __( 'Done' ),
    435             'l10n_print_after' => 'try{convertEntities(setPostThumbnailL10n);}catch(e){};'
     416            'done' => __( 'Done' )
    436417        ) );
    437418
    438419        // Navigation Menus
    439420        $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array('jquery-ui-sortable'), '20110524' );
    440         $scripts->localize( 'nav-menu', 'navMenuL10n', array(
     421        $scripts->add_script_data( 'nav-menu', 'navMenuL10n', array(
    441422            'noResultsFound' => _x('No results found.', 'search results'),
    442423            'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
    443             'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
    444             'l10n_print_after' => 'try{convertEntities(navMenuL10n);}catch(e){};'
     424            'saveAlert' => __('The changes you made will be lost if you navigate away from this page.')
    445425        ) );
    446426
     
    475455    $styles->default_version = get_bloginfo( 'version' );
    476456    $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
    477     $styles->default_dirs = array('/wp-admin/', '/wp-includes/');
     457    $styles->default_dirs = array('/wp-admin/', '/wp-includes/css/');
    478458
    479459    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
     
    559539function wp_just_in_time_script_localization() {
    560540
    561     wp_localize_script( 'autosave', 'autosaveL10n', array(
     541    wp_add_script_data( 'autosave', 'autosaveL10n', array(
    562542        'autosaveInterval' => AUTOSAVE_INTERVAL,
    563543        'savingText' => __('Saving Draft…'),
    564         'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
    565         'l10n_print_after' => 'try{convertEntities(autosaveL10n);}catch(e){};'
     544        'saveAlert' => __('The changes you made will be lost if you navigate away from this page.')
    566545    ) );
    567546
     
    636615
    637616    script_concat_settings();
    638     $wp_scripts->do_items( 'l10n' );
    639617    $wp_scripts->do_concat = $concatenate_scripts;
    640618    $wp_scripts->do_head_items();
     
    648626
    649627/**
    650  * Prints the scripts that were queued for the footer on admin pages.
     628 * Prints the scripts that were queued for the footer or too late for the HTML head.
    651629 *
    652630 * @since 2.8
     
    654632function print_footer_scripts() {
    655633    global $wp_scripts, $concatenate_scripts;
    656 
    657     if ( ! did_action('wp_print_footer_scripts') )
    658         do_action('wp_print_footer_scripts');
    659634
    660635    if ( !is_a($wp_scripts, 'WP_Scripts') )
     
    672647}
    673648
     649/**
     650 * @internal use
     651 */
    674652function _print_scripts() {
    675653    global $wp_scripts, $compress_scripts;
     
    682660
    683661        if ( !empty($wp_scripts->print_code) ) {
    684             echo "<script type='text/javascript'>\n";
    685             echo "/* <![CDATA[ */\n";
     662            echo "\n<script type='text/javascript'>\n";
     663            echo "/* <![CDATA[ */\n"; // not needed in HTML 5
    686664            echo $wp_scripts->print_code;
    687665            echo "/* ]]> */\n";
     
    719697
    720698/**
    721  * Prints the scripts that were queued for the footer on the front end.
     699 * Hooks to print the scripts and styles in the footer.
    722700 *
    723701 * @since 2.8
     
    726704    print_late_styles();
    727705    print_footer_scripts();
     706
     707    if ( !is_admin() )
     708        do_action('wp_print_footer_scripts');
     709
    728710    return true;
    729711}
     
    741723}
    742724
     725/**
     726 * Prints the styles queue in the HTML head on admin pages.
     727 *
     728 * @since 2.8
     729 */
    743730function print_admin_styles() {
    744731    global $wp_styles, $concatenate_scripts, $compress_css;
     
    762749}
    763750
     751/**
     752 * Prints the styles that were queued too late for the HTML head.
     753 *
     754 * @since 3.3
     755 */
    764756function print_late_styles() {
    765757    global $wp_styles, $concatenate_scripts;
     
    778770}
    779771
     772/**
     773 * @internal use
     774 */
    780775function _print_styles() {
    781776    global $wp_styles, $compress_css;
     
    790785        $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&load=" . trim($wp_styles->concat, ', ') . "&ver=$ver";
    791786        echo "<link rel='stylesheet' href='" . esc_attr($href) . "' type='text/css' media='all' />\n";
     787
     788        if ( !empty($wp_styles->print_code) ) {
     789            echo "<style type='text/css'>\n";
     790            echo $wp_styles->print_code;
     791            echo "\n</style>\n";
     792        }
    792793    }
    793794
     
    796797}
    797798
     799/**
     800 * Determine the concatenation and compression settings for scripts and styles.
     801 *
     802 * @since 2.8
     803 */
    798804function script_concat_settings() {
    799805    global $concatenate_scripts, $compress_scripts, $compress_css;
Note: See TracChangeset for help on using the changeset viewer.