Created
December 31, 2012 13:26
-
-
Save retgef/4419756 to your computer and use it in GitHub Desktop.
Allows you to send the current user auth cookie along with a WP HTTP API remote request. This is useful for storing a page load for analysis in a psuedo-buffer if you are competing with cache plugins that use output buffering.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#Set your current WP install URL | |
$url = 'http://currentwpinstall.com'; | |
#Create cookie string | |
$cookie_string = ''; | |
foreach($_COOKIE as $k => $v) | |
#Assure we are setting the proper string if other cookies are set | |
if(preg_match('/(wordpress_test_cookie|wordpress_logged_in_|wp-settings-1|wp-settings-time-1)/', $k)) | |
$cookie_string .= $k . '=' . urlencode($v) . '; '; | |
#Remove stray delimiters | |
$cookie_string = trim($cookie_string, '; '); | |
#Prep headers | |
$headers = array( | |
'Cookie' => $cookie_string | |
); | |
#Make Request | |
$http = new WP_Http; | |
$response = $http->request($url, array('method' => 'GET', 'headers' => $headers)); | |
#Retrieve Body | |
$body = wp_remote_retrieve_body($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful, 10 years later!