Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r47088 r47122  
    124124        $default_no_texturize_shortcodes = array( 'code' );
    125125
    126         // if a plugin has provided an autocorrect array, use it
     126        // If a plugin has provided an autocorrect array, use it.
    127127        if ( isset( $wp_cockneyreplace ) ) {
    128128            $cockney        = array_keys( $wp_cockneyreplace );
     
    131131            /*
    132132             * translators: This is a comma-separated list of words that defy the syntax of quotations in normal use,
    133              * for example...  'We do not have enough words yet' ... is a typical quoted phrase. But when we write
     133             * for example... 'We do not have enough words yet'... is a typical quoted phrase. But when we write
    134134             * lines of code 'til we have enough of 'em, then we need to insert apostrophes instead of quotes.
    135135             */
     
    182182        }
    183183
    184         // Quoted Numbers like '0.42'
     184        // Quoted numbers like '0.42'.
    185185        if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
    186186            $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote;
     
    192192        }
    193193
    194         // Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
     194        // Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
    195195        if ( "'" !== $apos ) {
    196196            $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag;
     
    201201        $dynamic                      = array();
    202202
    203         // Quoted Numbers like "42"
     203        // Quoted numbers like "42".
    204204        if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
    205205            $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $open_q_flag . '$1' . $closing_quote;
     
    215215        $dynamic                       = array();
    216216
    217         // Dashes and spaces
     217        // Dashes and spaces.
    218218        $dynamic['/---/'] = $em_dash;
    219219        $dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash;
     
    225225    }
    226226
    227     // Must do this every time in case plugins use these filters in a context sensitive manner
     227    // Must do this every time in case plugins use these filters in a context sensitive manner.
    228228    /**
    229229     * Filters the list of HTML elements not to texturize.
     
    272272            }
    273273        } elseif ( '' === trim( $curl ) ) {
    274             // This is a newline between delimiters.  Performance improves when we check this.
     274            // This is a newline between delimiters. Performance improves when we check this.
    275275            continue;
    276276
     
    286286            }
    287287        } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
    288             // This is neither a delimiter, nor is this content inside of no_texturize pairs.  Do texturize.
     288            // This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize.
    289289
    290290            $curl = str_replace( $static_characters, $static_replacements, $curl );
     
    305305            }
    306306
    307             // 9x9 (times), but never 0x9999
     307            // 9x9 (times), but never 0x9999.
    308308            if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
    309309                // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
     
    349349            $sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
    350350            if ( $count > 1 ) {
    351                 // This sentence appears to have multiple closing quotes.  Attempt Vulcan logic.
     351                // This sentence appears to have multiple closing quotes. Attempt Vulcan logic.
    352352                $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
    353353                if ( 0 === $count2 ) {
     
    373373                $sentence = preg_replace( $prime_pattern, $prime, $sentence );
    374374            } else {
    375                 // No closing quotes found.  Just run primes pattern.
     375                // No closing quotes found. Just run primes pattern.
    376376                $sentence = preg_replace( $prime_pattern, $prime, $sentence );
    377377            }
     
    429429            /*
    430430             * This disables texturize until we find a closing tag of our type
    431              * (e.g. <pre>) even if there was invalid nesting before that
     431             * (e.g. <pre>) even if there was invalid nesting before that.
    432432             *
    433433             * Example: in the case <pre>sadsadasd</code>"baba"</pre>
    434              *          "baba" won't be texturize
     434             *          "baba" won't be texturized.
    435435             */
    436436
     
    479479            $start = strpos( $pee_part, '<pre' );
    480480
    481             // Malformed html?
     481            // Malformed HTML?
    482482            if ( $start === false ) {
    483483                $pee .= $pee_part;
     
    494494        $pee .= $last_pee;
    495495    }
    496     // Change multiple <br>s into two line breaks, which will turn into paragraphs.
     496    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    497497    $pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee );
    498498
     
    677677            .     '(?'          // Conditional expression follows.
    678678            .         $escaped  // Find end of escaped element.
    679             .     '|'           // ... else ...
     679            .     '|'           // ...else...
    680680            .         '[^>]*>?' // Find end of normal element.
    681681            .     ')'
     
    697697 * @staticvar string $html_regex
    698698 *
    699  * @param string $shortcode_regex The result from _get_wptexturize_shortcode_regex().  Optional.
     699 * @param string $shortcode_regex The result from _get_wptexturize_shortcode_regex(). Optional.
    700700 * @return string The regular expression
    701701 */
     
    747747    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    748748    $regex =
    749         '\['              // Find start of shortcode.
    750         . '[\/\[]?'         // Shortcodes may begin with [/ or [[
     749        '\['                // Find start of shortcode.
     750        . '[\/\[]?'         // Shortcodes may begin with [/ or [[.
    751751        . $tagregexp        // Only match registered shortcodes, because performance.
    752752        . '(?:'
     
    756756        . ')*+'             // Possessive critical.
    757757        . '\]'              // Find end of shortcode.
    758         . '\]?';            // Shortcodes may end with ]]
     758        . '\]?';            // Shortcodes may end with ]].
    759759    // phpcs:enable
    760760
     
    851851    $pattern =
    852852        '/'
    853         . '<p>'                              // Opening paragraph
    854         . '(?:' . $spaces . ')*+'            // Optional leading whitespace
    855         . '('                                // 1: The shortcode
    856         .     '\\['                          // Opening bracket
    857         .     "($tagregexp)"                 // 2: Shortcode name
    858         .     '(?![\\w-])'                   // Not followed by word character or hyphen
    859                                              // Unroll the loop: Inside the opening shortcode tag
    860         .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
     853        . '<p>'                              // Opening paragraph.
     854        . '(?:' . $spaces . ')*+'            // Optional leading whitespace.
     855        . '('                                // 1: The shortcode.
     856        .     '\\['                          // Opening bracket.
     857        .     "($tagregexp)"                 // 2: Shortcode name.
     858        .     '(?![\\w-])'                   // Not followed by word character or hyphen.
     859                                             // Unroll the loop: Inside the opening shortcode tag.
     860        .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash.
    861861        .     '(?:'
    862         .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket
    863         .         '[^\\]\\/]*'               // Not a closing bracket or forward slash
     862        .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket.
     863        .         '[^\\]\\/]*'               // Not a closing bracket or forward slash.
    864864        .     ')*?'
    865865        .     '(?:'
    866         .         '\\/\\]'                   // Self closing tag and closing bracket
     866        .         '\\/\\]'                   // Self closing tag and closing bracket.
    867867        .     '|'
    868         .         '\\]'                      // Closing bracket
    869         .         '(?:'                      // Unroll the loop: Optionally, anything between the opening and closing shortcode tags
    870         .             '[^\\[]*+'             // Not an opening bracket
     868        .         '\\]'                      // Closing bracket.
     869        .         '(?:'                      // Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
     870        .             '[^\\[]*+'             // Not an opening bracket.
    871871        .             '(?:'
    872         .                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
    873         .                 '[^\\[]*+'         // Not an opening bracket
     872        .                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
     873        .                 '[^\\[]*+'         // Not an opening bracket.
    874874        .             ')*+'
    875         .             '\\[\\/\\2\\]'         // Closing shortcode tag
     875        .             '\\[\\/\\2\\]'         // Closing shortcode tag.
    876876        .         ')?'
    877877        .     ')'
    878878        . ')'
    879         . '(?:' . $spaces . ')*+'            // optional trailing whitespace
    880         . '<\\/p>'                           // closing paragraph
     879        . '(?:' . $spaces . ')*+'            // Optional trailing whitespace.
     880        . '<\\/p>'                           // Closing paragraph.
    881881        . '/';
    882882    // phpcs:enable
     
    916916            $n = 5; // 1111110b
    917917        } else {
    918             return false; // Does not match any model
     918            return false; // Does not match any model.
    919919        }
    920920        for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow ?
     
    957957    }
    958958
    959     // Don't bother if there are no specialchars - saves some processing
     959    // Don't bother if there are no specialchars - saves some processing.
    960960    if ( ! preg_match( '/[&<>"\']/', $string ) ) {
    961961        return $string;
    962962    }
    963963
    964     // Account for the previous behaviour of the function when the $quote_style is not an accepted value
     964    // Account for the previous behaviour of the function when the $quote_style is not an accepted value.
    965965    if ( empty( $quote_style ) ) {
    966966        $quote_style = ENT_NOQUOTES;
     
    969969    }
    970970
    971     // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
     971    // Store the site charset as a static to avoid multiple calls to wp_load_alloptions().
    972972    if ( ! $charset ) {
    973973        static $_charset = null;
     
    10351035    }
    10361036
    1037     // Don't bother if there are no entities - saves a lot of processing
     1037    // Don't bother if there are no entities - saves a lot of processing.
    10381038    if ( strpos( $string, '&' ) === false ) {
    10391039        return $string;
    10401040    }
    10411041
    1042     // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value
     1042    // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value.
    10431043    if ( empty( $quote_style ) ) {
    10441044        $quote_style = ENT_NOQUOTES;
     
    10471047    }
    10481048
    1049     // More complete than get_html_translation_table( HTML_SPECIALCHARS )
     1049    // More complete than get_html_translation_table( HTML_SPECIALCHARS ).
    10501050    $single      = array(
    10511051        '&#039;' => '\'',
     
    10951095    }
    10961096
    1097     // Remove zero padding on numeric entities
     1097    // Remove zero padding on numeric entities.
    10981098    $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
    10991099
    1100     // Replace characters according to translation table
     1100    // Replace characters according to translation table.
    11011101    return strtr( $string, $translation );
    11021102}
     
    11211121    }
    11221122
    1123     // Store the site charset as a static to avoid multiple calls to get_option()
     1123    // Store the site charset as a static to avoid multiple calls to get_option().
    11241124    static $is_utf8 = null;
    11251125    if ( ! isset( $is_utf8 ) ) {
     
    11301130    }
    11311131
    1132     // Check for support for utf8 in the installed PCRE library once and store the result in a static
     1132    // Check for support for utf8 in the installed PCRE library once and store the result in a static.
    11331133    static $utf8_pcre = null;
    11341134    if ( ! isset( $utf8_pcre ) ) {
     
    11361136        $utf8_pcre = @preg_match( '/^./u', 'a' );
    11371137    }
    1138     // We can't demand utf8 in the PCRE installation, so just return the string in those cases
     1138    // We can't demand utf8 in the PCRE installation, so just return the string in those cases.
    11391139    if ( ! $utf8_pcre ) {
    11401140        return $string;
    11411141    }
    11421142
    1143     // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $string
     1143    // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $string.
    11441144    if ( 1 === @preg_match( '/^./us', $string ) ) {
    11451145        return $string;
    11461146    }
    11471147
    1148     // Attempt to strip the bad chars if requested (not recommended)
     1148    // Attempt to strip the bad chars if requested (not recommended).
    11491149    if ( $strip && function_exists( 'iconv' ) ) {
    11501150        return iconv( 'utf-8', 'utf-8', $string );
     
    16081608    if ( seems_utf8( $string ) ) {
    16091609        $chars = array(
    1610             // Decompositions for Latin-1 Supplement
     1610            // Decompositions for Latin-1 Supplement.
    16111611            'ª' => 'a',
    16121612            'º' => 'o',
     
    16731673            'ÿ' => 'y',
    16741674            'Ø' => 'O',
    1675             // Decompositions for Latin Extended-A
     1675            // Decompositions for Latin Extended-A.
    16761676            'Ā' => 'A',
    16771677            'ā' => 'a',
     
    18021802            'ž' => 'z',
    18031803            'ſ' => 's',
    1804             // Decompositions for Latin Extended-B
     1804            // Decompositions for Latin Extended-B.
    18051805            'Ș' => 'S',
    18061806            'ș' => 's',
    18071807            'Ț' => 'T',
    18081808            'ț' => 't',
    1809             // Euro Sign
     1809            // Euro sign.
    18101810            '€' => 'E',
    1811             // GBP (Pound) Sign
     1811            // GBP (Pound) sign.
    18121812            '£' => '',
    1813             // Vowels with diacritic (Vietnamese)
    1814             // unmarked
     1813            // Vowels with diacritic (Vietnamese).
     1814            // Unmarked.
    18151815            'Ơ' => 'O',
    18161816            'ơ' => 'o',
    18171817            'Ư' => 'U',
    18181818            'ư' => 'u',
    1819             // grave accent
     1819            // Grave accent.
    18201820            'Ầ' => 'A',
    18211821            'ầ' => 'a',
     
    18321832            'Ỳ' => 'Y',
    18331833            'ỳ' => 'y',
    1834             // hook
     1834            // Hook.
    18351835            'Ả' => 'A',
    18361836            'ả' => 'a',
     
    18571857            'Ỷ' => 'Y',
    18581858            'ỷ' => 'y',
    1859             // tilde
     1859            // Tilde.
    18601860            'Ẫ' => 'A',
    18611861            'ẫ' => 'a',
     
    18741874            'Ỹ' => 'Y',
    18751875            'ỹ' => 'y',
    1876             // acute accent
     1876            // Acute accent.
    18771877            'Ấ' => 'A',
    18781878            'ấ' => 'a',
     
    18871887            'Ứ' => 'U',
    18881888            'ứ' => 'u',
    1889             // dot below
     1889            // Dot below.
    18901890            'Ạ' => 'A',
    18911891            'ạ' => 'a',
     
    19121912            'Ỵ' => 'Y',
    19131913            'ỵ' => 'y',
    1914             // Vowels with diacritic (Chinese, Hanyu Pinyin)
     1914            // Vowels with diacritic (Chinese, Hanyu Pinyin).
    19151915            'ɑ' => 'a',
    1916             // macron
     1916            // Macron.
    19171917            'Ǖ' => 'U',
    19181918            'ǖ' => 'u',
    1919             // acute accent
     1919            // Acute accent.
    19201920            'Ǘ' => 'U',
    19211921            'ǘ' => 'u',
    1922             // caron
     1922            // Caron.
    19231923            'Ǎ' => 'A',
    19241924            'ǎ' => 'a',
     
    19311931            'Ǚ' => 'U',
    19321932            'ǚ' => 'u',
    1933             // grave accent
     1933            // Grave accent.
    19341934            'Ǜ' => 'U',
    19351935            'ǜ' => 'u',
    19361936        );
    19371937
    1938         // Used for locale-specific rules
     1938        // Used for locale-specific rules.
    19391939        $locale = get_locale();
    19401940
     
    19641964    } else {
    19651965        $chars = array();
    1966         // Assume ISO-8859-1 if not UTF-8
     1966        // Assume ISO-8859-1 if not UTF-8.
    19671967        $chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e"
    19681968            . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
     
    20292029    }
    20302030
    2031     // Split the filename into a base and extension[s]
     2031    // Split the filename into a base and extension[s].
    20322032    $parts = explode( '.', $filename );
    20332033
    2034     // Return if only one extension
     2034    // Return if only one extension.
    20352035    if ( count( $parts ) <= 2 ) {
    20362036        /**
     
    20452045    }
    20462046
    2047     // Process multiple extensions
     2047    // Process multiple extensions.
    20482048    $filename  = array_shift( $parts );
    20492049    $extension = array_pop( $parts );
     
    20942094    $username     = wp_strip_all_tags( $username );
    20952095    $username     = remove_accents( $username );
    2096     // Kill octets
     2096    // Kill octets.
    20972097    $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
    2098     $username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
     2098    // Kill entities.
     2099    $username = preg_replace( '/&.+?;/', '', $username );
    20992100
    21002101    // If strict, reduce to ASCII for max portability.
     
    21042105
    21052106    $username = trim( $username );
    2106     // Consolidate contiguous whitespace
     2107    // Consolidate contiguous whitespace.
    21072108    $username = preg_replace( '|\s+|', ' ', $username );
    21082109
     
    22302231
    22312232    if ( 'save' == $context ) {
    2232         // Convert nbsp, ndash and mdash to hyphens
     2233        // Convert &nbsp, &ndash, and &mdash to hyphens.
    22332234        $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
    2234         // Convert nbsp, ndash and mdash HTML entities to hyphens
     2235        // Convert &nbsp, &ndash, and &mdash HTML entities to hyphens.
    22352236        $title = str_replace( array( '&nbsp;', '&#160;', '&ndash;', '&#8211;', '&mdash;', '&#8212;' ), '-', $title );
    2236         // Convert forward slash to hyphen
     2237        // Convert forward slash to hyphen.
    22372238        $title = str_replace( '/', '-', $title );
    22382239
    2239         // Strip these characters entirely
     2240        // Strip these characters entirely.
    22402241        $title = str_replace(
    22412242            array(
    2242                 // soft hyphens
     2243                // Soft hyphens.
    22432244                '%c2%ad',
    2244                 // iexcl and iquest
     2245                // &iexcl and &iquest.
    22452246                '%c2%a1',
    22462247                '%c2%bf',
    2247                 // angle quotes
     2248                // Angle quotes.
    22482249                '%c2%ab',
    22492250                '%c2%bb',
    22502251                '%e2%80%b9',
    22512252                '%e2%80%ba',
    2252                 // curly quotes
     2253                // Curly quotes.
    22532254                '%e2%80%98',
    22542255                '%e2%80%99',
     
    22592260                '%e2%80%9e',
    22602261                '%e2%80%9f',
    2261                 // copy, reg, deg, hellip and trade
     2262                // &copy, &reg, &deg, &hellip, and &trade.
    22622263                '%c2%a9',
    22632264                '%c2%ae',
     
    22652266                '%e2%80%a6',
    22662267                '%e2%84%a2',
    2267                 // acute accents
     2268                // Acute accents.
    22682269                '%c2%b4',
    22692270                '%cb%8a',
    22702271                '%cc%81',
    22712272                '%cd%81',
    2272                 // grave accent, macron, caron
     2273                // Grave accent, macron, caron.
    22732274                '%cc%80',
    22742275                '%cc%84',
     
    22792280        );
    22802281
    2281         // Convert times to x
     2282        // Convert &times to 'x'.
    22822283        $title = str_replace( '%c3%97', 'x', $title );
    22832284    }
    22842285
    2285     $title = preg_replace( '/&.+?;/', '', $title ); // kill entities
     2286    // Kill entities.
     2287    $title = preg_replace( '/&.+?;/', '', $title );
    22862288    $title = str_replace( '.', '-', $title );
    22872289
     
    23302332 */
    23312333function sanitize_html_class( $class, $fallback = '' ) {
    2332     //Strip out any % encoded octets
     2334    // Strip out any %-encoded octets.
    23332335    $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );
    23342336
    2335     //Limit to A-Z,a-z,0-9,_,-
     2337    // Limit to A-Z, a-z, 0-9, '_', '-'.
    23362338    $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
    23372339
     
    23822384function convert_invalid_entities( $content ) {
    23832385    $wp_htmltranswinuni = array(
    2384         '&#128;' => '&#8364;', // the Euro sign
     2386        '&#128;' => '&#8364;', // The Euro sign.
    23852387        '&#129;' => '',
    2386         '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
    2387         '&#131;' => '&#402;',  // they would look weird on non-Windows browsers
     2388        '&#130;' => '&#8218;', // These are Windows CP1252 specific characters.
     2389        '&#131;' => '&#402;',  // They would look weird on non-Windows browsers.
    23882390        '&#132;' => '&#8222;',
    23892391        '&#133;' => '&#8230;',
     
    24642466    $tagqueue  = '';
    24652467    $newtext   = '';
    2466     // Known single-entity/self-closing tags
     2468    // Known single-entity/self-closing tags.
    24672469    $single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' );
    2468     // Tags that can be immediately nested within themselves
     2470    // Tags that can be immediately nested within themselves.
    24692471    $nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' );
    24702472
    2471     // WP bug fix for comments - in case you REALLY meant to type '< !--'
     2473    // WP bug fix for comments - in case you REALLY meant to type '< !--'.
    24722474    $text = str_replace( '< !--', '<    !--', $text );
    2473     // WP bug fix for LOVE <3 (and other situations with '<' before a number)
     2475    // WP bug fix for LOVE <3 (and other situations with '<' before a number).
    24742476    $text = preg_replace( '#<([0-9]{1})#', '&lt;$1', $text );
    24752477
     
    25272529        // Clear the shifter.
    25282530        $tagqueue = '';
    2529         if ( $has_leading_slash ) { // End Tag.
     2531        if ( $has_leading_slash ) { // End tag.
    25302532            // If too many closing tags.
    25312533            if ( $stacksize <= 0 ) {
     
    25352537                // If stacktop value = tag close value, then pop.
    25362538            } elseif ( $tagstack[ $stacksize - 1 ] === $tag ) { // Found closing tag.
    2537                 $tag = '</' . $tag . '>'; // Close Tag.
     2539                $tag = '</' . $tag . '>'; // Close tag.
    25382540                array_pop( $tagstack );
    25392541                $stacksize--;
     
    25512553                $tag = '';
    25522554            }
    2553         } else { // Begin Tag.
     2555        } else { // Begin tag.
    25542556            if ( $has_self_closer ) { // If it presents itself as a self-closing tag...
    2555                 // ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and
    2556                 // immediately close it with a closing tag (the tag will encapsulate no text as a result)
     2557                // ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such
     2558                // and immediately close it with a closing tag (the tag will encapsulate no text as a result).
    25572559                if ( ! $is_single_tag ) {
    25582560                    $attributes = trim( substr( $attributes, 0, -1 ) ) . "></$tag";
    25592561                }
    2560             } elseif ( $is_single_tag ) { // ElseIf it's a known single-entity tag but it doesn't close itself, do so
     2562            } elseif ( $is_single_tag ) { // Else if it's a known single-entity tag but it doesn't close itself, do so.
    25612563                $pre_attribute_ws = ' ';
    25622564                $attributes      .= '/';
     
    25872589    }
    25882590
    2589     // Clear Tag Queue.
     2591    // Clear tag queue.
    25902592    $newtext .= $tagqueue;
    25912593
     
    28192821
    28202822    if ( ')' == $matches[3] && strpos( $url, '(' ) ) {
    2821         // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
    2822         // Then we can let the parenthesis balancer do its thing below.
     2823        // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it,
     2824        // add the closing parenthesis to the URL. Then we can let the parenthesis balancer do its thing below.
    28232825        $url   .= $matches[3];
    28242826        $suffix = '';
     
    28272829    }
    28282830
    2829     // Include parentheses in the URL only if paired
     2831    // Include parentheses in the URL only if paired.
    28302832    while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
    28312833        $suffix = strrchr( $url, ')' ) . $suffix;
     
    28742876    $dest = 'http://' . $dest;
    28752877
    2876     // removed trailing [.,;:)] from URL
     2878    // Removed trailing [.,;:)] from URL.
    28772879    if ( in_array( substr( $dest, -1 ), array( '.', ',', ';', ':', ')' ) ) === true ) {
    28782880        $ret  = substr( $dest, -1 );
     
    29272929function make_clickable( $text ) {
    29282930    $r               = '';
    2929     $textarr         = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags
    2930     $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
     2931    $textarr         = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Split out HTML tags.
     2932    $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>.
    29312933    foreach ( $textarr as $piece ) {
    29322934
     
    29422944        }
    29432945
    2944         // Long strings might contain expensive edge cases ...
     2946        // Long strings might contain expensive edge cases...
    29452947        if ( 10000 < strlen( $piece ) ) {
    2946             // ... break it up
    2947             foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses
     2948            // ...break it up.
     2949            foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses.
    29482950                if ( 2101 < strlen( $chunk ) ) {
    29492951                    $r .= $chunk; // Too big, no whitespace: bail.
     
    29532955            }
    29542956        } else {
    2955             $ret = " $piece "; // Pad with whitespace to simplify the regexes
     2957            $ret = " $piece "; // Pad with whitespace to simplify the regexes.
    29562958
    29572959            $url_clickable = '~
    2958                 ([\\s(<.,;:!?])                                        # 1: Leading whitespace, or punctuation
    2959                 (                                                      # 2: URL
    2960                     [\\w]{1,20}+://                                # Scheme and hier-part prefix
    2961                     (?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long
    2962                     [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character
    2963                     (?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character
    2964                         [\'.,;:!?)]                            # Punctuation URL character
    2965                         [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character
     2960                ([\\s(<.,;:!?])                                # 1: Leading whitespace, or punctuation.
     2961                (                                              # 2: URL.
     2962                    [\\w]{1,20}+://                                # Scheme and hier-part prefix.
     2963                    (?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long.
     2964                    [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character.
     2965                    (?:                                            # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character.
     2966                        [\'.,;:!?)]                                    # Punctuation URL character.
     2967                        [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++         # Non-punctuation URL character.
    29662968                    )*
    29672969                )
    2968                 (\)?)                                                  # 3: Trailing closing parenthesis (for parethesis balancing post processing)
     2970                (\)?)                                          # 3: Trailing closing parenthesis (for parethesis balancing post processing).
    29692971            ~xS';
    29702972            // The regex is a non-anchored pattern and does not have a single fixed starting character.
     
    29812983    }
    29822984
    2983     // Cleanup of accidental links within links
     2985    // Cleanup of accidental links within links.
    29842986    return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', '$1$3</a>', $r );
    29852987}
     
    29972999 *     _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234   890 123456789 1234567890a    45678   1 3 5 7 90 ", 10 ) ==
    29983000 *     array (
    2999  *         0 => '1234 67890 ',  // 11 characters: Perfect split
    3000  *         1 => '1234 ',        //  5 characters: '1234 67890a' was too long
    3001  *         2 => '67890a cd ',   // 10 characters: '67890a cd 1234' was too long
    3002  *         3 => '1234   890 ',  // 11 characters: Perfect split
    3003  *         4 => '123456789 ',   // 10 characters: '123456789 1234567890a' was too long
    3004  *         5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split
    3005  *         6 => '   45678   ',  // 11 characters: Perfect split
    3006  *         7 => '1 3 5 7 90 ',  // 11 characters: End of $string
     3001 *         0 => '1234 67890 ',  // 11 characters: Perfect split.
     3002 *         1 => '1234 ',        //  5 characters: '1234 67890a' was too long.
     3003 *         2 => '67890a cd ',   // 10 characters: '67890a cd 1234' was too long.
     3004 *         3 => '1234   890 ',  // 11 characters: Perfect split.
     3005 *         4 => '123456789 ',   // 10 characters: '123456789 1234567890a' was too long.
     3006 *         5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split.
     3007 *         6 => '   45678   ',  // 11 characters: Perfect split.
     3008 *         7 => '1 3 5 7 90 ',  // 11 characters: End of $string.
    30073009 *     );
    30083010 *
     
    31893191    $original_link_html = $link_html;
    31903192
    3191     // Consider the html escaped if there are no unescaped quotes
     3193    // Consider the HTML escaped if there are no unescaped quotes.
    31923194    $is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html );
    31933195    if ( $is_escaped ) {
    3194         // Replace only the quotes so that they are parsable by wp_kses_hair, leave the rest as is
     3196        // Replace only the quotes so that they are parsable by wp_kses_hair(), leave the rest as is.
    31953197        $link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html );
    31963198    }
     
    32083210    $rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html );
    32093211
    3210     // Return early if no rel values to be added or if no actual target attribute
     3212    // Return early if no rel values to be added or if no actual target attribute.
    32113213    if ( ! $rel || ! isset( $atts['target'] ) ) {
    32123214        return "<a $original_link_html>";
     
    33393341    $output = '';
    33403342    if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
    3341         // HTML loop taken from texturize function, could possible be consolidated
    3342         $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between
    3343         $stop    = count( $textarr );// loop stuff
    3344 
    3345         // Ignore proessing of specific tags
     3343        // HTML loop taken from texturize function, could possible be consolidated.
     3344        $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.
     3345        $stop    = count( $textarr ); // Loop stuff.
     3346
     3347        // Ignore proessing of specific tags.
    33463348        $tags_to_ignore       = 'code|pre|style|script|textarea';
    33473349        $ignore_block_element = '';
     
    33503352            $content = $textarr[ $i ];
    33513353
    3352             // If we're in an ignore block, wait until we find its closing tag
     3354            // If we're in an ignore block, wait until we find its closing tag.
    33533355            if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
    33543356                $ignore_block_element = $matches[1];
    33553357            }
    33563358
    3357             // If it's not a tag and not in ignore block
     3359            // If it's not a tag and not in ignore block.
    33583360            if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
    33593361                $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
    33603362            }
    33613363
    3362             // did we exit ignore block
     3364            // Did we exit ignore block?
    33633365            if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
    33643366                $ignore_block_element = '';
     
    33683370        }
    33693371    } else {
    3370         // return default text.
     3372        // Return default text.
    33713373        $output = $text;
    33723374    }
     
    33903392    }
    33913393
    3392     // Test for the minimum length the email can be
     3394    // Test for the minimum length the email can be.
    33933395    if ( strlen( $email ) < 6 ) {
    33943396        /**
     
    34083410    }
    34093411
    3410     // Test for an @ character after the first position
     3412    // Test for an @ character after the first position.
    34113413    if ( strpos( $email, '@', 1 ) === false ) {
    34123414        /** This filter is documented in wp-includes/formatting.php */
     
    34143416    }
    34153417
    3416     // Split out the local and domain parts
     3418    // Split out the local and domain parts.
    34173419    list( $local, $domain ) = explode( '@', $email, 2 );
    34183420
    34193421    // LOCAL PART
    3420     // Test for invalid characters
     3422    // Test for invalid characters.
    34213423    if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
    34223424        /** This filter is documented in wp-includes/formatting.php */
     
    34253427
    34263428    // DOMAIN PART
    3427     // Test for sequences of periods
     3429    // Test for sequences of periods.
    34283430    if ( preg_match( '/\.{2,}/', $domain ) ) {
    34293431        /** This filter is documented in wp-includes/formatting.php */
     
    34313433    }
    34323434
    3433     // Test for leading and trailing periods and whitespace
     3435    // Test for leading and trailing periods and whitespace.
    34343436    if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
    34353437        /** This filter is documented in wp-includes/formatting.php */
     
    34373439    }
    34383440
    3439     // Split the domain into subs
     3441    // Split the domain into subs.
    34403442    $subs = explode( '.', $domain );
    34413443
    3442     // Assume the domain will have at least two subs
     3444    // Assume the domain will have at least two subs.
    34433445    if ( 2 > count( $subs ) ) {
    34443446        /** This filter is documented in wp-includes/formatting.php */
     
    34463448    }
    34473449
    3448     // Loop through each sub
     3450    // Loop through each sub.
    34493451    foreach ( $subs as $sub ) {
    3450         // Test for leading and trailing hyphens and whitespace
     3452        // Test for leading and trailing hyphens and whitespace.
    34513453        if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
    34523454            /** This filter is documented in wp-includes/formatting.php */
     
    34543456        }
    34553457
    3456         // Test for invalid characters
     3458        // Test for invalid characters.
    34573459        if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
    34583460            /** This filter is documented in wp-includes/formatting.php */
     
    34613463    }
    34623464
    3463     // Congratulations your email made it!
     3465    // Congratulations, your email made it!
    34643466    /** This filter is documented in wp-includes/formatting.php */
    34653467    return apply_filters( 'is_email', $email, $email, null );
     
    35503552 */
    35513553function iso8601_timezone_to_offset( $timezone ) {
    3552     // $timezone is either 'Z' or '[+|-]hhmm'
     3554    // $timezone is either 'Z' or '[+|-]hhmm'.
    35533555    if ( $timezone == 'Z' ) {
    35543556        $offset = 0;
     
    36003602 */
    36013603function sanitize_email( $email ) {
    3602     // Test for the minimum length the email can be
     3604    // Test for the minimum length the email can be.
    36033605    if ( strlen( $email ) < 6 ) {
    36043606        /**
     
    36183620    }
    36193621
    3620     // Test for an @ character after the first position
     3622    // Test for an @ character after the first position.
    36213623    if ( strpos( $email, '@', 1 ) === false ) {
    36223624        /** This filter is documented in wp-includes/formatting.php */
     
    36243626    }
    36253627
    3626     // Split out the local and domain parts
     3628    // Split out the local and domain parts.
    36273629    list( $local, $domain ) = explode( '@', $email, 2 );
    36283630
    36293631    // LOCAL PART
    3630     // Test for invalid characters
     3632    // Test for invalid characters.
    36313633    $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
    36323634    if ( '' === $local ) {
     
    36363638
    36373639    // DOMAIN PART
    3638     // Test for sequences of periods
     3640    // Test for sequences of periods.
    36393641    $domain = preg_replace( '/\.{2,}/', '', $domain );
    36403642    if ( '' === $domain ) {
     
    36433645    }
    36443646
    3645     // Test for leading and trailing periods and whitespace
     3647    // Test for leading and trailing periods and whitespace.
    36463648    $domain = trim( $domain, " \t\n\r\0\x0B." );
    36473649    if ( '' === $domain ) {
     
    36503652    }
    36513653
    3652     // Split the domain into subs
     3654    // Split the domain into subs.
    36533655    $subs = explode( '.', $domain );
    36543656
    3655     // Assume the domain will have at least two subs
     3657    // Assume the domain will have at least two subs.
    36563658    if ( 2 > count( $subs ) ) {
    36573659        /** This filter is documented in wp-includes/formatting.php */
     
    36593661    }
    36603662
    3661     // Create an array that will contain valid subs
     3663    // Create an array that will contain valid subs.
    36623664    $new_subs = array();
    36633665
    3664     // Loop through each sub
     3666    // Loop through each sub.
    36653667    foreach ( $subs as $sub ) {
    3666         // Test for leading and trailing hyphens
     3668        // Test for leading and trailing hyphens.
    36673669        $sub = trim( $sub, " \t\n\r\0\x0B-" );
    36683670
    3669         // Test for invalid characters
     3671        // Test for invalid characters.
    36703672        $sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub );
    36713673
    3672         // If there's anything left, add it to the valid subs
     3674        // If there's anything left, add it to the valid subs.
    36733675        if ( '' !== $sub ) {
    36743676            $new_subs[] = $sub;
     
    36763678    }
    36773679
    3678     // If there aren't 2 or more valid subs
     3680    // If there aren't 2 or more valid subs.
    36793681    if ( 2 > count( $new_subs ) ) {
    36803682        /** This filter is documented in wp-includes/formatting.php */
     
    36823684    }
    36833685
    3684     // Join valid subs into the new domain
     3686    // Join valid subs into the new domain.
    36853687    $domain = join( '.', $new_subs );
    36863688
    3687     // Put the email back together
     3689    // Put the email back together.
    36883690    $sanitized_email = $local . '@' . $domain;
    36893691
    3690     // Congratulations your email made it!
     3692    // Congratulations, your email made it!
    36913693    /** This filter is documented in wp-includes/formatting.php */
    36923694    return apply_filters( 'sanitize_email', $sanitized_email, $email, null );
     
    43054307
    43064308    $url = str_replace( ';//', '://', $url );
    4307     /* If the URL doesn't appear to contain a scheme, we
    4308      * presume it needs http:// prepended (unless a relative
    4309      * link starting with /, # or ? or a php file).
     4309    /*
     4310     * If the URL doesn't appear to contain a scheme, we presume
     4311     * it needs http:// prepended (unless it's a relative link
     4312     * starting with /, # or ?, or a PHP file).
    43104313     */
    43114314    if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
     
    46234626        case 'default_ping_status':
    46244627        case 'default_comment_status':
    4625             // Options that if not there have 0 value but need to be something like "closed"
     4628            // Options that if not there have 0 value but need to be something like "closed".
    46264629            if ( $value == '0' || $value == '' ) {
    46274630                $value = 'closed';
     
    46444647
    46454648        case 'blog_charset':
    4646             $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // strips slashes
     4649            $value = preg_replace( '/[^a-zA-Z0-9_-]/', '', $value ); // Strips slashes.
    46474650            break;
    46484651
     
    46794682
    46804683        case 'gmt_offset':
    4681             $value = preg_replace( '/[^0-9:.-]/', '', $value ); // strips slashes
     4684            $value = preg_replace( '/[^0-9:.-]/', '', $value ); // Strips slashes.
    46824685            break;
    46834686
     
    49494952    $arg_index = 0;
    49504953    while ( $len > $start ) {
    4951         // Last character: append and break
     4954        // Last character: append and break.
    49524955        if ( strlen( $pattern ) - 1 == $start ) {
    49534956            $result .= substr( $pattern, -1 );
     
    49554958        }
    49564959
    4957         // Literal %: append and continue
     4960        // Literal %: append and continue.
    49584961        if ( substr( $pattern, $start, 2 ) == '%%' ) {
    49594962            $start  += 2;
     
    49624965        }
    49634966
    4964         // Get fragment before next %
     4967        // Get fragment before next %.
    49654968        $end = strpos( $pattern, '%', $start + 1 );
    49664969        if ( false === $end ) {
     
    49694972        $fragment = substr( $pattern, $start, $end - $start );
    49704973
    4971         // Fragment has a specifier
     4974        // Fragment has a specifier.
    49724975        if ( $pattern[ $start ] == '%' ) {
    4973             // Find numbered arguments or take the next one in order
     4976            // Find numbered arguments or take the next one in order.
    49744977            if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
    4975                 $index    = $matches[1] - 1; // 0-based array vs 1-based sprintf arguments.
     4978                $index    = $matches[1] - 1; // 0-based array vs 1-based sprintf() arguments.
    49764979                $arg      = isset( $args[ $index ] ) ? $args[ $index ] : '';
    49774980                $fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
     
    49995002        }
    50005003
    5001         // Append to result and move to next fragment
     5004        // Append to result and move to next fragment.
    50025005        $result .= $fragment;
    50035006        $start   = $end;
    50045007    }
     5008
    50055009    return $result;
    50065010}
     
    50205024 */
    50215025function wp_sprintf_l( $pattern, $args ) {
    5022     // Not a match
     5026    // Not a match.
    50235027    if ( substr( $pattern, 0, 2 ) != '%l' ) {
    50245028        return $pattern;
    50255029    }
    50265030
    5027     // Nothing to work with
     5031    // Nothing to work with.
    50285032    if ( empty( $args ) ) {
    50295033        return '';
     
    50585062        $result .= $l['between_only_two'] . array_shift( $args );
    50595063    }
    5060     // Loop when more than two args
     5064
     5065    // Loop when more than two args.
    50615066    $i = count( $args );
    50625067    while ( $i ) {
     
    50695074        }
    50705075    }
     5076
    50715077    return $result . substr( $pattern, 2 );
    50725078}
     
    50905096        $more = '';
    50915097    }
     5098
    50925099    $str     = wp_strip_all_tags( $str, true );
    50935100    $excerpt = mb_substr( $str, 0, $count );
    5094     // remove part of an entity at the end
     5101
     5102    // Remove part of an entity at the end.
    50955103    $excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
    50965104    if ( $str != $excerpt ) {
    50975105        $excerpt = trim( $excerpt ) . $more;
    50985106    }
     5107
    50995108    return $excerpt;
    51005109}
     
    51355144function _links_add_base( $m ) {
    51365145    global $_links_add_base;
    5137     //1 = attribute name  2 = quotation mark  3 = URL
     5146    // 1 = attribute name  2 = quotation mark  3 = URL.
    51385147    return $m[1] . '=' . $m[2] .
    51395148        ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ?
     
    53095318        $filtered = wp_strip_all_tags( $filtered, false );
    53105319
    5311         // Use html entities in a special case to make sure no later
    5312         // newline stripping stage could lead to a functional tag
     5320        // Use HTML entities in a special case to make sure no later
     5321        // newline stripping stage could lead to a functional tag.
    53135322        $filtered = str_replace( "<\n", "&lt;\n", $filtered );
    53145323    }
     
    53605369 */
    53615370function capital_P_dangit( $text ) {
    5362     // Simple replacement for titles
     5371    // Simple replacement for titles.
    53635372    $current_filter = current_filter();
    53645373    if ( 'the_title' === $current_filter || 'wp_title' === $current_filter ) {
    53655374        return str_replace( 'Wordpress', 'WordPress', $text );
    53665375    }
    5367     // Still here? Use the more judicious replacement
     5376    // Still here? Use the more judicious replacement.
    53685377    static $dblq = false;
    53695378    if ( false === $dblq ) {
     
    55235532 *
    55245533 * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
    5525  * This is designed to replace the PCRE \s sequence.  In ticket #22692, that
     5534 * This is designed to replace the PCRE \s sequence. In ticket #22692, that
    55265535 * sequence was found to be unreliable due to random inclusion of the A0 byte.
    55275536 *
     
    57995808        }
    58005809
    5801         // Did we exit ignore block.
     5810        // Did we exit ignore block?
    58025811        if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
    58035812            $ignore_block_element = '';
     
    58075816    }
    58085817
    5809     // Finally, remove any stray U+FE0F characters
     5818    // Finally, remove any stray U+FE0F characters.
    58105819    $output = str_replace( '&#xfe0f;', '', $output );
    58115820
Note: See TracChangeset for help on using the changeset viewer.