LLMS_Certificates::get_export( int $certificate_id, bool $use_cache = false )

Retrieve an existing or generate a downloadable HTML file for a certificate


Description Description


Parameters Parameters

$certificate_id

(int) (Required) WP Post ID of the earned certificate

$use_cache

(bool) (Optional) if true will check for existence of a cached version of the file first

Default value: false


Top ↑

Return Return

(mixed) WP_Error or full path to the generated export


Top ↑

Source Source

File: includes/class.llms.certificates.php

	public function get_export( $certificate_id, $use_cache = false ) {

		if ( $use_cache ) {
			$cached = get_post_meta( $certificate_id, '_llms_export_filepath', true );
			if ( $cached && file_exists( $cached ) ) {
				return $cached;
			}
		}

		$cert = new LLMS_User_Certificate( $certificate_id );

		/* translators: %1$s = url-safe certificate title, %2$s = random alpha-numeric characters for filename obscurity */
		$filename = sanitize_title( sprintf( esc_attr_x( 'certificate-%1$s-%2$s', 'certificate download filename', 'lifterlms' ), $cert->get( 'certificate_title' ), wp_generate_password( 12, false, false ) ) );
		$filename .= '.html';
		$filepath = LLMS_TMP_DIR . $filename;

		if ( $use_cache ) {
			update_post_meta( $certificate_id, '_llms_export_filepath', $filepath );
		}

		return $this->generate_export( $filepath, $certificate_id );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.18.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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