Make WordPress Core

Changeset 52789


Ignore:
Timestamp:
02/23/2022 08:01:55 PM (2 years ago)
Author:
hellofromTonya
Message:

Formatting: Make terms in wpautop() and shortcode_unautop() more welcoming and inclusive.

The developer facing humor in these functions were from a different era of WordPress. Tolerance for in-jokes and other developer facing humor has decreased over the years. Terms like "pee" and "tinkle" may make some folks chuckle while for others it makes them uncomfortable.

Terminology of the past is being (or has been) re-evaluated to transform words into a language that are inclusive and welcome for all. This commit is part of that effort as it replaces.

Follow-up [13], [9255].

Props ricomoorman, tzipporahwitty, ironprogrammer, peterwilsoncc, jeremyfelt, Viper007Bond, rmccue, SergeyBiryukov, hellofromTonya.
Fixes #25615.

Location:
trunk
Files:
2 edited

Legend:

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

    r52640 r52789  
    434434 * @since 0.71
    435435 *
    436  * @param string $pee The text which has to be formatted.
    437  * @param bool   $br  Optional. If set, this will convert all remaining line breaks
    438  *                    after paragraphing. Line breaks within `<script>`, `<style>`,
    439  *                    and `<svg>` tags are not affected. Default true.
     436 * @param string $text The text which has to be formatted.
     437 * @param bool   $br   Optional. If set, this will convert all remaining line breaks
     438 *                     after paragraphing. Line breaks within `<script>`, `<style>`,
     439 *                     and `<svg>` tags are not affected. Default true.
    440440 * @return string Text which has been converted into correct paragraph tags.
    441441 */
    442 function wpautop( $pee, $br = true ) {
     442function wpautop( $text, $br = true ) {
    443443    $pre_tags = array();
    444444
    445     if ( trim( $pee ) === '' ) {
     445    if ( trim( $text ) === '' ) {
    446446        return '';
    447447    }
    448448
    449449    // Just to make things a little easier, pad the end.
    450     $pee = $pee . "\n";
     450    $text = $text . "\n";
    451451
    452452    /*
     
    454454     * Replace pre tags with placeholders and bring them back after autop.
    455455     */
    456     if ( strpos( $pee, '<pre' ) !== false ) {
    457         $pee_parts = explode( '</pre>', $pee );
    458         $last_pee  = array_pop( $pee_parts );
    459         $pee       = '';
    460         $i         = 0;
    461 
    462         foreach ( $pee_parts as $pee_part ) {
    463             $start = strpos( $pee_part, '<pre' );
     456    if ( strpos( $text, '<pre' ) !== false ) {
     457        $text_parts = explode( '</pre>', $text );
     458        $last_part  = array_pop( $text_parts );
     459        $text       = '';
     460        $i          = 0;
     461
     462        foreach ( $text_parts as $text_part ) {
     463            $start = strpos( $text_part, '<pre' );
    464464
    465465            // Malformed HTML?
    466466            if ( false === $start ) {
    467                 $pee .= $pee_part;
     467                $text .= $text_part;
    468468                continue;
    469469            }
    470470
    471471            $name              = "<pre wp-pre-tag-$i></pre>";
    472             $pre_tags[ $name ] = substr( $pee_part, $start ) . '</pre>';
    473 
    474             $pee .= substr( $pee_part, 0, $start ) . $name;
     472            $pre_tags[ $name ] = substr( $text_part, $start ) . '</pre>';
     473
     474            $text .= substr( $text_part, 0, $start ) . $name;
    475475            $i++;
    476476        }
    477477
    478         $pee .= $last_pee;
     478        $text .= $last_part;
    479479    }
    480480    // Change multiple <br>'s into two line breaks, which will turn into paragraphs.
    481     $pee = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee );
     481    $text = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text );
    482482
    483483    $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    484484
    485485    // Add a double line break above block-level opening tags.
    486     $pee = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $pee );
     486    $text = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $text );
    487487
    488488    // Add a double line break below block-level closing tags.
    489     $pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
     489    $text = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $text );
    490490
    491491    // Add a double line break after hr tags, which are self closing.
    492     $pee = preg_replace( '!(<hr\s*?/?>)!', "$1\n\n", $pee );
     492    $text = preg_replace( '!(<hr\s*?/?>)!', "$1\n\n", $text );
    493493
    494494    // Standardize newline characters to "\n".
    495     $pee = str_replace( array( "\r\n", "\r" ), "\n", $pee );
     495    $text = str_replace( array( "\r\n", "\r" ), "\n", $text );
    496496
    497497    // Find newlines in all elements and add placeholders.
    498     $pee = wp_replace_in_html_tags( $pee, array( "\n" => ' <!-- wpnl --> ' ) );
     498    $text = wp_replace_in_html_tags( $text, array( "\n" => ' <!-- wpnl --> ' ) );
    499499
    500500    // Collapse line breaks before and after <option> elements so they don't get autop'd.
    501     if ( strpos( $pee, '<option' ) !== false ) {
    502         $pee = preg_replace( '|\s*<option|', '<option', $pee );
    503         $pee = preg_replace( '|</option>\s*|', '</option>', $pee );
     501    if ( strpos( $text, '<option' ) !== false ) {
     502        $text = preg_replace( '|\s*<option|', '<option', $text );
     503        $text = preg_replace( '|</option>\s*|', '</option>', $text );
    504504    }
    505505
     
    508508     * so they don't get autop'd.
    509509     */
    510     if ( strpos( $pee, '</object>' ) !== false ) {
    511         $pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
    512         $pee = preg_replace( '|\s*</object>|', '</object>', $pee );
    513         $pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
     510    if ( strpos( $text, '</object>' ) !== false ) {
     511        $text = preg_replace( '|(<object[^>]*>)\s*|', '$1', $text );
     512        $text = preg_replace( '|\s*</object>|', '</object>', $text );
     513        $text = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text );
    514514    }
    515515
     
    518518     * before and after <source> and <track> elements.
    519519     */
    520     if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
    521         $pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
    522         $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
    523         $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
     520    if ( strpos( $text, '<source' ) !== false || strpos( $text, '<track' ) !== false ) {
     521        $text = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text );
     522        $text = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $text );
     523        $text = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $text );
    524524    }
    525525
    526526    // Collapse line breaks before and after <figcaption> elements.
    527     if ( strpos( $pee, '<figcaption' ) !== false ) {
    528         $pee = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $pee );
    529         $pee = preg_replace( '|</figcaption>\s*|', '</figcaption>', $pee );
     527    if ( strpos( $text, '<figcaption' ) !== false ) {
     528        $text = preg_replace( '|\s*(<figcaption[^>]*>)|', '$1', $text );
     529        $text = preg_replace( '|</figcaption>\s*|', '</figcaption>', $text );
    530530    }
    531531
    532532    // Remove more than two contiguous line breaks.
    533     $pee = preg_replace( "/\n\n+/", "\n\n", $pee );
     533    $text = preg_replace( "/\n\n+/", "\n\n", $text );
    534534
    535535    // Split up the contents into an array of strings, separated by double line breaks.
    536     $pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
    537 
    538     // Reset $pee prior to rebuilding.
    539     $pee = '';
     536    $paragraphs = preg_split( '/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY );
     537
     538    // Reset $text prior to rebuilding.
     539    $text = '';
    540540
    541541    // Rebuild the content as a string, wrapping every bit with a <p>.
    542     foreach ( $pees as $tinkle ) {
    543         $pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
     542    foreach ( $paragraphs as $paragraph ) {
     543        $text .= '<p>' . trim( $paragraph, "\n" ) . "</p>\n";
    544544    }
    545545
    546546    // Under certain strange conditions it could create a P of entirely whitespace.
    547     $pee = preg_replace( '|<p>\s*</p>|', '', $pee );
     547    $text = preg_replace( '|<p>\s*</p>|', '', $text );
    548548
    549549    // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
    550     $pee = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $pee );
     550    $text = preg_replace( '!<p>([^<]+)</(div|address|form)>!', '<p>$1</p></$2>', $text );
    551551
    552552    // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
    553     $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
     553    $text = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text );
    554554
    555555    // In some cases <li> may get wrapped in <p>, fix them.
    556     $pee = preg_replace( '|<p>(<li.+?)</p>|', '$1', $pee );
     556    $text = preg_replace( '|<p>(<li.+?)</p>|', '$1', $text );
    557557
    558558    // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
    559     $pee = preg_replace( '|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $pee );
    560     $pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
     559    $text = preg_replace( '|<p><blockquote([^>]*)>|i', '<blockquote$1><p>', $text );
     560    $text = str_replace( '</blockquote></p>', '</p></blockquote>', $text );
    561561
    562562    // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
    563     $pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $pee );
     563    $text = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', '$1', $text );
    564564
    565565    // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
    566     $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $pee );
     566    $text = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', '$1', $text );
    567567
    568568    // Optionally insert line breaks.
    569569    if ( $br ) {
    570570        // Replace newlines that shouldn't be touched with a placeholder.
    571         $pee = preg_replace_callback( '/<(script|style|svg).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
     571        $text = preg_replace_callback( '/<(script|style|svg).*?<\/\\1>/s', '_autop_newline_preservation_helper', $text );
    572572
    573573        // Normalize <br>
    574         $pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee );
     574        $text = str_replace( array( '<br>', '<br/>' ), '<br />', $text );
    575575
    576576        // Replace any new line characters that aren't preceded by a <br /> with a <br />.
    577         $pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee );
     577        $text = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $text );
    578578
    579579        // Replace newline placeholders with newlines.
    580         $pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
     580        $text = str_replace( '<WPPreserveNewline />', "\n", $text );
    581581    }
    582582
    583583    // If a <br /> tag is after an opening or closing block tag, remove it.
    584     $pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $pee );
     584    $text = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', '$1', $text );
    585585
    586586    // If a <br /> tag is before a subset of opening or closing block tags, remove it.
    587     $pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
    588     $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
     587    $text = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $text );
     588    $text = preg_replace( "|\n</p>$|", '</p>', $text );
    589589
    590590    // Replace placeholder <pre> tags with their original content.
    591591    if ( ! empty( $pre_tags ) ) {
    592         $pee = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $pee );
     592        $text = str_replace( array_keys( $pre_tags ), array_values( $pre_tags ), $text );
    593593    }
    594594
    595595    // Restore newlines in all elements.
    596     if ( false !== strpos( $pee, '<!-- wpnl -->' ) ) {
    597         $pee = str_replace( array( ' <!-- wpnl --> ', '<!-- wpnl -->' ), "\n", $pee );
    598     }
    599 
    600     return $pee;
     596    if ( false !== strpos( $text, '<!-- wpnl -->' ) ) {
     597        $text = str_replace( array( ' <!-- wpnl --> ', '<!-- wpnl -->' ), "\n", $text );
     598    }
     599
     600    return $text;
    601601}
    602602
     
    815815 * @global array $shortcode_tags
    816816 *
    817  * @param string $pee The content.
     817 * @param string $text The content.
    818818 * @return string The filtered content.
    819819 */
    820 function shortcode_unautop( $pee ) {
     820function shortcode_unautop( $text ) {
    821821    global $shortcode_tags;
    822822
    823823    if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
    824         return $pee;
     824        return $text;
    825825    }
    826826
     
    862862    // phpcs:enable
    863863
    864     return preg_replace( $pattern, '$1', $pee );
     864    return preg_replace( $pattern, '$1', $text );
    865865}
    866866
  • trunk/tests/phpunit/tests/formatting/wpAutop.php

    r52010 r52789  
    532532     * @ticket 4857
    533533     */
    534     public function test_that_text_before_blocks_is_peed() {
     534    public function test_that_text_before_blocks_is_wrapped_in_a_paragraph() {
    535535        $content  = 'a<div>b</div>';
    536536        $expected = "<p>a</p>\n<div>b</div>";
     
    566566     * @ticket 14674
    567567     */
    568     public function test_the_hr_is_not_peed() {
     568    public function test_the_hr_is_not_wrapped_in_a_paragraph() {
    569569        $content  = 'paragraph1<hr>paragraph2';
    570570        $expected = "<p>paragraph1</p>\n<hr>\n<p>paragraph2</p>";
Note: See TracChangeset for help on using the changeset viewer.