I try to do some thing with wordpress social login plugin. I need to put steamid to wp_users table. I have to create colum called steamid in wp_users table.
Trying to do it with:
$userdata = array(
'user_login' => $user_login,
'user_email' => $user_email,
'display_name' => $user_login,
'first_name' => $hybridauth_user_profile->firstName,
'last_name' => $hybridauth_user_profile->lastName,
'user_url' => $hybridauth_user_profile->profileURL,
'description' => $hybridauth_user_profile->description,
'steamid' => $user_login,
'user_pass' => wp_generate_password()
);
But nothing, the table column steamid is still empty. What's wrong?
Related
I made a registration form but after the registration I am unable to login into the newly created account. Wordpress says wrong password for this email, what am I doing wrong?
Here is the code:
$userdata = array(
'user_pass' => $password,
'user_nicename' => $company_clean,
'user_email' => $email,
'user_login' => $company_clean,
'display_name' => $company_clean,
'nickname' => $company_clean,
'first_name' => $name,
'last_name' => $last_name,
'rich_editing' => false,
'syntax_highlighting' => false,
'comment_shortcuts' => false,
'user_registered' => date('Y-m-d H:i:s'),
'show_admin_bar_front' => false,
'role' => 'customer',
);
$user_id = wp_insert_user( wp_slash($userdata) );
add_user_meta($user_id, 'company', $company, false);
add_user_meta($user_id, 'primary', '1', false);
add_user_meta($user_id, 'miles', 0, false);
add_user_meta($user_id, 'phone', $phone, false);
if(!term_exists($company, 'customers')){
wp_insert_term(
$company,
'customers'
);
}
wp_redirect(get_home_url() . '/login');
I already tried with and without wp_slash() but the result is the same.
Solved, before registering the new user I was encrypting the password with md5() and then I was using that to register it.
wp_insert_user() does its own encryption so it was a double encrypted password, hence it was impossible for WP to match the entered value, with the messy one stored in the db.
Anyway searching on the web I found out that it is better to use wp_hash_password() rather than md5().
Trying to insert random emails like test''#test.com, etc.. and they are inserted into the database. Shouldn't this be automatically prevented by Active Record?
My query:
$data = array(
'name' => ''.$name.'' ,
'email' => ''.$email.'' ,
'country' => ''.$country.'' ,
'phone' => ''.$phone.'' ,
'compid' => ''.$compID.''
);
$this->db->insert('people', $data);
Where all variables are taken from user POST input, such as
$this->input->post('address')
for address.
shouldn't this be:
$data = array(
'name' => $name,
'email' => $email,
'country' => $country,
'phone' => $phone,
'compid' => $compID
);
$this->db->insert('people', $data);
I have three tables users,roles and role_user I want to insert record on that tables with minimum query using eloquent. My current code of insertation
User::create([
'name' => 'admin',
'email' => 'admin#test.pk',
'password' => bcrypt('admin123'),
]);
//create default roles while installation of application
$roles = array(
array('name' => 'admin', 'display_name' => 'Administrator User', 'description' => 'system admin user'),
array('name' => 'registered', 'display_name' => 'Registered User', 'description' => 'free user')
);
foreach ($roles as $key => $role)
{
Role::create($role);
}
//relation between users and roles
User::find(1)->roles()->attach(1);
In above code i am creating a user then creating two roles then inserting record in pivot table(role_user). I want to know is there any otherway that i insert the record on these table at same time with one eloquent query Or there is anyother better way?
Unfortunately it is not possible to insert rows in more than one table at the same time.
Best what I can think of is that:
$user = User::create([
'name' => 'admin',
'email' => 'admin#test.pk',
'password' => bcrypt('admin123'),
]);
//create default roles while installation of application
$roles = [
['name' => 'admin', 'display_name' => 'Administrator User', 'description' => 'system admin user'],
['name' => 'registered', 'display_name' => 'Registered User', 'description' => 'free user']
];
Role::insert($roles);
//relation between users and roles
$user->roles()->attach(1);
With this example You save two queries:
Laravel calls only one insert query, instead of two when inserting roles;
Laravel does not select User from database - using variable instead;
I have added a new column in wp-user named as twitter_username and its datatype is varchar.
In sign up form I have also added a new field named
as twitter username.
when I signup, I am unable to save that
field's value in "twitter_username" column in wp-user table. i have
tried following code all values are storing in the wp-user table
instead of the "twitter_username".
$new_customer_data = apply_filters('woocommerce_new_customer_data', array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email,
'twitter_username' => $twitter_username,
'role' => 'customer',
'user_url' => 'this is url'
));
$customer_id = wp_insert_user($new_customer_data);
This could work for you
$new_customer_data = array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email,
'role' => 'customer',
);
//Using WP inbuilt function to create users
$user = wp_insert_user($new_customer_data);
//Adding additional data in user meta
add_user_meta($user, 'twitter_username', $twitter_username);
if you can store this twitter_username in usermeta try this code.
update_user_meta( $user_id, 'twitter_username', $twitter_username);
$new_customer_data = apply_filters_ref_array('woocommerce_new_customer_data', array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email,
'twitter_username' => $twitter_username,
'role' => 'customer',
'user_url' => 'this is url'
));
$customer_id = wp_insert_user($new_customer_data);
//On success
if ( ! is_wp_error($customer_id ) ) {
echo "User created : ". $customer_id;
}
I want to create a custom registration for wordpress and I need to create a new custom field for each profile. For example a phone field.
Here's my code
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->username),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
The phone line is my custom field for profile.
It doesn't work, I've tried creating a custom field in the admin user panel, and it works! But I can't insert data to that field phone
function registration()
{
$userdata = array(
'user_login' => esc_attr($this->username),
'phone' => esc_attr($this->phone),
'pre_user_email' => esc_attr($this->email),
'user_pass' => esc_attr($this->password),
'user_url' => esc_attr($this->website),
'first_name' => esc_attr($this->first_name),
'last_name' => esc_attr($this->last_name),
'nickname' => esc_attr($this->nickname),
'description' => esc_attr($this->bio),
);
}
You should add 'phone' string on MySQL db