Overview
Uncanny Redemption Codes provides a number of action hooks and filters that allow developers to extend and customize the plugin’s behavior. This reference documents the available hooks, their parameters, and example usage.
Note: No support is provided for the use of developer hooks and filters. Use them at your own risk and always test thoroughly in a staging environment before deploying to production.
Action Hooks
Action hooks allow you to execute custom code at specific points during the code lifecycle — such as before or after a code is redeemed, when a batch is generated, or when access is granted.
uo_codes_after_redeem
Fires after a code has been successfully redeemed by a user. Use this to trigger custom logic after enrollment is complete — for example, logging the redemption, sending a notification, or updating an external system.
/**
* Log code redemptions to an external system.
*
* @param int $user_id The ID of the user who redeemed the code.
* @param string $code The code string that was redeemed.
* @param int $batch_id The batch ID the code belongs to.
*/
add_action( 'uo_codes_after_redeem', function( $user_id, $code, $batch_id ) {
// Example: log the redemption
error_log( sprintf( 'User %d redeemed code %s from batch %d', $user_id, $code, $batch_id ) );
}, 10, 3 );
uo_codes_before_redeem
Fires before a code is redeemed, after validation has passed but before enrollment is processed. Use this to add pre-redemption checks or modify behavior.
/**
* Perform a custom check before code redemption.
*
* @param int $user_id The ID of the user attempting to redeem.
* @param string $code The code string being redeemed.
* @param int $batch_id The batch ID the code belongs to.
*/
add_action( 'uo_codes_before_redeem', function( $user_id, $code, $batch_id ) {
// Custom pre-redemption logic
}, 10, 3 );
uo_codes_access_removed
Fires when a user’s code-based access is removed (e.g., via the [uo_self_remove_access] shortcode or admin action).
/**
* Notify when access is removed.
*
* @param int $user_id The ID of the user whose access was removed.
*/
add_action( 'uo_codes_access_removed', function( $user_id ) {
// Custom logic after access removal
}, 10, 1 );
Filters
Filters allow you to modify data as it passes through the plugin — such as customizing validation messages, modifying the redemption form output, or altering code data before it is saved.
uo_codes_validate_code
Filter the validation result for a code before it is redeemed. Return a WP_Error object to prevent redemption with a custom error message, or return true to allow it.
/**
* Add custom validation before a code can be redeemed.
*
* @param bool|WP_Error $valid Whether the code is valid (true) or an error.
* @param string $code The code string being validated.
* @param int $user_id The user attempting to redeem.
* @return bool|WP_Error
*/
add_filter( 'uo_codes_validate_code', function( $valid, $code, $user_id ) {
// Example: restrict redemption to users with a specific role
$user = get_user_by( 'id', $user_id );
if ( ! in_array( 'subscriber', $user->roles, true ) ) {
return new WP_Error( 'role_mismatch', 'Only subscribers can redeem codes.' );
}
return $valid;
}, 10, 3 );
uo_codes_redemption_message
Filter the success message displayed after a code is successfully redeemed.
/**
* Customize the redemption success message.
*
* @param string $message The default success message.
* @param string $code The code that was redeemed.
* @param int $user_id The user who redeemed the code.
* @return string
*/
add_filter( 'uo_codes_redemption_message', function( $message, $code, $user_id ) {
return 'Welcome! Your code has been applied and your access is now active.';
}, 10, 3 );
uo_codes_error_message
Filter the error message displayed when a code cannot be redeemed (invalid, expired, already used, etc.).
/**
* Customize code error messages.
*
* @param string $message The default error message.
* @param string $error_type The type of error (e.g., 'invalid', 'expired', 'already_redeemed').
* @param string $code The code that failed validation.
* @return string
*/
add_filter( 'uo_codes_error_message', function( $message, $error_type, $code ) {
if ( 'already_redeemed' === $error_type ) {
return 'This code has already been used. Please contact support if you need assistance.';
}
return $message;
}, 10, 3 );
uo_codes_csv_columns
Filter the columns included in the CSV download from the View Codes page. Use this to add custom columns or remove default ones.
/**
* Add a custom column to the CSV download.
*
* @param array $columns The default CSV columns (key => label).
* @return array
*/
add_filter( 'uo_codes_csv_columns', function( $columns ) {
$columns['custom_field'] = 'Custom Field';
return $columns;
} );
uo_codes_csv_row_data
Filter the data for each row in the CSV download. Use alongside uo_codes_csv_columns to populate custom column data.
/**
* Populate data for a custom CSV column.
*
* @param array $row_data The data for the current row.
* @param object $code The code object.
* @return array
*/
add_filter( 'uo_codes_csv_row_data', function( $row_data, $code ) {
$row_data['custom_field'] = get_post_meta( $code->batch_id, 'custom_value', true );
return $row_data;
}, 10, 2 );
uo_codes_form_output
Filter the HTML output of the code redemption form rendered by the [uo_user_redeem_code] shortcode.
/**
* Add a wrapper div around the redemption form.
*
* @param string $html The default form HTML.
* @return string
*/
add_filter( 'uo_codes_form_output', function( $html ) {
return '<div class="custom-redemption-wrapper">' . $html . '</div>';
} );
Template Overrides
In addition to hooks and filters, you can customize the appearance of code forms by overriding template files. Copy the template file from the plugin directory to your theme:
From: wp-content/plugins/uncanny-learndash-codes/templates/
To: wp-content/themes/yourtheme/uncanny-codes/
The copied file will override the default template. See Template Overrides for more details.
Warning: Do not edit template files within the plugin directory, as they will be overwritten on plugin update.