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.
require('wp-load.php');
//$output variable is set by $_GET
$result = getURLparams($output);
function getURLparams($data){
parse_str($data, $result);
getMethod($result);
}
function getMethod($result){
if($result['method']==='registerUser'){
registerUser($result);
}elseif($result['method']==='updateUser'){
updateUser($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?