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_images( DOMDocument $dom )

Modify images of the DOMDocument


Parameters Parameters

$dom

(DOMDocument) (Required) The DOMDocument containing the certificate.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.certificates.php

	private function modify_dom_images( $dom ) {

		$images    = $dom->getElementsByTagName( 'img' );
		$to_remove = array();

		// Convert images to data uris.
		foreach ( $images as $img ) {

			$img_data_type = $this->get_image_data_and_type( $img->getAttribute( 'src' ) );

			if ( empty( $img_data_type['data'] ) || empty( $img_data_type['type'] ) ) {
				$to_remove[] = $img; // Save images to remove: removing them directly here will alter the collection iteration (skip).
				continue;
			}

			$data = base64_encode( $img_data_type['data'] );// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode

			$img->setAttribute( 'src', 'data:' . $img_data_type['type'] . ';base64,' . $data );

			// Remove srcset and sizes attributes.
			$img->removeAttribute( 'sizes' );
			$img->removeAttribute( 'srcset' );
			// Remove useless loading attribute.
			$img->removeAttribute( 'loading' );
		}

		foreach ( $to_remove as $img ) {
			$img->parentNode->removeChild( $img ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.21.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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