Support » Plugin: JSON API » How to login, register and logout user?

Viewing 13 replies - 1 through 13 (of 13 total)
  • I’ve created an authentication class to do this. I’ve sent it to the plug-in author rather than post it here since it is quite long. If anyone would like it I can post it here or email it.

    Moderator Jan Dembowski


    Brute Squad and Volunteer Moderator

    If you want to share the link to that source then please do. But do not encourage people to post email addresses in these forums.

    I’ve created a pastebin here. I’ve tested it and it has worked for me. Your mileage may vary. Please post your comments or suggestions. Hopefully it will be integrated into the main branch and if need be, we can work out any bugs. It doesn’t support multisite (didn’t have time) so that’s one thing that can be done.

    Can you post, documentation or examples on how to use your User Controller. I’m really new to this and trying to test things up. Right now I’m just using curl to test everything and makes sure it works.

    Sure. You will want to go through documentation on the main plugin to get a feel for how it works. Once you do that the following will make more sense.

    BTW I’m only a beginner at curl but I’ll try to give you a few examples.

    The main thing is to know what information to pass to the API. It will either be all in a GET request (in the URL query) or if more info is needed, in the POST data.

    When making a call the Query is appended to the URL to your WP install. So, if your site is at then the query would be appended as, “”.


    The POST information should include:
    log = string
    pwd = string
    rememberme = true or false


    POST data:
    username = string
    email = string


    POST data:
    username = string

    ?json=user/reset_password&action=resetpass&key=” + key + “&login=” + username

    POST data:
    pass1 = string
    pass2 = string

    The user would have received the key in an email when they lost their password or registered for the first time. You must then include their new password in the post.




    When you reset your password or register you or your user receive an email from “”. You can change by uncommenting the lines at the top of the User controller and filling them in with the email and name you want to use. You may have to actually create that mailbox on your server depending on your host.

    /** changing default wordpress email settings. uncomment to set your own email */
    add_filter(‘wp_mail_from’, ‘new_mail_from’);
    add_filter(‘wp_mail_from_name’, ‘new_mail_from_name’);

    function new_mail_from($old) {
    return ‘’;
    function new_mail_from_name($old) {
    return ‘Your Site’;

    It would be nice to have this on the settings page but I ran out of time and you would have to modify the main class which I want to avoid since it is out of my control.

    NOTE: Of course, if your site uses HTTPS rather than HTTP then make your calls are using that.

    Also, when logging in, WordPress creates a set of authentication cookies. I’m not sure if curl supports cookies so it may or may not work.

    Thanks for this really great instructions,

    Just another question, I’m using the user-friendly permalinks, so I’m doing the login like this: but its not working. I’m getting an invalid username.

    And is it possible to login while creating a post?

    Like in one go, Lets say, – and insert the login credentials somewhere there?

    Thanks again for answering my question and I really hope you answer this too. 🙂

    You can’t do both at the same time. You will have to log in first.

    The data that you include in the URL is called query data and is part of a GET method type. For login you must send the login information with a POST method type. I’m not sure what you would change to make it work in cURL but the URL would be “” and then you’d pass the login info via post.

    FYI I’ve uploaded the project to github to make it easier to work on,

    Another question, and this is quite out of topic. I’m really having trouble using the custom_fields arguments, lets say I have a custom field : price. and I want to add a value to price while I create a post?

    Thanks in advance, I created a similar post here but didn’t get any reply, mr. monkeypunch3 is active here. I might as well ask it here.

    Thanks in advance,

    PS: I saw this while searching for authentication stuff for json api.

    and he’s controller can include login credentials during create posts.

    But I think monkeypunch’s controller is better due to security details.

    What? That’s this plugin. You posted a link to the github repository.

    With the user controller I wrote above there’s no way to do both at the same time. You are free to add that functionality in and send me the patch?

    As setting custom fields search this forum. I don’t have the time to find it right now but there’s a patch that allows you to set the value. Here is the code you need to add.

    In models/post.php after this code:

    if (isset($wp_values['ID'])) {
    	$this->id = wp_update_post($wp_values);
    } else {
    	$this->id = wp_insert_post($wp_values);


    // add custom fields
    if ( !empty($values["custom"]) ) {
    	foreach ($values["custom"] as $metakey => $metavalue) {
    		update_post_meta($this->id,$metakey, $metavalue);

    Sir, Can you provide a complete sample of the query?

    I’m using my browser to test and I’m really having trouble logging in and registering. I always get Invalid Username or Username is Empty.

    Can you please help?

    Grasshopper, to really understand how to use this library you need to understand HTTP protocol.

    Your browser can submit GET requests through the URL address bar but not POST requests. You have to create a form to do that and set it to post.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to login, register and logout user?’ is closed to new replies.