Make WordPress Core


Ignore:
Timestamp:
03/24/2015 11:32:23 PM (12 years ago)
Author:
pento
Message:

Emoji: Instead of loading the emoji JS files automatically, we now include a small JS shim in the header, to test if the user's browser needs Twemoji. It then loads the emoji JS files only if they're needed.

Props pento, azaozz.

Fixes #31701.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r31864 r31875  
    40834083 */
    40844084function print_emoji_styles() {
     4085        static $printed = false;
     4086
     4087        if ( $printed ) {
     4088                return;
     4089        }
     4090
     4091        $printed = true;
    40854092?>
    40864093<style type="text/css">
    … …  
    40994106</style>
    41004107<?php
     4108}
     4109
     4110function print_emoji_detection_script() {
     4111        global $wp_version;
     4112        static $printed = false;
     4113
     4114        if ( $printed ) {
     4115                return;
     4116        }
     4117
     4118        $printed = true;
     4119
     4120        $settings = array(
     4121                /**
     4122                 * Filter the URL where emoji images are hosted.
     4123                 *
     4124                 * @since 4.2.0
     4125                 *
     4126                 * @param string The emoji base URL.
     4127                 */
     4128                'baseUrl' => apply_filters( 'emoji_url', set_url_scheme( '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ) ),
     4129
     4130                /**
     4131                 * Filter the extension of the emoji files.
     4132                 *
     4133                 * @since 4.2.0
     4134                 *
     4135                 * @param string The emoji extension. Default .png.
     4136                 */
     4137                'ext'     => apply_filters( 'emoji_ext', '.png' ),
     4138        );
     4139
     4140        $version = 'ver=' . $wp_version;
     4141
     4142        if ( SCRIPT_DEBUG ) {
     4143                $settings['source'] = array(
     4144                        'wpemoji' => includes_url( "js/wp-emoji.js?$version" ),
     4145                        'twemoji' => includes_url( "js/twemoji.js?$version" ),
     4146                );
     4147
     4148                ?>
     4149                <script type="text/javascript">
     4150                        window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
     4151                        <?php readfile( ABSPATH . WPINC . "/js/wp-emoji-loader.js" ); ?>
     4152                </script>
     4153                <?php
     4154        } else {
     4155                $settings['source'] = array(
     4156                        'concatemoji' => includes_url( "js/wp-emoji-release.min.js?$version" ),
     4157                );
     4158
     4159                ?>
     4160                <script type="text/javascript">
     4161                        window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>;
     4162                        include "js/wp-emoji-loader.min.js"
     4163                </script>
     4164                <?php
     4165        }
    41014166}
    41024167
    … …  
    41644229        }
    41654230
    4166         /** This filter is documented in wp-includes/script-loader.php */
     4231        /** This filter is documented in wp-includes/formatting.php */
    41674232        $cdn_url = apply_filters( 'emoji_url', set_url_scheme( '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72/' ) );
    41684233
    4169         /** This filter is documented in wp-includes/script-loader.php */
     4234        /** This filter is documented in wp-includes/formatting.php */
    41704235        $ext = apply_filters( 'emoji_ext', '.png' );
    41714236
Note: See TracChangeset for help on using the changeset viewer.