llms_certificates_remove_print_styles()

Automatically remove all non-safelisted print stylesheets from certificate and certificate templates.


Return Return

(boolean) Returns false when run on non-certificate post types, otherwise returns true.


Top ↑

Source Source

File: includes/functions/llms.functions.templates.certificates.php

function llms_certificates_remove_print_styles() {

	if ( ! in_array( get_post_type(), array( 'llms_certificate', 'llms_my_certificate' ), true ) ) {
		return false;
	}

	/**
	 * A list of registered print stylesheet handles which should be allowed for certificate and certificate templates.
	 *
	 * By default, any enqueued print stylesheets are automatically dequeued to prevent visual issues encountered when
	 * printing certificates.
	 *
	 * Any stylesheets added to this safelist will not be removed from certificates.
	 *
	 * @since 6.0.0
	 *
	 * @param string[] $safelist Array of print stylesheet handles.
	 */
	$safelist = apply_filters( 'llms_certificate_print_styles_safelist', array() );

	$styles = wp_styles();
	foreach ( $styles->queue as $handle ) {
		$style = $styles->registered[ $handle ] ?? false;
		if ( ! empty( $style->args ) && 'print' === $style->args && ! in_array( $handle, $safelist, true ) ) {
			wp_dequeue_style( $handle );
		}
	}

	return true;

}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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