We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials

More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsWordPressWordPress Administration

How to create local users in each subdomain

Germany Cloud Servers

This tutorial covers the main steps of how to create local users in each subdomain for WordPress. Since this procedure requires custom WordPress modification, it’s recommended to have at least basic programming skills and latest WordPress backup.

Once we are safe to edit the website, it’s time to go ahead and check the following lines of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
$user_id = username_exists($user_login);
 
 if ( ! $user_id )
    {
         $hostAddress = explode('.',$_SERVER['HTTP_HOST']);
         $user_login .= '_' . $hostAddress[0];
         $user_id = wpmu_create_user($user_login, $password, $user_email);
    }
 else
        $user_already_exists = true;
 
 if ( ! $user_id )
  return new WP_Error('create_user', __('Could not create user'), $signup);

With this basic code entry we will be able to add functionality which allows to create local users for each of the subdomain. The core function of this code is “wpmu_create_user” which is being used for creating users in WordPress multisite installation. As we can see it takes three arguments including user login, password and email address for creating new user. More information about “wpmu_create_user” can be found by visiting WordPress website.

KVM VPS
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (182)

Popular Keywords