Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Certificates::modify_dom( string $html )

Modify the HTML using DOMDocument.


Description Description

Preparations include:

1. Removing all `script` tags.
2. Removes the WP Admin Bar.
3. Converting all stylesheets into inline `style` tags.
4. Removes all non stylesheet `link` tags.
5. Converts `img` tags into data uris.
6. Adds inline CSS to hide anything hidden in a print view.

Top ↑

Parameters Parameters

$html

(string) (Required) Certificate HTML.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class.llms.certificates.php

	private function modify_dom( $html ) {

		$dom = llms_get_dom_document( $html );
		if ( is_wp_error( $dom ) ) {
			return $html;
		}

		// Don't throw or log warnings.
		$libxml_state = libxml_use_internal_errors( true );

		// Remove all <scripts>.
		$scripts = $dom->getElementsByTagName( 'script' );
		while ( $scripts && $scripts->length ) {
			$scripts->item( 0 )->parentNode->removeChild( $scripts->item( 0 ) );
		}

		// Remove the admin bar (if found).
		$admin_bar = $dom->getElementById( 'wpadminbar' );
		if ( $admin_bar ) {
			$admin_bar->parentNode->removeChild( $admin_bar ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
		}

		$this->modify_dom_links( $dom );
		$this->modify_dom_images( $dom );

		// Hide print stuff (this is faster than traversing the dom to remove the element).
		$header = $dom->getElementsByTagName( 'head' )->item( 0 );
		$header->appendChild( $dom->createELement( 'style', '.no-print { display: none !important; }' ) );

		$html = $dom->saveHTML();

		// Handle errors.
		libxml_clear_errors();

		// Restore.
		libxml_use_internal_errors( $libxml_state );

		return $html;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.8.0 Use llms_get_dom_document() in favor of loading DOMDocument directly.
4.21.0 Allow external assets (e.g. images/stylesheets from CDN) to be embedded/inlined. Also, remove the WP Admin Bar earlier. Move the links and images modification in specific methods.
3.38.1 Use LLMS_Mime_Type_Extractor::from_file_path() in place of mime_content_type() to avoid issues with PHP installs that do not support it.
3.37.3 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.