• Resolved rborsari

    (@rborsari)


    I have club members listed in the Participants Database plugin. Members must be in the database and membership must be active before they can register (using User Registration and Membership). I have written the following code and tested it both as a plugin and code snippet. According to error logging (which for easier reading purposes I have removed from the code below), the code is not executing. What am not understanding?

    Thanks.

    //Verify Email Active

    /* Only active members located in Participants Database can register with the  website.

     * 1) Sanitize email

     * 2) Find row in Participants Database containing sanitized email.

     * 3) If row exists, check that membership status is active.

     * 4) If row does not exist or membership status is not active, return error.

    */

    function verify_custom_db_email_active ($errors, $sanitized_user_login, $user_email) {

        global $wpdb;

        $sanitized_email = sanitize_email($user_email);

        $table = $wpdb->vxj2_participants_database; 

        // Query for the email

        $row = $wpdb->get_row(

            $wpdb->prepare ("SELECT membership_status FROM $table WHERE email = %s", $sanitized_email)

        );

        if ($row) { // Check if membership is active

            if ($row->membership !== “Active”) {

                $errors->add ('membership_inactive', __('Your membership is not active.'));

            }

        }  else {  // Email not found in database

            $errors->add('email_not_found', __('Email address not found in our membership database.'));

        }

        return $errors;

    }

    add_filter ('registration_errors', 'verify_custom_db_email_active', 1, 3);
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @rborsari,

    Thank you for reaching out,

    The code you’re currently using:

    add_filter('registration_errors', 'verify_custom_db_email_active', 1, 3);

    is part of WordPress’s default registration process. However, the User Registration & Memebership plugin has its own custom form handling, so this hook doesn’t work with it.

    To add a custom error message that works with this plugin, please use the code below:

    add_filter( 'user_registration_response_array', 'validate_before_login', 10, 3 );function validate_before_login( $errors, $form_data, $form_id ) {
    $your_error = array( 'This is my error' ); // You can change this message as needed
    return array_merge( $errors, $your_error );
    }

    This will display your error message properly when someone submits the form.

    Best regards,

    Thread Starter rborsari

    (@rborsari)

    Thank you for this. One more question: How do I get the given user_email out of the form_data?

    Thread Starter rborsari

    (@rborsari)

    I’ve tried the following with no luck: $user_email = $form_data[‘user_email’];

    Thread Starter rborsari

    (@rborsari)

    Never mind. I found it. $user_email = $form_data[5];

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Getting custom plugin or code snippet to fire.’ is closed to new replies.