Use the wordpress OAuth from PHP without user prompt from credentials, and make API calls

Solution:

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.