• ' ); } /** * Strips the tags in a smart way. * * @param string $html The original HTML. * * @return string The sanitized HTML. */ public function smart_strip_tags( $html ) { // Replace all new lines with spaces. $html = \preg_replace( '/(\r|\n)/', ' ', $html ); // Replace
      tags with spaces. $html = \preg_replace( '//i', ' ', $html ); // Replace closing

      and other tags with the same tag with a space after it, so we don't end up connecting words when we remove them later. $html = \preg_replace( '/<\/(p|div|h\d)>/i', ' ', $html ); // Replace list items with list identifiers so it still looks natural. $html = \preg_replace( '/(]*>)/i', '$1• ', $html ); // Strip tags. $html = \wp_strip_all_tags( $html ); // Replace multiple spaces with one space. $html = \preg_replace( '!\s+!', ' ', $html ); return \trim( $html ); } }