本文整理汇总了PHP中wp_remote_get函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_get函数的具体用法?PHP wp_remote_get怎么用?PHP wp_remote_get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remote_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: import
/**
*
* @param array $current_import
* @return bool
*/
function import(array $current_import)
{
// fetch the remote content
$html = wp_remote_get($current_import['file']);
// Something failed
if (is_wp_error($html)) {
$redirect_url = get_admin_url(get_current_blog_id(), '/tools.php?page=pb_import');
error_log('\\PressBooks\\Import\\Html import error, wp_remote_get() ' . $html->get_error_message());
$_SESSION['pb_errors'][] = $html->get_error_message();
$this->revokeCurrentImport();
\Pressbooks\Redirect\location($redirect_url);
}
$url = parse_url($current_import['file']);
// get parent directory (with forward slash e.g. /parent)
$path = dirname($url['path']);
$domain = $url['scheme'] . '://' . $url['host'] . $path;
// get id (there will be only one)
$id = array_keys($current_import['chapters']);
// front-matter, chapter, or back-matter
$post_type = $this->determinePostType($id[0]);
$chapter_parent = $this->getChapterParent();
$body = $this->kneadandInsert($html['body'], $post_type, $chapter_parent, $domain);
// Done
return $this->revokeCurrentImport();
}
示例3: plugin_information
/**
* Sends and receives data to and from the server API
*
* @access public
* @since 1.0.0
* @return object $response
*/
public function plugin_information($args)
{
$target_url = $this->create_upgrade_api_url($args);
$apisslverify = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0;
$request = wp_remote_get($target_url, array('timeout' => 50, 'sslverify' => $apisslverify));
// $request = wp_remote_post( MainWP_Api_Manager::instance()->getUpgradeUrl() . 'wc-api/upgrade-api/', array('body' => $args) );
if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) {
return false;
}
$response = unserialize(wp_remote_retrieve_body($request));
/**
* For debugging errors from the API
* For errors like: unserialize(): Error at offset 0 of 170 bytes
* Comment out $response above first
*/
// $response = wp_remote_retrieve_body( $request );
// print_r($response); exit;
if (is_object($response)) {
if (isset($response->package)) {
$response->package = apply_filters('mainwp_api_manager_upgrade_url', $response->package);
}
return $response;
} else {
return false;
}
}
示例4: instagradam_embed_shortcode
function instagradam_embed_shortcode($atts, $content = null)
{
// define main output
$str = "";
// get remote data
$result = wp_remote_get("https://api.instagram.com/v1/media/popular?client_id=3f72f6859f3240c68b362b80c70e3121");
if (is_wp_error($result)) {
// error handling
$error_message = $result->get_error_message();
$str = "Something went wrong: {$error_message}";
} else {
// processing further
$result = json_decode($result['body']);
$main_data = array();
$n = 0;
// get username and actual thumbnail
foreach ($result->data as $d) {
$main_data[$n]['user'] = $d->user->username;
$main_data[$n]['thumbnail'] = $d->images->thumbnail->url;
$n++;
}
// create main string, pictures embedded in links
foreach ($main_data as $data) {
$str .= '<a target="_blank" href="http://instagram.com/' . $data['user'] . '"><img src="' . $data['thumbnail'] . '" alt="' . $data['user'] . ' pictures"></a> ';
}
}
return $str;
}
示例5: get_repository_info
private function get_repository_info()
{
if (is_null($this->github_response)) {
// Do we have a response?
$request_uri = sprintf('https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository);
// Build URI
if ($this->authorize_token) {
// Is there an access token?
$request_uri = add_query_arg('access_token', $this->authorize_token, $request_uri);
// Append it
}
$response = json_decode(wp_remote_retrieve_body(wp_remote_get($request_uri)), true);
// Get JSON and parse it
if (is_array($response)) {
// If it is an array
$response = current($response);
// Get the first item
}
if ($this->authorize_token) {
// Is there an access token?
$response['zipball_url'] = add_query_arg('access_token', $this->authorize_token, $response['zipball_url']);
// Update our zip url with token
}
$this->github_response = $response;
// Set it to our property
}
}
示例6: _manually_load_plugin
function _manually_load_plugin()
{
$host = getenv('ES_HOST');
$host = preg_replace('/(^https:\\/\\/|^http:\\/\\/)/is', '', $host);
$port = getenv('ES_PORT');
if (empty($host)) {
$host = 'localhost';
}
if (empty($port)) {
$port = 9200;
}
define('ES_HOST', $host);
define('ES_PORT', $port);
require dirname(dirname(__FILE__)) . '/wp-elasticsearch.php';
$tries = 5;
$sleep = 3;
do {
$response = wp_remote_get(esc_url(ES_HOST) . ':' . ES_PORT);
if (200 == wp_remote_retrieve_response_code($response)) {
// Looks good!
break;
} else {
printf("\nInvalid response from ES, sleeping %d seconds and trying again...\n", intval($sleep));
sleep($sleep);
}
} while (--$tries);
if (200 != wp_remote_retrieve_response_code($response)) {
exit('Could not connect to Elasticsearch server.');
}
}
示例7: 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);
}
示例8: createFile
function createFile($imgURL)
{
$remImgURL = urldecode($imgURL);
$urlParced = pathinfo($remImgURL);
$remImgURLFilename = $urlParced['basename'];
$imgData = wp_remote_get($remImgURL);
if (is_wp_error($imgData)) {
$badOut['Error'] = print_r($imgData, true) . " - ERROR";
return $badOut;
}
$imgData = $imgData['body'];
$tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()] = tmpfile())));
if (!is_writable($tmp)) {
return "Your temporary folder or file (file - " . $tmp . ") is not witable. Can't upload images to Flickr";
}
rename($tmp, $tmp .= '.png');
register_shutdown_function(create_function('', "unlink('{$tmp}');"));
file_put_contents($tmp, $imgData);
if (!$tmp) {
return 'You must specify a path to a file';
}
if (!file_exists($tmp)) {
return 'File path specified does not exist';
}
if (!is_readable($tmp)) {
return 'File path specified is not readable';
}
// $data['name'] = basename($tmp);
return "@{$tmp}";
}
示例9: _manually_load_plugin
function _manually_load_plugin()
{
$host = getenv('EP_HOST');
if (empty($host)) {
$host = 'http://localhost:9200';
}
define('EP_HOST', $host);
require dirname(__FILE__) . '/../vendor/woocommerce/woocommerce.php';
require dirname(__FILE__) . '/../elasticpress.php';
add_filter('ep_config_mapping', 'ep_test_shard_number');
$tries = 5;
$sleep = 3;
do {
$response = wp_remote_get(EP_HOST);
if (200 == wp_remote_retrieve_response_code($response)) {
// Looks good!
break;
} else {
printf("\nInvalid response from ES, sleeping %d seconds and trying again...\n", intval($sleep));
sleep($sleep);
}
} while (--$tries);
if (200 != wp_remote_retrieve_response_code($response)) {
exit('Could not connect to ElasticPress server.');
}
require_once dirname(__FILE__) . '/includes/functions.php';
}
示例10: constantcontact_submit
function constantcontact_submit()
{
$form_email = $_REQUEST['constantcontact_email'];
if ($form_email) {
$cc_user = get_field('constant_contact_username', 'option');
$cc_pass = get_field('constant_contact_password', 'option');
$cc_group = get_field('constant_contact_group_name', 'option');
if (empty($cc_user) || empty($cc_pass) || empty($cc_group)) {
$message = 'Plugin Settings incomplete';
} else {
if (empty($form_email)) {
$message = 'Email address is required.';
} else {
$cc_url = 'https://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp?' . 'loginName=' . rawurlencode($cc_user) . '&loginPassword=' . rawurlencode($cc_pass) . '&ea=' . rawurlencode($form_email) . '&ic=' . rawurlencode($cc_group);
$response = wp_remote_get($cc_url);
if (is_wp_error($response)) {
$message = 'Could not connect to Constant Contact';
} else {
$rsp = explode("\n", $response['body']);
if (intval($rsp[0])) {
$message = !empty($rsp[1]) ? $rsp[1] : (intval($rsp[0]) == 400 ? __('Constant Contact username/password not accepted') : __('Constant Contact error'));
} else {
$message = get_field('constant_contact_success_message', 'option');
$message = $message ? $message : "Thank you, you've been added to the list!";
$message_type = 'success';
}
}
}
}
if ($message) {
$tabby_cc_param = array('message' => $message, 'message_type' => $message_type ? $message_type : 'error');
wp_localize_script('jquery', 'tabby_cc_param', $tabby_cc_param);
}
}
}
示例11: check_email
public function check_email($data = '')
{
if (empty($this->public_key)) {
return new WP_Error('no_api_key', __('No API key was provided', 'awesome-support'));
}
if (empty($data)) {
if (isset($_POST)) {
$data = $_POST;
} else {
return new WP_Error('no_data', __('No data to check', 'awesome-support'));
}
}
if (!isset($data['email'])) {
return new WP_Error('no_email', __('No e-mail to check', 'awesome-support'));
}
global $wp_version;
$args = array('timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . base64_encode('api:' . $this->public_key)), 'cookies' => array(), 'body' => array('address' => $data['email']), 'compress' => false, 'decompress' => true, 'sslverify' => true, 'stream' => false, 'filename' => null);
$response = wp_remote_get(esc_url($this->endpoint), $args);
$response_code = wp_remote_retrieve_response_code($response);
if (is_wp_error($response)) {
return $response;
}
if (200 != $response_code) {
return new WP_Error($response_code, wp_remote_retrieve_response_message($response));
}
$body = wp_remote_retrieve_body($response);
return $body;
}
示例12: fetch_feed
function fetch_feed($username, $slice = 8)
{
$barcelona_remote_url = esc_url('http://instagram.com/' . trim(strtolower($username)));
$barcelona_transient_key = 'barcelona_instagram_feed_' . sanitize_title_with_dashes($username);
$slice = absint($slice);
if (false === ($barcelona_result_data = get_transient($barcelona_transient_key))) {
$barcelona_remote = wp_remote_get($barcelona_remote_url);
if (is_wp_error($barcelona_remote) || 200 != wp_remote_retrieve_response_code($barcelona_remote)) {
return new WP_Error('not-connected', esc_html__('Unable to communicate with Instagram.', 'barcelona'));
}
preg_match('#window\\.\\_sharedData\\s\\=\\s(.*?)\\;\\<\\/script\\>#', $barcelona_remote['body'], $barcelona_match);
if (!empty($barcelona_match)) {
$barcelona_data = json_decode(end($barcelona_match), true);
if (is_array($barcelona_data) && isset($barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'])) {
$barcelona_result_data = $barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
}
}
if (is_array($barcelona_result_data)) {
set_transient($barcelona_transient_key, $barcelona_result_data, 60 * 60 * 2);
}
}
if (empty($barcelona_result_data)) {
return new WP_Error('no-images', esc_html__('Instagram did not return any images.', 'barcelona'));
}
return array_slice($barcelona_result_data, 0, $slice);
}
示例13: getDownloadUrl
protected function getDownloadUrl()
{
global $wp_filesystem;
$this->skin->feedback('download_envato');
$package_filename = 'js_composer.zip';
$res = $this->fs_connect(array(WP_CONTENT_DIR));
if (!$res) {
return new WP_Error('no_credentials', __("Error! Can't connect to filesystem", 'js_composer'));
}
$username = WPBakeryVisualComposerSettings::get('envato_username');
$api_key = WPBakeryVisualComposerSettings::get('envato_api_key');
$purchase_code = WPBakeryVisualComposerSettings::get('js_composer_purchase_code');
if (empty($username) || empty($api_key) || empty($purchase_code)) {
return new WP_Error('no_credentials', __('Error! Envato username, api key and your purchase code are required for downloading updates from Envato marketplace for the Visual Composer. Visit <a href="' . admin_url('options-general.php?page=wpb_vc_settings&tab=updater') . '' . '">Settings</a> to fix.', 'js_composer'));
}
$json = wp_remote_get($this->envatoDownloadPurchaseUrl($username, $api_key, $purchase_code));
$result = json_decode($json['body'], true);
if (!isset($result['download-purchase']['download_url'])) {
return new WP_Error('no_credentials', __('Error! Envato API error' . (isset($result['error']) ? ': ' . $result['error'] : '.'), 'js_composer'));
}
$result['download-purchase']['download_url'];
$download_file = download_url($result['download-purchase']['download_url']);
if (is_wp_error($download_file)) {
return $download_file;
}
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/js_composer_envato_package';
if (is_dir($upgrade_folder)) {
$wp_filesystem->delete($upgrade_folder);
}
$result = unzip_file($download_file, $upgrade_folder);
if ($result && is_file($upgrade_folder . '/' . $package_filename)) {
return $upgrade_folder . '/' . $package_filename;
}
return new WP_Error('no_credentials', __('Error on unzipping package', 'js_composer'));
}
示例14: getArtistShows
public function getArtistShows($artist)
{
$json = wp_remote_get($this->apiUrl . 'artists/' . $artist . '/events.json?api_version=2.0&app_id=developer-candidate-practical-exam');
$array = json_decode($json['body']);
$shows = $array;
return $shows;
}
示例15: get_notice_json
private function get_notice_json()
{
// get notice data from server
$data = @wp_remote_get($this->server_file, array('sslverify' => false));
if (isset($data) && !empty($data) && !is_wp_error($data) && $data['response']['code'] == 200) {
$data = $data['body'];
// if some data exists
if ($data != '' || !empty($data)) {
if (!empty($this->notice_data)) {
if (strcmp($data, $this->notice_data) == 0) {
// set new cookie for interval value
AvadaRedux_Functions::setCookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/');
// bail out
return;
}
}
update_option('r_notice_data', $data);
$this->notice_data = $data;
// set cookie for three day expiry
setcookie($this->cookie_id, time(), time() + 86400 * $this->interval, '/');
// set unique key for dismiss meta key
update_option($this->cookie_id, time());
}
}
}