Filter Uncanny Redemption Codes

ulc_codes_batch_redirect_url

Filters the redirect URL after a batch of codes are processed.

add_filter( 'ulc_codes_batch_redirect_url', $callback, 10, 3 );

Description

Filters the redirect URL after a batch of codes is generated. Developers can modify the URL to redirect users to a different page or add custom query parameters, allowing for flexible post-generation navigation.


Usage

add_filter( 'ulc_codes_batch_redirect_url', 'your_function_name', 10, 3 );

Parameters

$redirect_url (mixed)
This parameter contains the URL to which the user will be redirected after the code generation process is complete.
$group_id (mixed)
This parameter contains the URL to which the user will be redirected after the batch of codes has been generated.
$data (mixed)
This parameter contains the ID of the current batch group for which codes are being generated.

Return Value

The filtered value.


Examples

/**
 * Modifies the redirect URL after a batch of Uncanny LearnDash Codes has been generated.
 *
 * This filter can be used to redirect the user to a different page or add custom
 * query parameters to the success URL. For example, you might want to redirect
 * to a specific report or add tracking information.
 *
 * @param string $redirect_url The default redirect URL.
 * @param int    $group_id     The ID of the code group that was generated.
 * @param array  $data         An array containing data related to the code generation process.
 *
 * @return string The modified redirect URL.
 */
add_filter( 'ulc_codes_batch_redirect_url', function( $redirect_url, $group_id, $data ) {
	// Example: Add a custom message parameter if the group ID is a specific value.
	if ( 123 === $group_id ) {
		$redirect_url = add_query_arg( 'custom_message', 'special_batch_handled', $redirect_url );
	}

	// Example: Always append a timestamp to the redirect URL for cache busting or tracking.
	$redirect_url = add_query_arg( 'timestamp', time(), $redirect_url );

	return $redirect_url;
}, 10, 3 );

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/admin/class-generate-codes.php:368

$inserted                = Database::add_codes_to_batch( $group_id, $codes, $args );
		self::$num_coupons_added = $inserted;


		do_action( 'ulc_codes_group_generated', $group_id, $inserted );
		if ( (int) self::$num_coupons_added === (int) self::$num_codes_requested && empty( self::$rejected_batch_codes ) ) {
			$redirect_url = admin_url( 'admin.php?page=uncanny-learndash-codes' ) . "&msg=success&codes_generated={$inserted}&group_id={$group_id}";
			$redirect_url = apply_filters( 'ulc_codes_batch_redirect_url', $redirect_url, $group_id, $data );
			wp_safe_redirect( $redirect_url );
			exit();
		} else {
			add_action( 'admin_notices', array( __CLASS__, 'success_notice' ) );
		}

		if ( 0 === self::$num_coupons_added ) {


Scroll to Top