I had an interesting need to have authenticated admin requests over HTTP. A few different plugins were creating output on admin pages. I needed to capture that output, HTML and all, and save it into PDFs. I’ll save the whole HTML-to-PDF discussion for another day – but what was interesting was figuring out how to serve these HTML pages in an admin request.
There was a lot of moving pieces, so the best way (in my mind) to serve this HTML was over an HTTP request, rather than try to piece together all of the functions and views from each different plugin that were producing the output. Naturally, the following code presented me with a login form.
That was expected. I assumed I would need to pass the cookies in the second parameter of the wp_remote_get() request. I tried the following, expecting it to work:
Doing this gave me an expected error. An ‘http_request_failed’ error with the following text: “Operation timed out after 4 seconds with 0 bytes received”.
Thinking that was odd, I checked out the cookies that were being passed and began tweaking. Removing the PHPSESSID cookie did the trick. Check it out:
Pretty neat. Not the first time I’ve run into this problem, but definitely the most effective way I’ve solved it.
You really saved me a lot of time!! Thanks a lot 🙂