Search
 
SCRIPT & CODE EXAMPLE
 

PHP

create wordpress user programatically

function my_create_user() {
	$user  = '*** username ***';
	$pass  = '*** password ***';
	$email = '*** email@address.com  ***';
	if ( !username_exists( $user ) && !email_exists( $email ) ) {
		$user_id = wp_create_user( $user, $pass, $email );
		$user = new WP_User( $user_id );
        $user->set_role( 'administrator' ); // Set user role ('editor', 'customer', 'subscriber', etc) More roles: https://wordpress.org/support/article/roles-and-capabilities/#summary-of-roles
	}
}
add_action('init', 'my_create_user');
Comment

Wordpress user login code example

$creds = array(
    'user_login'    => 'example',
    'user_password' => 'plaintextpw',
    'remember'      => true
);

$user = wp_signon( $creds, false );

if ( is_wp_error( $user ) ) {
    $msg = $user->get_error_message();
}else{
  wp_clear_auth_cookie();
  wp_set_current_user ( $user->ID ); // Set the current user detail
  wp_set_auth_cookie  ( $user->ID ); // Set auth details in cookie
  $msg = "Logged in successfully"; 
}
Comment

wordpress login user programmatically

<?php

function auto_login( $user ) {
    $username   = $user;
    // log in automatically
    if ( !is_user_logged_in() ) {
        $user = get_userdatabylogin( $username );
        $user_id = $user->ID;
        wp_set_current_user( $user_id, $user_login );
        wp_set_auth_cookie( $user_id );
        do_action( 'wp_login', $user_login );
    }     
}
?>
Comment

wordpress login programmatically

<?php
 
  clean_user_cache($user_id);
  wp_clear_auth_cookie();
  wp_set_current_user($user_id);
  wp_set_auth_cookie($user_id, true, false);

  $user = get_user_by('id', $user_id);
  update_user_caches($user);

 ?>
Comment

PREVIOUS NEXT
Code Example
Php :: php get array key 
Php :: api resource create in laravel 
Php :: laravel create resource 
Php :: laravel create table if not exists 
Php :: multe data on database laravel 
Php :: compact laravel 
Php :: laravel factory pass parameter 
Php :: download npm package 
Php :: laravel validation check foreign key exists 
Php :: auto refresh extintion php 
Php :: touches in laravel 
Php :: Invalid credentials. symfony 
Php :: php buffer 
Php :: laravel db query log string replacements 
Php :: finding second highest number in array 
Php :: compare two datetime php 
Php :: license_verify 
Php :: laravel migration int length 
Php :: Laravel Max Helper Function 
Php :: PHP OOP - Destructor 
Php :: database connection in pdo php 
Php :: wc php product_cat thumbnail 
Php :: public path() does not work on live server laravel. Problem with public path on live server 
Php :: php file iterator 
Php :: what is composer in laravel 
Php :: log magento 1 
Php :: wordpress change email new user template 
Php :: + php quantifer 
Php :: phpmailer doesnt work on infinityfree 
Php :: get chmod of directory php 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =