Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wptexturize [ WordPress Function ]

wptexturize ( $text )
Parameters:
  • (string) $text The text to be formatted
Uses:
  • $wp_cockneyreplace
Returns:
  • (string) The string replaced with html entities
Defined at:



Replaces common plain text characters into formatted entities

As an example,

'cause today's effort makes it worth tomorrow's "holiday"...

Becomes:

’cause today’s effort makes it worth tomorrow’s “holiday”…

Code within certain html blocks are skipped.

Source


<?php
function wptexturize($text) {
    global 
$wp_cockneyreplace;
    static 
$static_characters$static_replacements$dynamic_characters$dynamic_replacements,
        
$default_no_texturize_tags$default_no_texturize_shortcodes;

    
// No need to set up these static variables more than once
    
if ( ! isset( $static_characters ) ) {
        
/* translators: opening curly double quote */
        
$opening_quote _x'&#8220;''opening curly double quote' );
        
/* translators: closing curly double quote */
        
$closing_quote _x'&#8221;''closing curly double quote' );

        
/* translators: apostrophe, for example in 'cause or can't */
        
$apos _x'&#8217;''apostrophe' );

        
/* translators: prime, for example in 9' (nine feet) */
        
$prime _x'&#8242;''prime' );
        
/* translators: double prime, for example in 9" (nine inches) */
        
$double_prime _x'&#8243;''double prime' );

        
/* translators: opening curly single quote */
        
$opening_single_quote _x'&#8216;''opening curly single quote' );
        
/* translators: closing curly single quote */
        
$closing_single_quote _x'&#8217;''closing curly single quote' );

        
/* translators: en dash */
        
$en_dash _x'&#8211;''en dash' );
        
/* translators: em dash */
        
$em_dash _x'&#8212;''em dash' );

        
$default_no_texturize_tags = array('pre''code''kbd''style''script''tt');
        
$default_no_texturize_shortcodes = array('code');

        
// if a plugin has provided an autocorrect array, use it
        
if ( isset($wp_cockneyreplace) ) {
            
$cockney array_keys($wp_cockneyreplace);
            
$cockneyreplace array_values($wp_cockneyreplace);
        } elseif ( 
"'" != $apos ) { // Only bother if we're doing a replacement.
            
$cockney = array( "'tain't""'twere""'twas""'tis""'twill""'til""'bout""'nuff""'round""'cause" );
            
$cockneyreplace = array( $apos "tain" $apos "t"$apos "twere"$apos "twas"$apos "tis"$apos "twill"$apos "til"$apos "bout"$apos "nuff"$apos "round"$apos "cause" );
        } else {
            
$cockney $cockneyreplace = array();
        }

        
$static_characters array_merge( array( '---'' -- ''--'' - ''xn&#8211;''...''``''\'\''' (tm)' ), $cockney );
        
$static_replacements array_merge( array( $em_dash' ' $em_dash ' '$en_dash' ' $en_dash ' ''xn--''&#8230;'$opening_quote$closing_quote' &#8482;' ), $cockneyreplace );

        
$dynamic = array();
        if ( 
"'" != $apos ) {
            
$dynamic'/\'(\d\d(?:&#8217;|\')?s)/' ] = $apos '$1'// '99's
            
$dynamic'/\'(\d)/'                   ] = $apos '$1'// '99
        
}
        if ( 
"'" != $opening_single_quote )
            
$dynamic'/(\s|\A|[([{<]|")\'/'       ] = '$1' $opening_single_quote// opening single quote, even after (, {, <, [
        
if ( '"' != $double_prime )
            
$dynamic'/(\d)"/'                    ] = '$1' $double_prime// 9" (double prime)
        
if ( "'" != $prime )
            
$dynamic'/(\d)\'/'                   ] = '$1' $prime// 9' (prime)
        
if ( "'" != $apos )
            
$dynamic'/(\S)\'([^\'\s])/'          ] = '$1' $apos '$2'// apostrophe in a word
        
if ( '"' != $opening_quote )
            
$dynamic'/(\s|\A|[([{<])"(?!\s)/'    ] = '$1' $opening_quote '$2'// opening double quote, even after (, {, <, [
        
if ( '"' != $closing_quote )
            
$dynamic'/"(\s|\S|\Z)/'              ] = $closing_quote '$1'// closing double quote
        
if ( "'" != $closing_single_quote )
            
$dynamic'/\'([\s.]|\Z)/'             ] = $closing_single_quote '$1'// closing single quote

        
$dynamic'/\b(\d+)x(\d+)\b/'              ] = '$1&#215;$2'// 9x9 (times)

        
$dynamic_characters array_keys$dynamic );
        
$dynamic_replacements array_values$dynamic );
    }

    
// Transform into regexp sub-expression used in _wptexturize_pushpop_element
    // Must do this everytime in case plugins use these filters in a context sensitive manner
    
$no_texturize_tags '(' implode('|'apply_filters('no_texturize_tags'$default_no_texturize_tags) ) . ')';
    
$no_texturize_shortcodes '(' implode('|'apply_filters('no_texturize_shortcodes'$default_no_texturize_shortcodes) ) . ')';

    
$no_texturize_tags_stack = array();
    
$no_texturize_shortcodes_stack = array();

    
$textarr preg_split('/(<.*>|\[.*\])/Us'$text, -1PREG_SPLIT_DELIM_CAPTURE);

    foreach ( 
$textarr as &$curl ) {
        if ( empty( 
$curl ) )
            continue;

        
// Only call _wptexturize_pushpop_element if first char is correct tag opening
        
$first $curl[0];
        if ( 
'<' === $first ) {
            
_wptexturize_pushpop_element($curl$no_texturize_tags_stack$no_texturize_tags'<''>');
        } elseif ( 
'[' === $first ) {
            
_wptexturize_pushpop_element($curl$no_texturize_shortcodes_stack$no_texturize_shortcodes'['']');
        } elseif ( empty(
$no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
            
// This is not a tag, nor is the texturization disabled static strings
            
$curl str_replace($static_characters$static_replacements$curl);
            
// regular expressions
            
$curl preg_replace($dynamic_characters$dynamic_replacements$curl);
        }
        
$curl preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/''&#038;$1'$curl);
    }
    return 
implode''$textarr );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics