Support » Plugins » Hacks » Passing current cookies in wp_remote_get to get Draft Post Preview

  • Hello

    I want pass current user cookies in wp_remote_get function to get a Draft Post Preview page content.

    I assume I can do what I want passing the cookies to wp_remote_get function, here in WordPress documentation mention how WordPress stores the cookies but how can I get them taking in care they use a hash value in the cookie name? How I can get the required cookies to pass them to wp_remote_get function?

    More details:

    What I want to do is given a Post ID get the content of the WordPress Post view page and analyse it. For the already published Posts all works fine, but for Draft Posts I get that the page doesn’t exist. Here is the code simplified:

    $post_permalink = get_permalink($post_id);
    $response = wp_remote_get($post_permalink);
    $whole_post_page = $response['body'];

    This code is executed when the owner of the Post is editing it, so the user is already authenticated and the request is for a local Post. How I can accomplish that wp_remote_get returns me the Post Preview page content? as WordPress does when I go to the preview link in my browser.

    Thanks in advanced.

  • The topic ‘Passing current cookies in wp_remote_get to get Draft Post Preview’ is closed to new replies.