Make WordPress Core


Ignore:
Timestamp:
07/14/2017 12:44:49 PM (7 years ago)
Author:
pento
Message:

Emoji: Store the results of the emoji_url and emoji_ext filters in statics.

Previously, these filters were being run once per post, but the changes in [41043] caused them to be run once per emoji found.

We will not stand idly by while this kind of unfair performance penalty is placed on the emoji literate. The filters are now run once only, emoji aficionados everywhere can rest easy, knowing their posts will be just as performant as their emoji-less cousins.

Props ocean90 for noticing this severe oversight.
See #35293.

File:
1 edited

Legend:

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

    r41045 r41046  
    51935193 * @access private
    51945194 *
     5195 * @see wp_staticize_emoji()
     5196 * @staticvar string $cdn_url The CDN url returned by the {@see 'emoji_url'} filter.
     5197 * @staticvar string $ext     The file extension returned by the {@see 'emoji_ext'} filter.
     5198 *
    51955199 * @param  array $matches The matched data.
    51965200 * @return string HTML for the static emoji image.
    51975201 */
    51985202function _wp_staticize_emoji( $matches ) {
    5199     /** This filter is documented in wp-includes/formatting.php */
    5200     $cdn_url = apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/2.3/72x72/' );
    5201 
    5202     /** This filter is documented in wp-includes/formatting.php */
    5203     $ext = apply_filters( 'emoji_ext', '.png' );
     5203    static $cdn_url;
     5204    if ( ! $cdn_url ) {
     5205        /** This filter is documented in wp-includes/formatting.php */
     5206        $cdn_url = apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/2.3/72x72/' );
     5207    }
     5208
     5209    static $ext;
     5210    if ( ! $ext ) {
     5211        /** This filter is documented in wp-includes/formatting.php */
     5212        $ext = apply_filters( 'emoji_ext', '.png' );
     5213    }
    52045214
    52055215    $char = str_replace( ';&#x', '-', $matches[1] );
Note: See TracChangeset for help on using the changeset viewer.