uo_group_signup_before_submission
Fires before a user group signup is submitted, allowing for custom validation or modification.
add_action( 'uo_group_signup_before_submission', $callback, 10, 1 );
Description
Fires before a new member is added to a group via the signup form. Developers can use this hook to perform custom actions, validate data, or modify member information before the user is created or assigned to the group. It runs after the nonce verification.
Usage
add_action( 'uo_group_signup_before_submission', 'your_function_name', 10, 1 );
Examples
/**
* Example of using the uo_group_signup_before_submission hook.
* This function demonstrates how to intercept and modify user registration data
* before it's processed for group signup.
*/
add_action( 'uo_group_signup_before_submission', function() {
// Check if the user has agreed to the terms and conditions.
// This assumes a checkbox with name 'uncanny_group_signup_terms_agree' is present in the form.
if ( ! isset( $_POST['uncanny_group_signup_terms_agree'] ) || 'yes' !== $_POST['uncanny_group_signup_terms_agree'] ) {
// If terms are not agreed to, we can prevent the submission or display an error.
// For this example, we'll add a notice and effectively halt processing by not letting
// the rest of the original function continue in its intended way.
// In a real-world scenario, you might redirect the user with an error message.
if ( function_exists( 'add_notice' ) ) { // Assuming a custom function for notices
add_notice( __( 'You must agree to the terms and conditions to sign up.', 'your-text-domain' ), 'error' );
} else {
// Fallback for basic error handling
error_log( 'User did not agree to terms for group signup.' );
}
// We can't directly stop the original do_action execution, but we can indicate failure.
// The original function would need to check for a flag or perform its own validation.
// For demonstration, we'll set a flag that the original function might check.
// This is a conceptual example, as direct modification of the original function's flow
// from a hook like this without careful design can be tricky.
// A better approach might be to pass data back via the hook if it were a filter.
// Since it's an action, we'd typically rely on the original function having checks.
return; // Exit this callback function
}
// You could also modify other submitted data here.
// For instance, if you wanted to prepend a string to the username.
// Note: This example assumes these POST variables are available and validated later.
if ( isset( $_POST['uncanny_group_signup_user_login'] ) ) {
$_POST['uncanny_group_signup_user_login'] = 'group_' . sanitize_text_field( $_POST['uncanny_group_signup_user_login'] );
}
// If you wanted to add custom meta to the user upon signup.
// This would require the original function to be aware of how to handle custom meta.
// Again, this is an action, so we modify the environment (like $_POST) for the original function to use.
if ( isset( $_POST['uncanny_group_signup_user_email'] ) ) {
// Store a flag for a custom meta field. The main function would need to implement
// the actual meta saving logic.
$_POST['custom_group_signup_meta'] = array(
'source' => 'manual_group_signup',
'timestamp' => current_time( 'mysql' ),
);
}
}, 10, 0 ); // Priority 10, 0 accepted arguments
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/learn-dash-group-sign-up.php:629
/**
* Registration form is submit
*/
public static function uncanny_group_signup_add_new_member() {
if ( filter_has_var( INPUT_POST, 'uncanny_group_signup_user_login' ) && wp_verify_nonce( filter_input( INPUT_POST, 'uncanny_group_signup_register_nonce' ), 'uncanny_group_signup-register-nonce' ) ) {
do_action( 'uo_group_signup_before_submission');
$user_login = sanitize_text_field( filter_input( INPUT_POST, 'uncanny_group_signup_user_login' ) );
$user_email = sanitize_email( filter_input( INPUT_POST, 'uncanny_group_signup_user_email' ) );
$user_first = sanitize_text_field( filter_input( INPUT_POST, 'uncanny_group_signup_user_first' ) );
$user_last = sanitize_text_field( filter_input( INPUT_POST, 'uncanny_group_signup_user_last' ) );
$user_pass = filter_input( INPUT_POST, 'uncanny_group_signup_user_pass' );
$pass_confirm = filter_input( INPUT_POST, 'uncanny_group_signup_user_pass_confirm' );