question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Right way to call wp.users().me()

See original GitHub issue

After nearly two weeks of trying to get WP-API working for my simple project/use, I’ve landed here thanks to @kadamwhite. I’m running a simple JS app within a Wordpress page. I want to save data specific to the logged-in user to the database. Using WP-API is ideal for this in my case. I’m nearly there, finally! Except for that bloody infuriating authentication again. I’m accessing draft/private posts.

So, how exactly do I;

function getPosts() {
    //wp.users().auth("USER","PASS").me();
    wp.posts().users().me().context('edit').param('status', 'draft').then(function (posts) {
        console.log(posts);
    });
};

But make sure the current WP User is authenticated? wp.users().me() looks about right, but what is the correct method?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
kadamwhitecommented, Aug 13, 2016

@wblaircox I’d check out register_rest_field to ensure those fields get included in the returned JSON. Hope that helps!

3reactions
kadamwhitecommented, Aug 12, 2016

@wblaircox we’ve got a guide in progress that’ll help you out a lot, I’m slammed with day job rn but will try to get it online within the next day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WordPress User Roles | Inviting Users | WordPress.com Support
This guide will explain how you can invite other contributors to work on your website with you, using the Users area of your...
Read more >
How to Create and Manage Custom WordPress User Roles
2. Create, Edit or Delete WordPress User Roles Manually · add_role(): For adding a custom role. · remove_role(): For removing a custom role....
Read more >
How to Add New Users and Authors to Your WordPress Blog
There are 3 ways to add new users to your WordPress website. You can add users ... The best way to do this...
Read more >
How to get current logged in user using Wordpress Rest Api?
add_action('rest_api_init', function () { register_rest_route( 'custom', '/login', array( 'methods' => 'GET', 'callback' => function(WP_REST_Request $request) { ...
Read more >
How to Edit & Customize User Roles in WordPress
Step 1: Select Users > User Role Editor in the left panel. Step 2: In the right-side button pane, choose Add Role. Step...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found