convert_smilies( string $text )
Convert text equivalent of smilies to images.
描述
Will only convert smilies if the option ‘use_smilies’ is true and the global used in the function isn’t empty.
参数
- $text
-
(string)
(Required)
Content to convert smilies from text.
返回值
(string) Converted content with text smilies replaced with images.
源代码
File: wp-includes/formatting.php
function convert_smilies( $text ) {
global $wp_smiliessearch;
$output = '';
if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
// HTML loop taken from texturize function, could possible be consolidated
$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
$stop = count( $textarr );// loop stuff
// Ignore proessing of specific tags
$tags_to_ignore = 'code|pre|style|script|textarea';
$ignore_block_element = '';
for ( $i = 0; $i < $stop; $i++ ) {
$content = $textarr[$i];
// If we're in an ignore block, wait until we find its closing tag
if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $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 && '<' != $content[0] ) {
$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
}
// did we exit ignore block
if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
$ignore_block_element = '';
}
$output .= $content;
}
} else {
// return default text.
$output = $text;
}
return $output;
}
更新日志
Version | 描述 |
---|---|
0.71 | Introduced. |
相关函数
Uses
-
wp-includes/option.php:
get_option()
User Contributed Notes
-
Skip to note content
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Contributed by
Codex
Displays text with converted smilies
echo convert_smilies("This smiley is going to show as an image...
");
Make your plugin generated content parse emoticons:
add_filter( "my_plugin_content_handle", "convert_smilies" );
echo apply_filters( "my_plugin_content_handle", "Howdy!
Generated with <3 by My Custom Plugin" );
你可能对这些文章感兴趣:
- wordpress函数get_all_post_type_supports()用法示例
- wordpress函数get_all_user_settings()用法示例
- wordpress函数get_all_category_ids()用法示例
- wordpress函数get_all_page_ids()用法示例
- wordpress函数get_allowed_mime_types()用法示例
- wordpress函数get_allowed_themes()用法示例
- wordpress函数get_alloptions_110()用法示例
- wordpress函数get_allowed_http_origins()用法示例
- wordpress函数get_alloptions()用法示例
- wordpress函数get_admin_users_for_domain()用法示例
- wordpress函数get_admin_url()用法示例
- wordpress函数get_admin_page_title()用法示例
- wordpress函数get_adjacent_post_rel_link()用法示例
- wordpress函数get_admin_page_parent()用法示例
如有疑问,请前往问答中心反馈!
反馈