Title: wp_get_current_user() function not working under custom endpoint.
Last modified: September 1, 2016

---

# wp_get_current_user() function not working under custom endpoint.

 *  [JamRizzi Technologies](https://wordpress.org/support/users/jamrizzi/)
 * (@jamrizzi)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/wp_get_current_user-function-not-working-under-custom-endpoint/)
 * I cannot get wp_get_current_user() on my custom WordPress endpoint.
 *     ```
       function spinwrite_endpoint() {
         register_rest_route('spinwrite', '/rewriter/', Array(
           'methods' => 'GET',
           'callback' => Array($this, 'rewriter')
         ));
       }
   
       function rewriter( $request ) {
         return wp_get_current_user();
       }
       ```
   
 * When I go to mywebsite.com/wp-json/spinwrite/rewriter when I am logged in, it
   gives me a response as though I’m not logged in.
 * `{"data":{},"ID":0,"caps":[],"cap_key":null,"roles":[],"allcaps":[],"filter":
   null}`
 * Also, I’ve tried other functions that access the user such as . . .
    `is_user_in_role('
   edit_posts');` . . . and WordPress treats me as though I’m logged out and have
   no permissions.
 * This is really important to get working because I can’t secure my endpoint without
   some form of checking who is accessing it.
 * I did try installing the WP REST API v2 plugin, but then my endpoint disappeared
   and when I uninstalled the WP REST API v2 plugin my endpoint was still gone. 
   I had to completely reinstall WordPress just to get it to work again.
 * I don’t want to use an external plugin for my endpoint authentication if I can
   help it anyways because then my plugin is dependant on it.

The topic ‘wp_get_current_user() function not working under custom endpoint.’ is
closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [endpoint](https://wordpress.org/support/topic-tag/endpoint/)
 * [json](https://wordpress.org/support/topic-tag/json/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 0 replies
 * 1 participant
 * Last reply from: [JamRizzi Technologies](https://wordpress.org/support/users/jamrizzi/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/wp_get_current_user-function-not-working-under-custom-endpoint/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
