ace_callback( $regex, [ $this, 'replace_svg' ], $html ); if ( empty( $replaced_html ) ) { return $html; } return $replaced_html; } /** * Replace svg with comment * * @since 3.12.3 * * @param array $match svg tag. * @return string */ protected function replace_svg( $match ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.matchFound $key = sprintf( '', uniqid( 'WPR_SVG_' ) ); $this->svg_replace[ $key ] = $match[0]; return $key; } /** * Replace xmp with comment * * @since 3.12.3 * * @param array $match xmp tag. * @return string */ protected function replace_xmp( $match ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.matchFound $key = sprintf( '', uniqid( 'WPR_XMP_' ) ); $this->xmp_replace[ $key ] = $match[0]; return $key; } /** * Restore tags * * @since 3.12.5.3 * * @param string $html HTML content. * @return string */ protected function restore_svg_tags( $html ) { if ( empty( $this->svg_replace ) ) { return $html; } return str_replace( array_keys( $this->svg_replace ), array_values( $this->svg_replace ), $html ); } /** * Restore tags * * @since 3.12.3 * * @param string $html HTML content. * @return string */ protected function restore_xmp_tags( $html ) { if ( empty( $this->xmp_replace ) ) { return $html; } return str_replace( array_keys( $this->xmp_replace ), array_values( $this->xmp_replace ), $html ); } /** * Checks if the page HTML is valid or not. * Valid here means that it has a closing title tag. * * @param string $html Page HTML. * * @return bool */ private function html_has_title_tag( string $html ) { return (bool) preg_match( '##iU', $html ); } }