LLMS_User_Certificate::get_background_image()

Retrieve information about the certificate background image.


Description Description

This function returns an array of information used for legacy certificates using the v1 template.

When using the v2 template, only the $src value is utilized and the background image itself is always set to 100% width and height of certificate as defined by the certificate’s sizing settings.


Top ↑

Return Return

(array) Returns an associative array of information about the background image.

  • 'src'
    (string) The image source url.
  • 'width'
    (int) The image display width, in pixels.
  • 'height'
    (int) The image display height, in pixels.
  • 'is_default'
    (bool) Whether or not the default image was returned.


Top ↑

Source Source

File: includes/models/model.llms.user.certificate.php

	public function get_background_image() {

		$id     = $this->get( 'id' );
		$img_id = get_post_thumbnail_id( $id );

		$size = 'full';
		if ( 1 === $this->get_template_version() ) {
			$size = llms_parse_bool( get_option( 'lifterlms_certificate_legacy_image_size', 'yes' ) ) ? 'full' : 'lifterlms_certificate_background';
		}

		if ( ! $img_id ) {

			// Get the source.
			$src = llms()->certificates()->get_default_image( $id );

			// Denote it's the default image in the return.
			$is_default = true;

			/**
			 * Filters the display height of the default certificate background image.
			 *
			 * This filter is used by legacy certificates only. If the certificate is utilizing
			 * the block editor the filtered value does not affect the size of the background image as
			 * the image is always set to fill the width and height of the certificate itself.
			 *
			 * @since 2.2.0
			 *
			 * @param int $height         Display height of the image, in pixels.
			 * @param int $certificate_id WP_Post ID of the awarded certificate.
			 */
			$height = apply_filters( 'lifterlms_certificate_background_image_placeholder_height', 616, $id );

			/**
			 * Filters the display width of the default certificate background image.
			 *
			 * This filter is used by legacy certificates only. If the certificate is utilizing
			 * the block editor the filtered value does not affect the size of the background image as
			 * the image is always set to fill the width and height of the certificate itself.
			 *
			 * @since 2.2.0
			 *
			 * @param int $width          Display width of the image, in pixels.
			 * @param int $certificate_id WP_Post ID of the awarded certificate.
			 */
			$width = apply_filters( 'lifterlms_certificate_background_image_placeholder_width', 800, $id );

		} else {

			list( $src, $width, $height ) = wp_get_attachment_image_src( $img_id, $size );

			// Denote it's not the default image in the return.
			$is_default = false;

			/**
			 * Filters the image source of the certificate background image.
			 *
			 * @since 2.2.0
			 *
			 * @param string $src            The image source url.
			 * @param int    $certificate_id WP_Post ID of the awarded certificate.
			 */
			$src = apply_filters( 'lifterlms_certificate_background_image_src', $src, $id );

			/**
			 * Filters the display height of the certificate background image.
			 *
			 * This filter is used by legacy certificates only. If the certificate is utilizing
			 * the block editor the filtered value does not affect the size of the background image as
			 * the image is always set to fill the width and height of the certificate itself.
			 *
			 * @since 2.2.0
			 *
			 * @param int $height         Display height of the image, in pixels.
			 * @param int $certificate_id WP_Post ID of the awarded certificate.
			 */
			$height = apply_filters( 'lifterlms_certificate_background_image_height', $height, $id );

			/**
			 * Filters the display width of the certificate background image.
			 *
			 * This filter is used by legacy certificates only. If the certificate is utilizing
			 * the block editor the filtered value does not affect the size of the background image as
			 * the image is always set to fill the width and height of the certificate itself.
			 *
			 * @since 2.2.0
			 *
			 * @param int $width          Display width of the image, in pixels.
			 * @param int $certificate_id WP_Post ID of the awarded certificate.
			 */
			$width = apply_filters( 'lifterlms_certificate_background_image_width', $width, $id );

		}

		return compact( 'src', 'width', 'height', 'is_default' );

	}


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.