wp_staticize_emoji
函数
wp_staticize_emoji ( $text )
- 参数
-
-
(string)
$text
The content to encode.- Required: 是
-
(string)
- 返回值
-
- (string) The encoded content.
- 定义位置
-
-
wp-includes/formatting.php
, line 5849
-
wp-includes/formatting.php
- 引入
- 4.2.0
- 弃用
- –
将表情符号转换为静态的img元素。
function wp_staticize_emoji( $text ) { if ( false === strpos( $text, '' ) ) { if ( ( function_exists( 'mb_check_encoding' ) && mb_check_encoding( $text, 'ASCII' ) ) || ! preg_match( '/[^x00-x7F]/', $text ) ) { // The text doesn't contain anything that might be emoji, so we can return early. return $text; } else { $encoded_text = wp_encode_emoji( $text ); if ( $encoded_text === $text ) { return $encoded_text; } $text = $encoded_text; } } $emoji = _wp_emoji_list( 'entities' ); // Quickly narrow down the list of emoji that might be in the text and need replacing. $possible_emoji = array(); foreach ( $emoji as $emojum ) { if ( false !== strpos( $text, $emojum ) ) { $possible_emoji[ $emojum ] = html_entity_decode( $emojum ); } } if ( ! $possible_emoji ) { return $text; } /** This filter is documented in wp-includes/formatting.php */ $cdn_url = apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/14.0.0/72x72/' ); /** This filter is documented in wp-includes/formatting.php */ $ext = apply_filters( 'emoji_ext', '.png' ); $output = ''; /* * HTML loop taken from smiley function, which was taken from texturize function. * It'll never be consolidated. * * First, capture the tags as well as in between. */ $textarr = preg_split( '/(<.>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); $stop = count( $textarr ); // Ignore processing of specific tags. $tags_to_ignore = 'code|pre|style|script|textarea'; $ignore_block_element = ''; for ( $i = 0; $i /', $content, $matches ) ) { $ignore_block_element = $matches[1]; } // If it's not a tag and not in ignore block. if ( '' === $ignore_block_element && strlen( $content ) > 0 && ' $emoji_char ) { if ( false === strpos( $content, $emojum ) ) { continue; } $file = str_replace( ';', '-', $emojum ); $file = str_replace( array( '', ';' ), '', $file ); $entity = sprintf( '', $cdn_url . $file . $ext, $emoji_char ); $content = str_replace( $emojum, $entity, $content ); } } // Did we exit ignore block? if ( '' !== $ignore_block_element && '' . $ignore_block_element . '>' === $content ) { $ignore_block_element = ''; } $output .= $content; } // Finally, remove any stray U+FE0F characters. $output = str_replace( '️', '', $output ); return $output; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。