• I want to get the currently logged-in user in the “wp_login’ hook.

    function mineral_child_login_updates() {
        // WP database handler
        global $wpdb, $current_user;
        $current_user = wp_get_current_user();
        $table_name = $wpdb->prefix . "cz_registered_users";
        $wpdb->update( $table_name,
    	array(
    		'user_last_login' => date("Y-m-d H:i:s"),
    	),
    	"WHERE user_login= " . $current_user->user_login
        );
    }
    add_action('wp_login', 'mineral_child_login_updates');

    Using a child theme I put the above function inside functions.php and it works. If I create a separate file for it in another folder that I insert in the functions.php file it doesn’t work, the $current_user properties returning null. What am I doing wrong?
    PS: no problem with the database …

  • The topic ‘Can't get the $current_user object in functions.php included file’ is closed to new replies.