Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_set_current_user [ WordPress Function ]

wp_set_current_user ( $id, $name = '' )
Parameters:
  • (int) $id User ID
  • (string) $name User's username
Uses:
Returns:
  • (WP_User) Current user User object
Defined at:



Changes the current user by ID or name.

Set $id to null and specify a name if you do not know a user's ID.

Some WordPress functionality is based on the current user and not based on the signed in user. Therefore, it opens the ability to edit and perform actions on users who aren't signed in.

Source


<?php
function wp_set_current_user($id$name '') {
    global 
$current_user;

    if ( isset( 
$current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) )
        return 
$current_user;

    
$current_user = new WP_User$id$name );

    
setup_userdata$current_user->ID );

    
do_action('set_current_user');

    return 
$current_user;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics