Action uncanny-continuing-education-credits

ceus_after_updated_user_ceu_record

Fires after a user's CEU record has been updated, providing details about the user, course, and CEU value.

add_action( 'ceus_after_updated_user_ceu_record', $callback, 10, 6 );

Description

Fires after a user's CEU record is updated or manually created. Developers can use this hook to perform custom actions like sending notifications, logging changes, or triggering other related processes based on the updated CEU data. Access user information, course details, and completion status via the provided parameters.


Usage

add_action( 'ceus_after_updated_user_ceu_record', 'your_function_name', 10, 6 );

Parameters

$current_user (mixed)
This parameter contains the current user object, which is a `WP_User` object in most contexts.
$is_manual_creation (mixed)
This parameter contains the WordPress user object for the user whose CEU record is being updated.
$completion_date (mixed)
This parameter indicates whether the CEU record was created manually.
$current_course_title (mixed)
This parameter represents a fixed string value 'manual-ceu' to indicate that the CEU record was manually created.
$course_slug (mixed)
This parameter holds the title of the course for which a CEU record was updated.
$ceu_value (mixed)
This parameter contains the CEU value associated with the user's completed course.

Examples

add_action( 'ceus_after_updated_user_ceu_record', 'my_custom_ceu_record_logic', 10, 8 );

/**
 * Example function to demonstrate using the ceus_after_updated_user_ceu_record hook.
 * This function logs the CEU record update and potentially sends a notification.
 *
 * @param WP_User $current_user          The user object for whom the CEU record was updated.
 * @param bool    $is_manual_creation   Whether the CEU record was manually created.
 * @param string  $completion_date      The completion date of the CEU record (e.g., 'YYYY-MM-DD').
 * @param string  $manual_ceu_marker    A marker indicating if this is a manual CEU entry (likely 'manual-ceu').
 * @param string  $current_course_title The title of the course associated with the CEU.
 * @param string  $course_slug          The slug of the course.
 * @param int     $ceu_value            The CEU credit value awarded.
 * @param int     $ceu_id               The ID of the CEU record.
 */
function my_custom_ceu_record_logic( $current_user, $is_manual_creation, $completion_date, $manual_ceu_marker, $current_course_title, $course_slug, $ceu_value, $ceu_id ) {

	// Log the action for debugging or auditing purposes.
	error_log( sprintf(
		'CEU record updated for user ID %d (%s). Course: "%s" (Slug: %s). CEU Value: %d. Completion Date: %s. Manual Entry: %s. CEU Record ID: %d',
		$current_user->ID,
		$current_user->user_login,
		$current_course_title,
		$course_slug,
		$ceu_value,
		$completion_date,
		$is_manual_creation ? 'Yes' : 'No',
		$ceu_id
	) );

	// Example: Send a notification email to the user if it's a manual creation.
	if ( $is_manual_creation ) {
		$user_email = $current_user->user_email;
		$subject = sprintf( __( 'Your CEU Credits Updated for %s', 'your-text-domain' ), $current_course_title );
		$message = sprintf(
			__( 'Hello %s, <br><br>Your manually added CEU record for the course "%s" has been updated. You have earned %d credits. <br><br>Completion Date: %s.', 'your-text-domain' ),
			$current_user->display_name,
			$current_course_title,
			$ceu_value,
			$completion_date
		);
		$headers = array( 'Content-Type: text/html; charset=UTF-8' );

		// In a real scenario, you'd want to check if emails are enabled and use wp_mail().
		// For this example, we'll just simulate sending.
		// wp_mail( $user_email, $subject, $message, $headers );
		error_log( sprintf( 'Simulating sending email notification to %s for CEU update.', $user_email ) );
	}

	// You could also update other user meta, trigger other actions, or sync with external systems here.
	// For instance, update a total CEU count for the user.
	$total_ceu_credits = get_user_meta( $current_user->ID, 'total_ceu_credits', true );
	if ( ! $total_ceu_credits ) {
		$total_ceu_credits = 0;
	}
	// This is a simplified example; you might want to handle updates more robustly to avoid double counting.
	// A better approach might be to recalculate total CEUs from all records after any update.
	// update_user_meta( $current_user->ID, 'total_ceu_credits', (int) $total_ceu_credits + (int) $ceu_value );

}

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:274
src/classes/award-certificate.php:317

//update_user_meta( $current_user->ID, 'ceu_course_' . $completion_date . '_manual-ceu-' . $course_slug, 'manual-ceu' );
			$k = 'ceu_course_' . $completion_date . '_manual-ceu-' . $course_slug;
			$this->ceu_crud->update_usermeta( $current_user->ID, $k, 'manual-ceu' );
			// Keep new record
			$this->ceu_crud->insert_usermeta( $ceu_id, $k, 'manual-ceu' );

			do_action( 'ceus_after_updated_user_ceu_record', $current_user, $is_manual_creation, $completion_date, 'manual-ceu', $current_course_title, $course_slug, $ceu_value );

		} else {

			$insert = array(
				'user_id'          => $current_user->ID,
				'course_id'        => $current_course->ID,
				'credits'          => $ceu_value,


Scroll to Top