0

For starters, I'm aware of the concerns generally brought up by many when someone looks for a way to skip duplicate e-mail checks for creating new user accounts.

However, In my case, I believe the reason for needing this is justified if I can explain it.

I'm building an extensive vendor directory on my site using a membership plugin with public member directory (Ultimate Member). The problem is, Not all vendors are to register an account on their own. There are vendors I'd like to include in our directory purely for their public contact info for other users to search from the directory.

For these vendors whom we can categorize as (unmanaged vendors), I'd like to use some catch-all e-mail such as noreply-vendor@domain.com to register multiple accounts. These accounts will never be logged into, thus making issues with password recovery not an issue. I also cannot create a new e-mail address every single time to add each of these unmanaged vendors, nor can I just use fake e-mail addresses each time due to email bounces.

Up until last week, I was using this plugin called "Multiple Accounts" to allow only a specifically designated e-mail address to be allowed multiple registration.

However, I've moved my site to Multisite, and this plugin seemed to have stopped working.

Upon web search, I've seen some function snippets people have suggested to bypass e-mail checks, but for reasons frowned upon by many, I cannot simply allow any and all e-mails to bypass this. I'd like to create a bypass for only 1 e-mail address (e.g. noreply-vendor@domain.com).

Would this be doable with a snippet for multisite install?

By coding logic, I'm thinking along the lines of If registration email is noreply@domain.com, then allow registration without email duplicate check. All Else standard registration.

I'd appreciate anyone to shed some light into this. Thanks in advance!

  • Have you tried what is described here? – flomei Jan 25 '16 at 8:54
  • Thanks for comment. Yes, I saw that but as i mentioned in the op im looking for a solution that only allows it for 1 specific designated email address. Not for all emails. That snippet looks to allow for all emails right? – A K Jan 25 '16 at 9:04
  • Would this really be a problem? Do you have an open registration or is it closed? – flomei Jan 25 '16 at 9:33
1

Here is another approach in which we can answer the question, here is a small Plugin that adds a Submenupage for "Users", containing a small form where you can enter a username to create the new user with no emailadress.

Additional Error handling allows you to see if the current user already exists, as usernames have to be unique.

Create a add-anonymous-user.php file in your plugins directory, and place this code inside - activate the plugin and voila.

Have fun!

<?php

    /*
    Plugin Name: Add anonymous user
    Description: Add a user with no email adress
    Version:     0.0.1
    Plugin URI:  http://fischi.cc
    Author:      Thomas fischi! Fischer
    Author URI:  https://fischi.cc
    Domain Path: /languages/
    License:     GPL v2 or later

    */


    /* Add a Menu Page */
    add_action( 'admin_menu', 'f711_register_menu_page' );

    function f711_register_menu_page() {

        add_submenu_page( 'users.php', 'Add anonymous User', 'Anon User', 'manage_options', 'anon_user', 'f711_menu_page' );

    }

    // Function to display the input
    function f711_menu_page() {

        echo '<div class="wrapper">';
            //check if form was sent
            f711_check_for_input();
            echo '<h1>' . __( 'Add Anon User', 'aau' ) . '</h1>';
            echo '<h3>' . __( 'Username', 'aau' ) . '</h3>';
            // insert a small form that targets this page
            echo '<form method="POST" action="">';

                echo '<input type="text" placeholder="' . __( 'Insert User Name', 'aau' ) . '" name="anonname" />';
                echo '<input type="submit" value="' . __( 'Create', 'aau' ) . '" />';

            echo '</form>';

        echo '</div>';

    }

    // Function to process the input
    function f711_check_for_input() {

        // do nothing if Form was not sent
        if ( !isset( $_POST['anonname'] ) || $_POST['anonname'] == "" ) return;

        // sanitize the input to avoid security breaches
        $username = sanitize_text_field( $_POST['anonname'] );

        // define the new user
        $args = array(
            'user_login' => $username,
            'user_pass'  => md5( rand( 1000000, 9999999 ) ), //create hash of randomized number as password
            'role'       => 'subscriber'
        );

        // try to insert the user
        $user_id = wp_insert_user( $args );

        // check if everything went coorectly
        if ( !is_wp_error( $user_id ) ) {
            //add a small notice
            echo '<div class="updated"><p>' . __( 'User created', 'aau' ) . ': '  . $username . '</p></div>';
        } else {
            //show error message
            $errors = implode( ', ', $user_id->get_error_messages() );
            echo '<div class="error"><p>' . __( 'Error', 'aau' ) . ': ' . $errors . '</p></div>';
        }

    }
  • thanks for suggestion and the code. I tried this out and tested creating "mytestvendor1" on that form but it tried re-creating my superadmin account. I got new e-mail confirmations of new registered user not with this new account just created, but in the username of the superadmin. It also changed the "Ultimate Member" status of the superadmin from "Admin" to "Member", and resent e-mail verification email to superadmin. – A K Jan 26 '16 at 13:30
  • Should that code be working for multisite install as my sites are? I did see the anon user submenu on each site's pages, but not under the network admin user menu. – A K Jan 26 '16 at 13:32
0

That is not possible in an easy way, as WordPress always checks if the Emailadress is already used.

function email_exists( $email ) {
    if ( $user = get_user_by( 'email', $email) ) {
        return $user->ID;
    }
    return false;
}

This function is also not filterable, so there is no way around in this direction.

What you could do, however, is something much easier just insert the user without an emailadress, as this is not a required field.

$userdata = array(
    'user_login'  =>  'login_name' . rand( 0, 1000 ), // randomize the login to test for multiple users. This is the field where you can insert your usernames.
    'user_pass'   =>  NULL,  // When creating an user, `user_pass` is expected.
    'role'        => 'subscriber' // do not forget to restrict capabilities for those users.
);

$user_id = wp_insert_user( $userdata );

If you REALLY need to have the Emailadress stored with each of those users (I do not see the point in this), you can add it manually to the database. I would highly recommend not to do that.

You can not know how future updates might compromise this.

Anyway, if you like playing with fire:

global $wpdb;

$query = "UPDATE $wpdb->users SET user_email = %s WHERE ID = %d";
$wpdb->get_results( $wpdb->prepare( $query, 'noreply-vendor@domain.com', $user_id ) );

As I mentioned - I really do not see the point in this, as the Emailadress is not used for anything. Have fun however ;)

You can not use this with the WordPress UI - you will have to create a Plugin or something to handle this for you.

  • Thank you. I see your point in not even needing to put in an e-mail address at all for these vendors. I'll be totally on board with that but I wouldn't know how to begin doing this myself. I came across what seems like a relevant post on wordpress.org wordpress.org/support/topic/… but don't understand how to have that function processed. I'd like to enter a unique username each time, but e-mail could be blank, and password randomly generated if possible. Any suggestions? Thank you! – A K Jan 25 '16 at 13:28
  • The easiest way would be to copy the code into functions.php, or create a simple plugin with it. Just be sure it's executed only once. – fischi Jan 25 '16 at 17:01
  • stemming from your earlier guidance, I have posted an answer with a snippet that seems to have a slight issue registering. Could you see if that was in line of what you were suggesting? Thank you. – A K Jan 25 '16 at 17:48
0

There is a function that lets you enter users without any email address at all! If that's what your looking for? Just put this piece of code in your functions.php

    // Remove required email address in user profile
    function remove_empty_email_error( $arg ) {
        if ( !empty( $arg->errors['empty_email'] ) ) 
unset( $arg->errors['empty_email'] ); }
    add_action( 'user_profile_update_errors', 'remove_empty_email_error' );

This while suppress the error message in the user profile and let you enter that user witout any email address.

  • thanks! does this only refer to adding users manually in the backend? would users be able to register two accounts under same email? – A K Jan 25 '16 at 15:31
  • Yes this only refers to adding users through the backend. Not sure what you mean with 2 accounts under same email? – RichyVN Jan 25 '16 at 15:44
  • I was wondering if this snippet would allow users to register on front-end to successfully register multiple times using the same e-mail address (albeit unknowingly), but I'm actually about to try this now and test it out. Thanks will let you know. – A K Jan 25 '16 at 17:21
  • does not work. Cannot add user in the administration area with email field blank. Perhaps because it's multisite. – A K Jan 25 '16 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.