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::can_process( string $type, int $user_id, int $template_id, string $related_id = '', null|int $engagement_id = null )
Create a new earned achievement or certificate.
Description Description
This method is called by handler callback functions run when engagements are triggered.
Before arriving here the input data ($user_id, $template_id, etc…) has already been validated to ensure that it exists and the engagement can be processed using this data.
Parameters Parameters
- $type
-
(string) (Required) The engagement type, either "achievement" or "certificate".
- $user_id
-
(int) (Required) WP_User ID of the student earning the engagement.
- $template_id
-
(int) (Required) WP_Post ID of the template post (llms_achievement or llms_certificate).
- $related_id
-
(string) (Optional) WP_Post ID of the triggering related post (course, lesson, etc...) or an empty string for user registration.
Default value: ''
- $engagement_id
-
(null|int) (Optional) WP_Post ID of the engagement post used to configure the trigger. A
null
value maybe be passed for legacy delayed engagements which were created without an engagement ID or when manually awarding via the admin UI.Default value: null
Return Return
(boolean|WP_Error[]) $can_process An array of WP_Errors or true if the engagement can be processed.
Source Source
File: includes/class-llms-engagement-handler.php
private static function can_process( $type, $user_id, $template_id, $related_id = '', $engagement_id = null ) { /** * Skip engagement processing checks and force engagements to process. * * This filter is used internally to skip running checks for immediate engagements which cannot * suffer from the issues that these checks seek to avoid. * * @since 6.0.0 * * @param boolean $skip_checks Whether or not to skip checks. * @param string $type The engagement type, either "achievement" or "certificate". * @param int $user_id WP_User ID of the student earning the engagement. * @param int $template_id WP_Post ID of the template post (llms_achievement or llms_certificate). * @param string $related_id WP_Post ID of the triggering related post (course, lesson, etc...) or an empty string for user registration. * @param null|int $engagement_id WP_Post ID of the engagement post used to configure the trigger. A `null` value maybe be passed for legacy * delayed engagements which were created without an engagement ID or when manually awarding via the admin UI. * } */ $skip_checks = apply_filters( 'llms_skip_engagement_processing_checks', false, $type, $user_id, $template_id, $related_id, $engagement_id ); if ( $skip_checks ) { return true; } $checks = array(); // User must exist. $user_check = get_userdata( $user_id ) ? true : new WP_Error( 'llms-engagement-check-user--not-found', sprintf( __( 'User "%d" not found.', 'lifterlms' ), $user_id ) ); $checks[] = $user_check; // Template must be published and of the expected post type. $checks[] = self::check_post( $template_id, "llms_{$type}" ); // Check related post (if one is passed). if ( ! empty( $related_id ) ) { $check_related = self::check_post( $related_id ); $checks[] = $check_related; // Check post enrollment if the check passed and there's no user issues. if ( ! is_wp_error( $check_related ) && ! is_wp_error( $user_check ) ) { $checks[] = self::check_post_enrollment( $related_id, $user_id ); } } // Ensure we have an argument to check, engagements created prior to v6.0.0 will not have this argument. if ( ! empty( $engagement_id ) ) { $checks[] = self::check_post( $engagement_id, 'llms_engagement' ); } // Find all the failed checks. $errors = array_values( array_filter( $checks, 'is_wp_error' ) ); /** * Filters whether or not an engagement should be processed immediately prior to it being sent or awarded. * * The dynamic portion of this hook, `{$type}` refers to the type of engagement being processed, either "email", * "certificate", or "achievement". * * @since 6.0.0 * * @param boolean|WP_Error[] $can_process An array of WP_Errors or true if the engagement can be processed. * @param int $user_id WP_User ID of the student earning the engagement. * @param int $template_id WP_Post ID of the template post (llms_achievement or llms_certificate). * @param string $related_id WP_Post ID of the triggering related post (course, lesson, etc...) or an empty string for user registration. * @param null|int $engagement_id WP_Post ID of the engagement post used to configure the trigger. A `null` value maybe be passed for legacy * delayed engagements which were created without an engagement ID or when manually awarding via the admin UI. * } */ return apply_filters( "llms_proccess_{$type}_engagement", count( $errors ) ? $errors : true, $user_id, $template_id, $related_id, $engagement_id ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.0.0 | Introduced. |