Filter uncanny-toolkit-pro

uo_course_completion_setup_parameters

Filters course completion setup parameters before initialization, allowing modification of data based on course and user.

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

Description

Filters the parameters used to generate a course completion certificate. Developers can modify `$setup_parameters` to customize certificate content, such as user details, course information, or certificate printing status, before it's processed. This hook fires during the certificate setup phase.


Usage

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

Parameters

$setup_parameters (mixed)
This parameter contains an array of setup parameters that will be used for course completion, and it is modified by the filter.
$course_id (mixed)
This parameter holds an array of setup parameters, including user and course information, that are passed to the filter for modification.
$user_id (mixed)
This parameter represents the unique identifier of the course for which completion setup is being configured.
$setup_parameters (mixed)
This parameter likely contains the existing setup parameters array which is being modified.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the 'uo_course_completion_setup_parameters' filter.
 * This example adds a custom parameter to the setup for course completion certificates
 * when a specific condition is met, such as the user having completed a prerequisite.
 *
 * @param array $setup_parameters The existing setup parameters for the course completion certificate.
 * @param int   $course_id        The ID of the course.
 * @param int   $user_id          The ID of the user.
 * @param mixed $certificate_post The ID of the certificate post, if available.
 *
 * @return array The modified setup parameters.
 */
add_filter( 'uo_course_completion_setup_parameters', function( $setup_parameters, $course_id, $user_id, $certificate_post ) {
	// Let's assume we have a function to check if a user has completed a prerequisite for this course.
	// Replace this with your actual prerequisite checking logic.
	$has_completed_prerequisite = false;
	if ( function_exists( 'check_course_prerequisite' ) ) {
		$has_completed_prerequisite = check_course_prerequisite( $course_id, $user_id );
	}

	// If the user has completed the prerequisite, add a custom parameter.
	if ( $has_completed_prerequisite ) {
		$setup_parameters['has-prerequisite-met'] = true;
		$setup_parameters['custom-message']       = sprintf(
			__( 'Congratulations, %s! You have met the prerequisites for %s and can now complete your certificate.', 'your-text-domain' ),
			get_user_meta( $user_id, 'first_name', true ),
			get_the_title( $course_id )
		);
	} else {
		$setup_parameters['has-prerequisite-met'] = false;
		$setup_parameters['custom-message']       = sprintf(
			__( 'Please complete the prerequisite for %s before generating your certificate.', 'your-text-domain' ),
			get_the_title( $course_id )
		);
	}

	// You could also modify existing parameters based on conditions.
	// For example, if you wanted to dynamically set the print-certificate status based on something else.
	// $setup_parameters['print-certificate'] = ( $has_completed_prerequisite && ! empty( $certificate_post ) ) ? 1 : 0;

	return $setup_parameters;
}, 10, 4 ); // Priority 10, accepting 4 arguments

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/course-completion-certificate.php:543

public static function setup_parameters( $course_id, $user_id ) {
		$meta             = get_post_meta( $course_id, '_sfwd-courses', true );
		$setup_parameters = array();

		$setup_parameters['userID']            = $user_id;
		$setup_parameters['course-id']         = $course_id;
		$setup_parameters['course-name']       = html_entity_decode( get_the_title( $course_id ) );
		$setup_parameters['print-certificate'] = 0;

		if ( is_array( $meta ) && ! empty( $meta ) && key_exists( 'sfwd-courses_certificate', $meta ) && ! empty( $meta['sfwd-courses_certificate'] ) ) {
			//Setting Certificate Post ID
			$setup_parameters['certificate-post'] = $meta['sfwd-courses_certificate'];
		}

		if ( empty( $setup_parameters['certificate-post'] ) ) {
			return $setup_parameters;
		}

		$setup_parameters['print-certificate'] = 1;

		return apply_filters( 'uo_course_completion_setup_parameters', $setup_parameters, $course_id, $user_id, $setup_parameters['certificate-post'] );
	}

Scroll to Top