ulc_code_characters
Filters the characters used for unique coupon codes before they are generated by the core system.
add_filter( 'ulc_code_characters', $callback, 10, 1 );
Description
Filters the characters used for generating unique license keys. Developers can modify this string to customize the character set, influencing the complexity and appearance of generated codes. The default set includes alphanumeric characters, excluding confusing ones like 'i', 'l', 'o', and '0'.
Usage
add_filter( 'ulc_code_characters', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Custom function to modify the allowed characters for generated codes.
*
* This example removes the character 'l' (lowercase L) from the default set
* to avoid confusion with the number '1'.
*
* @param string $characters The default string of allowed characters.
* @return string The modified string of allowed characters.
*/
add_filter( 'ulc_code_characters', function( $characters ) {
// Remove the lowercase 'l' to avoid confusion with the digit '1'.
$characters = str_replace( 'l', '', $characters );
return $characters;
}, 10, 1 );
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:54
public function __construct() {
self::$chars = apply_filters( 'ulc_code_characters', 'abcdefghjkmnpqrstuvwxyz123456789ABCDEFGHJKLMNPQRSTUVWXYZ' );
self::$manual_code_length = apply_filters( 'ulc_manual_code_length', 30 );
if ( is_admin() ) {
parent::__construct();
self::$courses = LearnDash::get_courses();
self::$groups = LearnDash::get_groups();
}
add_action( 'admin_init', array( $this, 'process_submit' ), 9 );
if ( SharedFunctionality::ulc_filter_has_var( 'msg' ) && 'success' === sanitize_text_field( SharedFunctionality::ulc_filter_input( 'msg' ) ) ) {
add_action( 'admin_notices', array( __CLASS__, 'success_notice' ) );
}
if ( SharedFunctionality::ulc_filter_has_var( 'msg' ) && 'failed' === SharedFunctionality::ulc_filter_input( 'msg' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'failed_notice' ) );
}
}