Filter uncanny-continuing-education-credits

ucec_trigger_ceu_earned_certificate

Filters the CEU certificate triggers when a certificate is earned, allowing modification of the event.

add_filter( 'ucec_trigger_ceu_earned_certificate', $callback, 10, 4 );

Description

This filter hook allows developers to modify the triggers for earning a certificate upon course completion. It fires after certificate triggers are normalized, enabling customization of conditions before the system determines if a certificate should be awarded. Developers can prevent or alter certificate awarding logic by returning false or modifying the `$ceu_certificate_triggers` array.


Usage

add_filter( 'ucec_trigger_ceu_earned_certificate', 'your_function_name', 10, 4 );

Parameters

$current_user (mixed)
This parameter indicates whether the certificate creation is being done manually.
$current_course (mixed)
This parameter contains the current WordPress user object who has earned the certificate.
$completion_date (mixed)
This parameter contains information about the current course that the user has completed.
$ceu_certificate_triggers (mixed)
This parameter contains an array of triggers for awarding a CEU certificate, which is normalized before being used.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Conditionally prevent certificate generation if user is a specific role.
 *
 * This example hook demonstrates how to intercept the certificate earning process
 * and conditionally prevent a certificate from being issued based on user role.
 *
 * @param bool   $earned_certificate   The current status of whether a certificate has been earned (default is true).
 * @param WP_User $current_user       The WP_User object of the current user.
 * @param int    $current_course_id  The ID of the current course. 0 if not a course completion.
 * @param string $completion_date    The date of completion.
 * @param array  $ceu_certificate_triggers The triggers for CEU certificates.
 *
 * @return bool True to proceed with certificate earning, false to prevent it.
 */
add_filter(
	'ucec_trigger_ceu_earned_certificate',
	function ( $earned_certificate, $current_user, $current_course_id, $completion_date, $ceu_certificate_triggers ) {
		// Check if the user has a specific role that should prevent certificate earning.
		// For demonstration, let's assume users with the 'administrator' role should not earn certificates.
		if ( user_can( $current_user->ID, 'administrator' ) ) {
			// If the user is an administrator, prevent certificate earning.
			return false;
		}

		// If the user is not an administrator, allow the default certificate earning process to continue.
		return $earned_certificate;
	},
	10, // Priority
	5  // Accepted args
);

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/award-certificate.php:343
src/classes/award-certificate.php:349

// Create a workable data
		$ceu_certificate_triggers = $this->normalize_triggers( $ceu_certificate_triggers );

		if ( ! $is_manual_creation && null !== $current_course ) {
			// Maybe Trigger certificate for Course Completions
			$this->maybe_trigger_course_completions_certificate( $current_user, $current_course->ID, $completion_date, $ceu_certificate_triggers );
			$earned_certificate = apply_filters( 'ucec_trigger_ceu_earned_certificate', true, $current_user, $current_course->ID, $completion_date, $ceu_certificate_triggers );
			if ( $earned_certificate ) {
				// Maybe Trigger certificate for CEU Completions
				$this->maybe_trigger_ceu_earned_certificate( $current_user, $current_course->ID, $completion_date, $ceu_certificate_triggers );
			}
		} else {
			$earned_certificate = apply_filters( 'ucec_trigger_ceu_earned_certificate', true, $current_user, 0, $completion_date, $ceu_certificate_triggers );
			if ( $earned_certificate ) {


Scroll to Top