I want to post from one WordPress install [SiteA] to another [SiteB] using the http API and cURL.

I have found plenty of JS examples where the auth cookie is loaded into the browser, and then an AJAX call is made from the browser to the API.

I can't find an example doing this from a PHP install using cookies. It should go something like this:

  1. SiteA cURLs SiteB at /wp-login.php and gets a login cookie. Using a user on SiteB's creds. Yes SiteA must therefore be aware of a user on SiteB's plaintext password. I am OK with this.

  2. SiteA stores the login cookie.

  3. SitetA makes another request to SiteB, this time a http POST request containing auth cookies, and a post data form with submission details.

This should be possible right? Anyone know of a code snippet?

  • See the docs for the proper ways to do Authentication: developer.wordpress.org/rest-api/using-the-rest-api/… – Jacob Peattie Sep 2 '18 at 2:06
  • 1
    There aren't any examples of using PHP cURL, just Javascript. The idea there being that you need to be logged in as a user. To do it with PHP cURL [without a browser] you would have to know the user's plaintext password. That's why it wouldn't be a best practice. My app the PHP side knows the plaintext password. In a normal JS flow, the user authenticates, and then a cookie is put into the browser. Subsequent API calls use that cookie. But thare aren't any examples from a PHP install doing API calls with username / password except basic HTTP auth which is insecure. – John Dee Sep 3 '18 at 0:22
  • Normally, you wouldn't want an app knowing or keeping a plaintext password. But that's exactly what I'm doing. – John Dee Sep 3 '18 at 0:23
  • I could use oAuth or Application Passwords, but I don't care about the best practice concept of not keeping passwords in this use case. – John Dee Sep 3 '18 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.