LLMS_Engagement_Handler::create_actions( string $type, int $user_id, int $generated_id, string|int|null $related_id = '', int|null $engagement_id = null )

Runs post-creation actions when creating/awarding an achievement or certificate to a user.


Parameters Parameters

$type

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

$user_id

(int) (Required) WP_User ID of the student who earned the engagement.

$generated_id

(int) (Required) WP_Post ID of the generated engagement post.

$related_id

(string|int|null) (Optional) WP_Post ID of the related post triggering generation, an empty string (in the event of a user registration trigger) or null if not supplied.

Default value: ''

$engagement_id

(int|null) (Optional) WP_Post ID of the engagement post used to configure engagement triggering.

Default value: null


Top ↑

Return Return

(void)


Top ↑

Source Source

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

	public static function create_actions( $type, $user_id, $generated_id, $related_id = '', $engagement_id = null ) {

		// I think this should be removed but there's a lot of places where queries to _certificate_earned or _achievement_earned exist and it's the documented way of retrieving this data.
		// Internally we should switch to stop relying on this and figure out a way to phase out the usage of the user postmeta data but for now I think we'll continue storing it.
		llms_update_user_postmeta(
			$user_id,
			$related_id,
			"_{$type}_earned",
			$generated_id,
			// The earned engagement must be unique if a `$related_id` is present, otherwise it must be not.
			// Manual awarding have no `$related_id`, and if we force the uniquiness we will end up updating always the same earned engagement
			// every time we manually award a new one for the same user.
			(bool) $related_id
		);

		/**
		 * Action run after a student has successfully earned an engagement.
		 *
		 * The dynamic portion of this hook, `{$type}`, refers to the engagement type,
		 * either "achievement" or "certificate".
		 *
		 * @since 1.0.0
		 * @since 6.0.0 Added the `$engagement_id` parameter.
		 *
		 * @param int             $user_id       WP_User ID of the student who earned the engagement.
		 * @param int             $generated_id  WP_Post ID of the generated engagement post.
		 * @param string|int|null $related_id    WP_Post ID of the related post triggering generation, an empty string (in the event of a user registration trigger) or null if not supplied.
		 * @param int|null        $engagement_id WP_Post ID of the engagement post used to configure engagement triggering.
		 */
		do_action(
			"llms_user_earned_{$type}",
			$user_id,
			$generated_id,
			$related_id,
			$engagement_id
		);

	}


Top ↑

User Contributed Notes User Contributed Notes

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