ulgm_key_status_changed
Fires when a user's key status changes, passing the new status and the key code.
add_action( 'ulgm_key_status_changed', $callback, 10, 2 );
Description
Fires after a product key's status is successfully changed in the database. Developers can use this action to trigger custom logic, such as sending notifications or updating external systems, when a product key's status is modified. It passes the new status code and the key code as arguments.
Usage
add_action( 'ulgm_key_status_changed', 'your_function_name', 10, 2 );
Parameters
-
$code_status(mixed) - This parameter represents the new status of the code.
-
$code(mixed) - This parameter contains the new status of the key, which could be a string or an integer representing the state.
Examples
/**
* Example callback function for the 'ulgm_key_status_changed' action hook.
*
* This function logs a message whenever a code's status is changed.
*
* @param string $code_status The new status of the code (e.g., 'active', 'inactive', 'pending').
* @param string $code The identifier of the code that had its status changed.
*/
function my_ulgm_log_code_status_change( $code_status, $code ) {
// Ensure we have valid parameters before proceeding.
if ( empty( $code_status ) || empty( $code ) ) {
error_log( 'my_ulgm_log_code_status_change: Received invalid parameters. $code_status: ' . print_r( $code_status, true ) . ', $code: ' . print_r( $code, true ) );
return;
}
// Log the status change to the WordPress debug log.
// In a real-world scenario, you might also:
// - Send an email notification to an administrator.
// - Update a meta field for the user associated with the code.
// - Trigger other related actions.
$log_message = sprintf(
'ULGM: Status of code "%s" has been changed to "%s".',
sanitize_text_field( $code ),
sanitize_text_field( $code_status )
);
error_log( $log_message );
}
// Hook the callback function to the 'ulgm_key_status_changed' action.
// The '3' indicates that this callback function accepts 3 arguments (though only 2 are strictly needed for this example).
// This matches the number of arguments passed by the do_action call in the source.
add_action( 'ulgm_key_status_changed', 'my_ulgm_log_code_status_change', 10, 2 );
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/handlers/class-group-management-db-handler.php:580
src/classes/handlers/class-group-management-db-handler.php:674
array( 'code_status' => $code_status ),
array( 'code' => $code ),
array( '%s' ),
array( '%s' )
);
if ( $update ) {
do_action( 'ulgm_key_status_changed', $code_status, $code );
$success = true;
} else {
$success = false;
}
}
if ( null !== $user_id ) {