Advertisement
verygoodplugins

Untitled

Jan 8th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. function wpf_example_auto_login() {
  2.  
  3.     if( ! isset( $_GET['user_id'] ) ) {
  4.         return;
  5.     }
  6.    
  7.     $user_id = sanitize_text_field( $_GET['user_id'] );
  8.  
  9.     if( user_can( $user_id, 'manage_options' ) ) {
  10.         return;
  11.     }
  12.  
  13.     $user = get_user_by( 'id', $user_id );
  14.  
  15.     // Login
  16.     wp_set_current_user( $user_id, $user->user_login );
  17.     wp_set_auth_cookie( $user_id );
  18.     do_action( 'wp_login', $user->user_login, $user );
  19.  
  20. }
  21.  
  22. add_action( 'after_setup_theme', 'wpf_example_auto_login' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement