convert_smilies( string $text )

Convert text equivalent of smilies to images.


Description Description

Will only convert smilies if the option ‘use_smilies’ is true and the global used in the function isn’t empty.


Parameters Parameters

$text

(string) (Required) Content to convert smilies from text.


Top ↑

Return Return

(string) Converted content with text smilies replaced with images.


Top ↑

Source Source

File: wp-includes/formatting.php

3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
0.71 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.