• How can I disable email requirement on registration. We don’t plane ot use it, since we want users to be anonymous (and emails are identifying information). Passowrd recovery will be handled manually.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could create a custom HTML sign-up form and set up a information-catching function.

    Your form could be something like this:

    <form>
    Username:
    <input type="text" name="username">
    <input type="submit" value="Submit">
    </form>

    Then in your functions.php of your theme use the following code to “catch the response”

    function my_prefix_catch_custom_signup_form(){
    
        if ( isset( $_POST['username'] )){
    
    		$username = sanitize_user( $_POST['username'] );
    
    		//This will create a fake email address for the user at your own domain. Something like '[email protected]'
    		$fake_user_email = $username . '@' . get_bloginfo( 'wpurl' );
    
    		$user_id = username_exists( $username );
    		if ( !$user_id and email_exists($fake_user_email) == false ) {
    			$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
    			$user_id = wp_create_user( $username, $random_password, $username . '@' . get_bloginfo( 'wpurl' )  );
    		} else {
    			$random_password = __('User already exists.  Password inherited.');
    		}
    
    	}
    
    }
    add_action( 'init', 'my_prefix_catch_custom_signup_form');

    Safety Tip: Make sure you always user proper sanitization when accepting user information through a custom form.

    Thread Starter Dani-Girl

    (@dani-girl)

    so that would mean creating a page? where would rthis code reside?

    You’d put the first code on a page (maybe using a page template).

    The second code you’d put in your functions.php file.

    To make a page template follow this:
    https://codex.www.ads-software.com/Page_Templates

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disable Email requirement’ is closed to new replies.