I am developing a registration system that will connect our main database from a php website with the database of wordpress.

I would like to use the following functions.

<?php wp_insert_user( $userdata ); ?>    
<?php wp_update_user( $userdata ); ?>
<?php add_user_meta( $user_id, $meta_key, $meta_value, $unique ); ?>
<?php update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); ?>

So far I added the following code to my php file which is located in the root directory of my wordpress installation.

//$output variable is set by $_GET
$result = getURLparams($output);

function getURLparams($data){
    parse_str($data, $result);

function getMethod($result){

function registerUser($data){   
    $userdata = array(
    'user_pass'     =>  $data['password'],
    'user_login'    =>  $data['email'],
    'user_email'    =>  $data['email'], 
    'first_name'    =>  $data['fname'],
    'last_name'     =>  $data['lname']

    $user_id = wp_insert_user( $userdata ) ;

    //On success add meta keys
    if( !is_wp_error($user_id) ) {
        add_user_meta( $user_id, 'telephone', $data['tel'], true );
        add_user_meta( $user_id, 'university', $data['uni_id'], true );
        add_user_meta( $user_id, 'enrollment_year', $data['admission_year'], true);     
        echo '300';


So far the error I get is Call to undefined function wp_insert_user()

What is my mistake?


You need to make the functions available, they are located in wp-includes/user.php. So load the user.php via require e.g. like this:

require( ABSPATH . WPINC . '/user.php' );

But keep in mind, if you need to do that and load wp-load.php manually, then you likely have not done it right. Meaning, you should aim for a solution that is integrated into the WordPress process, so that no manual stuff like that is necessary.

| improve this answer | |
  • Hi ialocin, I added user.php however it kept asking for more files to be added. is there a line or a require file that adds all the functions of wordpress? Some suggest wp-blog-header.php which seems to be old. – Onisiforos May 1 '15 at 19:58
  • @Onisiforos wp-load.php itself is quite far-reaching. The difference in contrast to wp-blog-header.php is minimal, just look at the files. I don't know a one-liner, because I haven't done this in years, since it - as stated - isn't a very good solution. And mostly it is not a must to do it taht way, so I don't. I guess you probably have to trickle-down all the dependencies/files needed. – Nicolai May 2 '15 at 14:22
  • is it a good idea if I make file in my page template in my theme? – Onisiforos May 3 '15 at 9:49

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.