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


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


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


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


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

Default value: ''


(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(
				'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(
			array( $template_id, $user_id, $related_id ),

		 * 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(

		if ( true === $is_duplicate ) {
			$is_duplicate = new WP_Error(
				// 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

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.