Title: adding user via  php
Last modified: August 19, 2016

---

# adding user via php

 *  Resolved [Alvaro](https://wordpress.org/support/users/nicardo/)
 * (@nicardo)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/adding-user-via-php/)
 * i have a multisite which is running fine .I also have a website in php which 
   have a user base.
    I need to make a user in wordpress when someone register in
   my php website. i am trying to write the code for username validation,if this
   works then I can use other wordpress function to create the user.Can anyone help
   me out in finding where I have done wrong in the code. my code is
 *     ```
       <?php
       //the include is working fine
       require_once('D:\wamp/www/d2mail/wp-blog-header.php') ;
   
       //taken this variable for testing purpose
       $user_name="admin" ;
       $password="admin";
       $password=md5($password);
       $email="admin@admin.com";
   
       $user_id = wp_create_user($user_name, $password, $email) ;
       // check if there was an error
       if (is_wp_error($user_id)){
            if (!isset($errhandler)){
                $errhandler= new apperrors() or die ("unable to creat instance of app errors") ;
                            }          $errhandler->add($user_id->get_error_message(),"my_wp_class->add_user") or  die("unable to add record to errors - $user_id");;
   
                   }
   
       ?>
       ```
   
 * I have receiving an error message as
    Fatal error: Call to undefined function
   wp_create_user() in D:\wamp\www\multiregistration\register.php on line 11
 * thank you in advance

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Alvaro](https://wordpress.org/support/users/nicardo/)
 * (@nicardo)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/adding-user-via-php/#post-1825311)
 * i have modified the code a bit
 *     ```
       <?php
       //the include is working fine
       require_once($_SERVER['DOCUMENT_ROOT'].'/multisite/wp-blog-header.php') ;
   
       //taken this variable for testing purpose
       $user_name="admin1" ;
       $password="admin1";
       $password=md5($password);
       $email="admin@admin.com";
   
       $user_id = wp_create_user($user_name, $password, $email) ;
       // check if there was an error
       if (is_wp_error($user_id)){
            if (!isset($errhandler)){
                $errhandler= new apperrors() or die ("unable to creat instance of app errors") ;
                            }          $errhandler->add($user_id->get_error_message(),"my_wp_class->add_user") or  die("unable to add record to errors - $user_id");;
   
                   }
   
       ?>
       ```
   
 * Still getting the same error..it seem wordpress environment is not loading…
    
   Anyone with any solution…
 *  Thread Starter [Alvaro](https://wordpress.org/support/users/nicardo/)
 * (@nicardo)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/adding-user-via-php/#post-1825316)
 * me again
    my issue has been resolved..for those who are looking to run wordpress
   function from external php files..they have to write this 3 lines in the beginning
   of their php file
 *     ```
       define('WP_USE_THEMES', false);
       require_once (dirname (dirname (__FILE__)) . '/websitefoldername/wp-blog-header.php');
       require_once (dirname (dirname (__FILE__)) . '/websitefoldername/wp-includes/registration.php');
       ```
   
 * NOTE
    Please change websitefoldername to your site folder name after this they
   can run any wordpress function.. I am creating users using this technique

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘adding user via php’ is closed to new replies.

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 2 replies
 * 1 participant
 * Last reply from: [Alvaro](https://wordpress.org/support/users/nicardo/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/adding-user-via-php/#post-1825316)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
