Fetch Post HTML for “Admin Only” page
-
Hi,
I am trying to create a feature that will allow admins to create a PDF of the front-end view of a post while in the admin area. The process is pretty simple.
- Fetch the HTML
- Send the HTML to the PDF maker
Step two works without issue. The problem is on step one. I’m passing in the URL and I’m storing it in $html. I have used each of the following.
$html = file_get_contents($url);
$html = wp_remote_get($url);
and this one (has two steps):
$html_body = wp_remote_post($url); $html = $html_body['body'];
All of these return the HTML for the login page. This is because I want to prevent non-logged in users from accessing the pages on this site. So going to any page, when not logged in, takes you to the login page. What I cannot figure out is how to somehow authenticate that this request is coming from a logged in user. It seems like I should be able to pass some args to one of the functions above that would handle that but I am having a really hard time with it when I Google it. I just get articles on how to password protect pages. Anything that points me in the right direction would be much appreciated.
Oh, and I need the entire HTML for the post, not just the content. So I can’t use
get_content()
.Thanks,
Swani
- The topic ‘Fetch Post HTML for “Admin Only” page’ is closed to new replies.