Please replace the ??? with your data!
[desc]:
Hi everyone,
I have a form to register new users, and it works fine, they get registered, logged in and redirected. I'm also tracking the submissions. Trubble is I want to connect their user id in the wordpress users table with their submission id in the cformssubmissions table so I can display their personal information once they are logged in. I don't really know how to go on from where I am. This is my code;
In the my-functions.php file;
function my_cforms_action($cformsdata) {
$formID = $cformsdata['id'];
$form = $cformsdata['data'];
$villkor = $form['Jag accepterar villkoren'];
$email = $form['Email'];
$password = $form['Losenord'];
if ( $villkor == 'on' ) {
include_once('registrera.php');
$reg = new Registrera();
$good = $reg->addUser($email,$password);
}
}
And the code in registrera.php;
define('WP_USE_THEMES', false);
include('../../../wp-blog-header.php');
require_once( ABSPATH . WPINC . '/registration.php');
class Registrera {
public function addUser($email, $password) {
global $wpdb;
if(username_exists( $email ) || !validate_username( $email ) || !is_email( $email ) || email_exists( $email )) {
return false;
} else {
$user_id = wp_create_user( $email, $password, $email );
wp_new_user_notification($user_id, $password);
$credentials=array('remember'=>true,'user_login'=>$email,'user_password'=>$password);
do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password']));
$user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
wp_set_auth_cookie($user_id, $credentials['remember']);
do_action('wp_login', $credentials['user_login']);
return true;
}
}
Also I would like to know if there is a way to display an error msg if the function returns false, i.e if the email is already registered.
Please help.
Thank you!
_