wp-includes/formatting.php:446Replaces double line breaks with paragraph elements.
$textstring$brbooloptionaltruestringfunction wpautop( $text, $br = true ) { $pre_tags = array(); if ( trim( $text ) === '' ) { return ''; } // Just to make things a little easier, pad the end. $text = $text . "\n"; /* * Pre tags shouldn't be touched by autop. * Replace pre tags with placeholders and bring them back after autop. */ if ( str_contains( $text, '<pre' ) ) { $text_parts = explode( '</pre>', $text ); $last_part = array_pop( $text_parts ); $text = ''; $i = 0; foreach ( $text_parts as $text_part ) { $start = strpos( $text_part, '<pre' ); // Malformed HTML? if ( false === $start ) { $text .= $text_part; continue; } $name = "<pre wp-pre-tag-$i></pre>"; $pre_tags[ $name ] = substr( $text_part, $start ) . '</pre>'; $text .= substr( $text_part, 0, $start ) . $name; ++$i; } $text .= $last_part; } // Change multiple <br>'s into two line breaks, which will turn into paragraphs. $text = preg_replace( '|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text ); $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; // Add a double line break above block-level opening tags. $text = preg_replace( '!(<' . $allblocks . '[\s/>])!', "\n\n$1", $text ); // Add a double line break below block-level closing tags. $text = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $text ); // Add a double line break after hr tags, which are self closing. $text = preg_replace( '!(<hr\s*?/?>)!', "$1\n\n", $text ); // Standardize newline characters to "\n". $text = str_replace( array( "\r\n", "\r" ), "\n", $text ); // Find newlines in all elements and add placeholders. $text = wp_replace_in_html_tags( $text, array( "\n" => ' <!-- wpnl --> ' ) ); // Collapse line breaks before and after <option> elements so they don't get autop'd. if ( str_contains( $text, '<option' ) ) { $text = preg_replace( '|\s*<option|', '<option', $text ); $text = preg_replace( '|</option>\s*|', '</option>', $text ); } /* * Collapse line breaks inside <object> elements, before <param> and <embed> elements * so they don't get autop'd. */ if ( str_contains( $text, '</object>' ) ) { $text = preg_replace( '|(<object[^>]*>)\s*|', '$1', $text ); $text = preg_replace( '|\s*</object>|', '</object>', $text ); $text = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $text ); } /* * Collapse line breaks inside <audio> and <video> elements, * before and after <source> and <track> elements. */ if ( str_contains( $text, '<source' ) || str_contains( $text, '<track' ) ) { $text = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $text );Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.