WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I write a function that will return the full rendered HTML of a non-public URL on my Wordpress site—a URL that you must be logged in to see, such as a draft? Not just the post content, but the full rendered HTML that a browser would receive, from <!doctype to </html>?

I would normally accomplish something like this with cURL, but in this case, a plain cURL would result in a 404—because the desired page is only accessible if you are a logged-in Wordpress user. I have seen examples of WordPress authentication with cURL, but they all seem to require you to hard-code a username and password, which I would like to avoid because a) it seems insecure, and b) Wordpress users can change their password at any time.

This is what I want to achieve:

function getFullPageHtml( $url ) { // pass in a url (post ID would be fine too)

   // Do something here that does not involve hard-coding a WP username password

   return $html; // a string of the full page's HTML--'<!doctype...etc...</html>'

Is there a different approach that would get me this result without relying on including username and password in the code? For example, using output buffers instead of making a cURL/HTTP request?

share|improve this question
It is possible to use cache plugin, there create a static page. You can use the result. Also it is possible to export via plugin the content of each post, but without the theme, the front end. Is it this, what you mean? – bueltge Jan 23 '14 at 20:06
You really need to rework that question. It's extremely unclear what you're asking – kaiser Jan 23 '14 at 21:32
@kaiser I've rewritten it, attempting to make it more straightforward. How's this version? – supertrue Jan 23 '14 at 23:37
The revision is much better (in my opinion) but under what conditions do you want someone to be allowed to see the page? And why does the ordinary "preview" functionality not work for you? – s_ha_dum Jan 23 '14 at 23:58
It's better as I now understand that you want to have an URL that returns 404 for non logged in visitors, right? What I don't get, is what this has to do with WP HTTP API and auth protocols used for connecting to 3rd party sites and services. – kaiser Jan 24 '14 at 0:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.