Enable Register forms for Logged-in users

-
97022283_609773649682028_5024484739814260736_n

UM Register form is visible to logged-out or guest users by default. It displays “You are already reigster” for logged-in users and prevents them from using the Register form or use it as a custom form to register a new user.

Here’s a simple custom solution that’s compatible to Ultimate Member 2.0+

Set the form mode to a custom form:

add_filter("um_shortcode_args_filter","um_custom_enable_register_form", 10, 1 );
function um_custom_enable_register_form( $args ){
    $args["mode"] = "custom_register_form";
   return $args;
}

If you want to apply this to specific Register form, you can add the following condition:

if( $args["form_id"] == 123 ){
  $args["mode"] = "custom_register_form";
}

Since we are bypassing the Register form blocker, we need to re-create a custom action hooks for Register form:

add_filter("um_template_load_args","um_custom_template_load_args");
function um_custom_template_load_args( $args ){

	$args['tpl'] = "register";
    $args['mode'] = "register";
	return $args;
}

add_action("um_pre_custom_register_form_shortcode","um_pre_custom_register_form_shortcode");
function um_pre_custom_register_form_shortcode( $args ){
	do_action("um_pre_register_shortcode", $args );
	do_action("um_before_register_form_is_loaded", $args );

}

Add the code to your theme’s function.php file and then visit the Register page once you’ve logged in to see if the Register form will display.

To clear the current user’s details in the custom Register form, add the following code snippet:

add_filter("um_template_load_args","um_custom_template_load_args");
function um_custom_template_load_args( $args ){
   ...
   if( $args["form_id"] == 123 ){ 
      add_filter("um_field_value","um_custom_register_form_clear",10 ,1 );
   }
   ...
}

function um_custom_register_form_clear( $value ){
    return "";
}


    

And here’s the entire code snippets:

add_filter("um_shortcode_args_filter","um_custom_enable_register_form", 10, 1 );
function um_custom_enable_register_form( $args ){
   
   //if( $args["form_id"] == 123 ){  // Apply to specific form only
     $args["mode"] = "custom_register_form";
   //}
   return $args;
}

add_filter("um_template_load_args","um_custom_template_load_args");
function um_custom_template_load_args( $args ){

	$args['tpl'] = "register";
    $args['mode'] = "register";
   
    //if( $args["form_id"] == 123 ){  // Apply to specific form only
    add_filter("um_field_value","um_custom_register_clear_value",10 ,1 );
    //}
	return $args;
}

add_action("um_pre_custom_register_form_shortcode","um_pre_custom_register_form_shortcode");
function um_pre_custom_register_form_shortcode( $args ){
	do_action("um_pre_register_shortcode", $args );
	do_action("um_before_register_form_is_loaded", $args );

}

function um_custom_register_clear_value( $value ){
    return "";
}

That’s all! Let me know if you have any questions in the comment section below! Don’t forget to subscribe to my newsletter for more Ultimate Member development tips and tricks everyweek!

Help me reach other people who need the help
Leave a Response

Leave a Reply

Your email address will not be published. Required fields are marked *