diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index a0438e9..2cd2212 100644
|
|
function translate_smiley( $matches ) { |
3141 | 3141 | /** |
3142 | 3142 | * Convert text equivalent of smilies to images. |
3143 | 3143 | * |
3144 | | * Will only convert smilies if the option 'use_smilies' is true and the global |
| 3144 | * Will only convert smilies if the option `'use_smilies'` is `true` and the global |
3145 | 3145 | * used in the function isn't empty. |
3146 | 3146 | * |
3147 | 3147 | * @since 0.71 |
… |
… |
function convert_smilies( $text ) { |
3155 | 3155 | global $wp_smiliessearch; |
3156 | 3156 | $output = ''; |
3157 | 3157 | if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) { |
3158 | | // HTML loop taken from texturize function, could possible be consolidated |
3159 | | $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between |
3160 | | $stop = count( $textarr );// loop stuff |
| 3158 | // HTML loop taken from texturize function, could possible be consolidated. |
| 3159 | $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between. |
| 3160 | $stop = count( $textarr );// Loop stuff. |
3161 | 3161 | |
3162 | | // Ignore proessing of specific tags |
| 3162 | // Ignore processing of specific tags. |
3163 | 3163 | $tags_to_ignore = 'code|pre|style|script|textarea'; |
3164 | 3164 | $ignore_block_element = ''; |
3165 | 3165 | |
3166 | 3166 | for ( $i = 0; $i < $stop; $i++ ) { |
3167 | 3167 | $content = $textarr[ $i ]; |
3168 | 3168 | |
3169 | | // If we're in an ignore block, wait until we find its closing tag |
3170 | | if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) { |
| 3169 | // If we're in an ignore block, wait until we find its closing tag. |
| 3170 | if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) { |
3171 | 3171 | $ignore_block_element = $matches[1]; |
3172 | 3172 | } |
3173 | 3173 | |
3174 | | // If it's not a tag and not in ignore block |
| 3174 | // If it's not a tag and not in ignore block. |
3175 | 3175 | if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) { |
3176 | 3176 | $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content ); |
3177 | 3177 | } |
3178 | 3178 | |
3179 | | // did we exit ignore block |
| 3179 | // Did we exit ignore block. |
3180 | 3180 | if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) { |
3181 | 3181 | $ignore_block_element = ''; |
3182 | 3182 | } |
… |
… |
function convert_smilies( $text ) { |
3184 | 3184 | $output .= $content; |
3185 | 3185 | } |
3186 | 3186 | } else { |
3187 | | // return default text. |
| 3187 | // Return default text. |
3188 | 3188 | $output = $text; |
3189 | 3189 | } |
3190 | 3190 | return $output; |
diff --git tests/phpunit/tests/formatting/Smilies.php tests/phpunit/tests/formatting/Smilies.php
index d1fd3af..114fd04 100644
|
|
class Tests_Formatting_Smilies extends WP_UnitTestCase { |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
| 197 | * Conversion of Smilies should be ignored in pre-determined tags |
| 198 | * (pre, code, script, style and textarea) with attributes. |
| 199 | * |
| 200 | * @ticket 44278 |
| 201 | * @dataProvider get_smilies_ignore_tags |
| 202 | */ |
| 203 | public function test_smilies_in_tags_with_attributes_should_be_ignored( $element ) { |
| 204 | update_option( 'use_smilies', 1 ); |
| 205 | smilies_init(); |
| 206 | |
| 207 | $expected = "<$element class=\"test\">:grin: :)</$element>"; |
| 208 | $actual = convert_smilies( $expected ); |
| 209 | |
| 210 | update_option( 'use_smilies', 0 ); |
| 211 | |
| 212 | $this->assertSame( $expected, $actual ); |
| 213 | } |
| 214 | |
| 215 | /** |
197 | 216 | * Validate Combinations of Smilies separated by single space |
198 | 217 | * are converted correctly |
199 | 218 | * |