• Resolved aicomp

    (@aicomp)


    Hi, I’ve added the following code to the functions.php to enable admin approval after the email confirmation. It worked pretty well for a certain time but now it doesn’t work anymore. Can you check the code please what’s wrong? Thanks

    add_action( 'um_after_email_confirmation', 'um_after_email_confirmation_admin_approval', 10, 1 );

    function um_after_email_confirmation_admin_approval( $user_id ) {

    um_fetch_user( $user_id );
    UM()->user()->pending();
    }



    add_action( 'um_submit_form_errors_hook_logincheck', 'my_submit_form_errors_hook_logincheck', 10, 1 );

    function my_submit_form_errors_hook_logincheck( $args ) {

    $user_id = ( isset( UM()->login()->auth_id ) ) ? UM()->login()->auth_id : '';
    um_fetch_user( $user_id );

    $status = um_user( 'account_status' );
    if( $status == 'awaiting_email_confirmation' ) {
    UM()->user()->email_pending();
    um_reset_user();
    exit( wp_redirect( add_query_arg( 'err', esc_attr( 'awaiting_new_email_confirmation' ), UM()->permalinks()->get_current_url() ) ) );
    }
    }

    add_filter( 'um_custom_error_message_handler', 'my_custom_error_message_handler', 999, 2 );

    function my_custom_error_message_handler( $err, $error ) {

    if( $error == 'awaiting_new_email_confirmation' ) {
    return __( 'Your account is awaiting e-mail verification and we have now sent you a new e-mail for verification.', 'ultimate-member' );
    } else {
    return $err;
    }
    }

    /**
    * Custom validation and error message for the E-mail Address field.
    */
    add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 999, 3 );
    function um_custom_validate_user_email_details( $key, $array, $args ) {
    if ( $key == 'user_email' && isset( $args['user_email'] ) ) {
    if ( isset( UM()->form()->errors['user_email'] ) ) {
    unset( UM()->form()->errors['user_email'] );
    }
    if ( empty( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'E-mail Address is required', 'ultimate-member' ) );
    } elseif ( ! is_email( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'The email you entered is invalid', 'ultimate-member' ) );
    } elseif ( email_exists( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'The email you entered is already registered', 'ultimate-member' ) );
    }
    }
    }
    /**
    * Doubled validation and error message for the E-mail Address field.
    */
    add_action( 'um_submit_form_errors_hook', 'confirm_user_email_textbox', 100, 1 );
    function confirm_user_email_textbox( $args ){

    if ( isset( $args['user_email'] ) && isset( $args['confirm_user_email'] ) && $args['confirm_user_email'] != $args['user_email'] ) {
    UM()->form()->add_error( 'user_email', 'Your email addresses are different' );
    UM()->form()->add_error( 'confirm_user_email', 'Your email addresses are different' );
    }
    }
Viewing 13 replies - 1 through 13 (of 13 total)
  • missveronica

    (@missveronicatv)

    @aicomp

    From the UM 2.8-7 release notes:

    Function: UM()->user()->pending(). Use function UM()->common()->users()->set_as_pending( $user_id, $force ) instead.

    https://github.com/ultimatemember/ultimatemember/releases/tag/2.8.7

    Thread Starter aicomp

    (@aicomp)

    See the code below. Unfortunately, the changes didn’t work. I also cleared the cache afterwards.

    add_action( 'um_after_email_confirmation', 'um_after_email_confirmation_admin_approval', 10, 1 );

    function um_after_email_confirmation_admin_approval( $user_id ) {

    um_fetch_user( $user_id );
    UM()->common()->users()->set_as_pending( $user_id, $force );
    }

    add_action( 'um_submit_form_errors_hook_logincheck', 'my_submit_form_errors_hook_logincheck', 10, 1 );

    function my_submit_form_errors_hook_logincheck( $args ) {

    $user_id = ( isset( UM()->login()->auth_id ) ) ? UM()->login()->auth_id : '';
    um_fetch_user( $user_id );

    $status = um_user( 'account_status' );
    if( $status == 'awaiting_email_confirmation' ) {
    UM()->common()->users()->set_as_pending( $user_id, $force );
    um_reset_user();
    exit( wp_redirect( add_query_arg( 'err', esc_attr( 'awaiting_new_email_confirmation' ), UM()->permalinks()->get_current_url() ) ) );
    }
    }

    add_filter( 'um_custom_error_message_handler', 'my_custom_error_message_handler', 999, 2 );

    function my_custom_error_message_handler( $err, $error ) {

    if( $error == 'awaiting_new_email_confirmation' ) {
    return __( 'Your account is awaiting e-mail verification and we have now sent you a new e-mail for verification.', 'ultimate-member' );
    } else {
    return $err;
    }
    }

    /**
    * Custom validation and error message for the E-mail Address field.
    */
    add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 999, 3 );
    function um_custom_validate_user_email_details( $key, $array, $args ) {
    if ( $key == 'user_email' && isset( $args['user_email'] ) ) {
    if ( isset( UM()->form()->errors['user_email'] ) ) {
    unset( UM()->form()->errors['user_email'] );
    }
    if ( empty( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'E-mail Address is required', 'ultimate-member' ) );
    } elseif ( ! is_email( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'The email you entered is invalid', 'ultimate-member' ) );
    } elseif ( email_exists( $args['user_email'] ) ) {
    UM()->form()->add_error( 'user_email', __( 'The email you entered is already registered', 'ultimate-member' ) );
    }
    }
    }
    /**
    * Doubled validation and error message for the E-mail Address field.
    */
    add_action( 'um_submit_form_errors_hook', 'confirm_user_email_textbox', 100, 1 );
    function confirm_user_email_textbox( $args ){

    if ( isset( $args['user_email'] ) && isset( $args['confirm_user_email'] ) && $args['confirm_user_email'] != $args['user_email'] ) {
    UM()->form()->add_error( 'user_email', 'Your email addresses are different' );
    UM()->form()->add_error( 'confirm_user_email', 'Your email addresses are different' );
    }
    }
    missveronica

    (@missveronicatv)

    @aicomp

    Can you explain with more details
    how you want the code snippet to work
    and how it works with current version of UM.

    Thread Starter aicomp

    (@aicomp)

    The code snippet worked in the past. It was needed that the user has to confirm the initial registration (double opt-in). After that the user gets an email being informed that I (admin) will review the registration (registration pending – approval needed). After given approval the user gets a final confirmation of being successfully registered.

    The rest of the code relies on better usability for the user informing if an email address (user) is already registered. This works as expected.

    Now, the manual admin approval step doesn’t work anymore. After the registration the user clicks the confirmation email link and will be redirected to the profile. With that the registration is approved automatically. But I need the manual approval step back.

    missveronica

    (@missveronicatv)

    @aicomp

    Thanks for your detailed explanation.
    I have verified your issue and I’m working on a plugin solution now.

    Thread Starter aicomp

    (@aicomp)

    Thank you

    missveronica

    (@missveronicatv)

    @aicomp

    The plugin solution will use two UM Roles of your choice.
    One Role for the email activation and another Role for the Admin review.
    Plugin will change the User Role after the email activation.
    This will make it easier to manage custom text messages.

    Thread Starter aicomp

    (@aicomp)

    I’ll ask again before we misunderstand each other. Sorry, if you already understood my issue ??

    As far as I know, text messages were not really a problem here. The problem is that by clicking the confirmation link in the first email (double option), the user already has direct access to the website. But actually, he/she should only get access when I manually approve them afterwards.

    So from the process: User registers -> gets double optin email -> clicks link in email -> I see that he/she has clicked the DOI and can approve him -> user gets email that he is approved -> account status Approved

    The bold part is now missing but worked in the past.

    missveronica

    (@missveronicatv)

    @aicomp

    The issue is UM refuses to make a full Admin review for a User where the Role is based on Email activation and that’s why you got a redirect to Login after email activation.

    The custom message is a good proof for this limitation.

    The link to initiate the User Admin review is ignored by UM and you get either email activation custom message or a redirect to the Login page.

    To be safe for future updates in UM the plugin will take control of the second step’s custom message and redirect URL creations.

    missveronica

    (@missveronicatv)

    @aicomp

    You can download and test the “Email Activation and Admin Review” plugin now

    https://github.com/MissVeronica/um-email-activation-admin-review

    • This reply was modified 1 week, 1 day ago by missveronica.
    Thread Starter aicomp

    (@aicomp)

    Hi,

    Thank you. It works great. One question: The code in the functions.php can be deleted as the plugin now provides the functionality, right?

    missveronica

    (@missveronicatv)

    @aicomp

    The code in the functions.php can be deleted

    Yes, these code lines can be removed now.

    add_action( 'um_after_email_confirmation', 'um_after_email_confirmation_admin_approval', 10, 1 );
    
    function um_after_email_confirmation_admin_approval( $user_id ) {
    
        um_fetch_user( $user_id );
        UM()->common()->users()->set_as_pending( $user_id, $force );
    }
    Thread Starter aicomp

    (@aicomp)

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.