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

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


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( 'title' ), wp_generate_password( 12, false, false ) ) );
		$filename .= '.html';
		$filepath  = LLMS_TMP_DIR . $filename;

		// Generate the file.
		$filepath = $this->generate_export( $filepath, $certificate_id );

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

		return $filepath;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Use the certificate post title in favor of the deprecated meta value _llms_certificate_title.
3.18.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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