diff --git a/src/class-convertkit-api-traits.php b/src/class-convertkit-api-traits.php index 2ffd6e6..22693c5 100644 --- a/src/class-convertkit-api-traits.php +++ b/src/class-convertkit-api-traits.php @@ -1773,6 +1773,9 @@ public function convert_script_type(\DOMNodeList $elements) */ public function strip_html_head_body_tags(string $markup) { + // Mark as deprecated in 2.1.0. + _deprecated_function( __FUNCTION__, '2.1.0', 'get_body_html()' ); + $markup = str_replace('', '', $markup); $markup = str_replace('', '', $markup); $markup = str_replace('', '', $markup); @@ -1784,6 +1787,28 @@ public function strip_html_head_body_tags(string $markup) return $markup; } + /** + * Returns the HTML within the DOMDocument's tag as a string. + * + * @param \DOMDocument $dom DOM Document. + * + * @since 2.1.0 + * + * @return string + */ + public function get_body_html(\DOMDocument $dom) { + + $body = $dom->getElementsByTagName( 'body' )->item( 0 ); + + $html = ''; + foreach ( $body->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase + $html .= $dom->saveHTML( $child ); + } + + return $html; + + } + /** * Adds total count and pagination parameters to the given array of existing API parameters. * diff --git a/src/class-convertkit-api-v4.php b/src/class-convertkit-api-v4.php index 1733c71..babda61 100644 --- a/src/class-convertkit-api-v4.php +++ b/src/class-convertkit-api-v4.php @@ -1251,10 +1251,8 @@ public function get_html( $url, $body_only = true ) { return $html->saveHTML(); } - // Remove some HTML tags that DOMDocument adds, returning the output. - // We do this instead of using LIBXML_HTML_NOIMPLIED in loadHTML(), because Legacy Forms are not always contained in - // a single root / outer element, which is required for LIBXML_HTML_NOIMPLIED to correctly work. - return $this->strip_html_head_body_tags( $html->saveHTML() ); + // Return the HTML within the DOMDocument's tag as a string. + return $this->get_body_html( $html ); }