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_Engagement_Handler::dupcheck( string $type, int $user_id, int $template_id, string $related_id = '', int $engagement_id = null )

Check if the engagement for the specified template and related post has already been earned / awarded to a given user.


Parameters Parameters

$type

(string) (Required) Engagement type, either "certificate" or "achievement".

$user_id

(int) (Required) WP_User ID of the user earning the engagement.

$template_id

(int) (Required) WP_Post ID of the template post, either an llms_certificate or an llms_achievement.

$related_id

(string) (Optional) WP_Post ID of the related post or an empty string during user registration.

Default value: ''

$engagement_id

(int) (Optional) WP_Post ID of the llms_engagement post type.

Default value: null


Top ↑

Return Return

(WP_Error|boolean) Returns true if the dupcheck passes otherwise returns an error object.


Top ↑

Source Source

File: includes/class-llms-engagement-handler.php

	private static function dupcheck( $type, $user_id, $template_id, $related_id = '', $engagement_id = null ) {

		$student = llms_get_student( $user_id );

		$query = new LLMS_Awards_Query(
			array(
				'type'          => $type,
				'users'         => $user_id,
				'templates'     => $template_id,
				'related_posts' => $related_id,
				'fields'        => 'ids',
				'no_found_rows' => true,
				'per_page'      => 1,
			)
		);

		$is_duplicate = self::do_deprecated_filter(
			$query->has_results(),
			array( $template_id, $user_id, $related_id ),
			$type,
			"llms_{$type}_has_user_earned",
			"llms_earned_{$type}_dupcheck"
		);

		/**
		 * Filters whether or not the given user has already earned a certificate or achievement.
		 *
		 * The dynamic portion of this hook, `{$type}`, refers to the type of engagement, either
		 * "achievement" or "certificate".
		 *
		 * This filter should return `true` or a `WP_Error` to denote the certificate has already been earned and
		 * `false` to denote that it has not.
		 *
		 * If `true` is returned the default error message will be used.
		 *
		 * @since 6.0.0
		 *
		 * @param boolean $is_duplicate Whether or not the engagement has already been earned.
		 */
		$is_duplicate = apply_filters(
			"llms_earned_{$type}_dupcheck",
			$is_duplicate,
			$user_id,
			$template_id,
			$related_id,
			$engagement_id
		);

		if ( true === $is_duplicate ) {
			$is_duplicate = new WP_Error(
				'llms-engagement--is-duplicate',
				// Translators: %s = the WP_User ID.
				sprintf( __( 'User "%s" has already earned this engagement.', 'lifterlms' ), $user_id ),
				compact( 'type', 'user_id', 'template_id', 'related_id', 'engagement_id' )
			);
		}

		return is_wp_error( $is_duplicate ) ? $is_duplicate : 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.