What URL do you pass to wp_remote_get to load the body of the current post’s preview?

The URL is okay, what you need to add are cookies that authenticate you as the user who is allowed to see the preview. That is basically sending headers. I would start with the HTTP API (WordPress Codex) looking for a method to add additional HTTP headers and set your cookies.

Otherwise – because probably this is somewhat complicated – you could take a look inside the preview code so to see if you can provide a hook to control access to previews. If possible, you can add some secret parameter to the URL which would allow you to preview any page w/o the need of being logged in (and the need of a nonce as it needs to be provided for preview as well).

The result of either the first or the second approach is quite the same, the only difference would be how to trigger it.

Leave a Comment