1

I have a Wordpress project with the OAuth Server, jSON API User and jSON API plugins enabled, and i get the ID, Key and Secret string using:

php /var/www/mywordpress/wp-cli.phar --url=mydomain.com oauth1 add

Now I need to create/edit/delete users from OUTSIDE Wordpress (from PHP Project).

I read more tutorials to use the OAuth1 to get access token and can call the API with permissions, but the codes allways prompt to the user the login window to get the access permissions.

I need to make all this by the server side, using only PHP (CURL or similar) to get the credentials and make calls to the API.

Any know how, or have any code example to login into wordpress OAuth from pure PHP ?

Thanks

1 Answer 1

1

I was facing a similar issue and solved it with the following approach:

  1. Use Wordpress OAuth Server plug-in instead of the one suggested by the WP REST API docs.
  2. Enable "User Credentials" grant type in the settings.
  3. Follow the directions for using the Postman tool to get the idea of the flow for obtaining the OAuth access token.

I don't have a PHP code sample as I'm working in JavaScript. However, the steps are fairly easy:

  • Issue a POST request to yourserver.com?oauth=token (step 3 in the list above)
  • Append ?access_token=xxxxxx (xxxxxx being the access token) to all subsequent requests to the API endpoints that require privileged access.
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, works perfect using this way. Now my problem its with the Multisite configuration and the API calls, when i call the OAuth and the API, only works for my primary site, secondary sites have not permissions to do noting in the API (message appear "You have not permissions to do that"), i need to test more to solve this now.
can not find "User Credentials". Plugin (free one) also do not have any settings . where this item is?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.