Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/class-convertkit-api-traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<html>', '', $markup);
$markup = str_replace('</html>', '', $markup);
$markup = str_replace('<head>', '', $markup);
Expand All @@ -1784,6 +1787,28 @@ public function strip_html_head_body_tags(string $markup)
return $markup;
}

/**
* Returns the HTML within the DOMDocument's <body> 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.
*
Expand Down
6 changes: 2 additions & 4 deletions src/class-convertkit-api-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> tag as a string.
return $this->get_body_html( $html );

}

Expand Down