Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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 :: check url parameter if not redirect wordpress plugin 
Php :: php mail() 
Php :: Route pattern cannot reference variable name more than once. laravel 
Php :: login with email or username codeigniter 4 
Php :: Laravel unique with Validation rule 
Php :: php convert path from server url to link 
Php :: how to prevent the Undefined index in php 
Php :: laravel schedule kernel code sample 
Php :: square root 
Php :: eloquent search ignore case 
Php :: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8192 bytes) 
Php :: laravel 8 search with pagination 
Php :: PHP exif_read_data() 
Php :: upload image with watermark in codeigniter 
Php :: * * * * * cd /path-to-your-project && php artisan schedule:run /dev/null 2&1 
Php :: php xpath get all image 
Php :: Redirect to HTTPS & remove www 
Php :: how to empty an array in php 
Php :: laravel php what does compact 
Php :: if else in php 
Php :: post rest drupal 
Php :: php include file for its symlink directory 
Php :: taxonomy-{taxonomy-slug}.php 
Php :: getting routes in middleware laravel 
Php :: country list laravel 
Php :: php vs python speed 
Php :: php array_diff_assoc 
Php :: dynamic variable in php 
Php :: laravel relationship 
Php :: where is cache file in laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =