当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_remote_request函数代码示例

本文整理汇总了PHP中wp_remote_request函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remote_request函数的具体用法?PHP wp_remote_request怎么用?PHP wp_remote_request使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_remote_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: make_request

 /**
  * Make API request.
  * 
  * @access public
  * @param string $path
  * @param array $options
  * @param bool $return_status (default: false)
  * @param string $method (default: 'GET')
  * @return void
  */
 function make_request($path, $options = array(), $method = 'GET', $return_key = null)
 {
     /* Build base request options string. */
     $request_options = '?format=json&auth_token=' . $this->oauth_token;
     /* Add options if this is a GET request. */
     $request_options .= $method == 'GET' ? '&' . http_build_query($options) : null;
     /* Build request URL. */
     $request_url = $this->api_url . $path . $request_options;
     /* Setup request arguments. */
     $args = array('method' => $method, 'sslverify' => $this->verify_ssl);
     /* Add request options to body of POST and PUT requests. */
     if ($method == 'POST' || $method == 'PUT') {
         $args['body'] = $options;
     }
     /* Execute request. */
     $result = wp_remote_request($request_url, $args);
     /* If WP_Error, throw exception */
     if (is_wp_error($result)) {
         throw new Exception('Request failed. ' . $result->get_error_messages());
     }
     /* Decode JSON. */
     $decoded_result = json_decode($result['body'], true);
     /* If invalid JSON, return original result body. */
     if (json_last_error() !== JSON_ERROR_NONE) {
         return $result['body'];
     }
     /* If return key is set and exists, return array item. */
     if ($return_key && array_key_exists($return_key, $decoded_result)) {
         return $decoded_result[$return_key];
     }
     return $decoded_result;
 }
开发者ID:wp-premium,项目名称:gravityformshipchat,代码行数:42,代码来源:class-hipchat.php

示例2: PATCH

 public static function PATCH($url, $headers = array(), $data = array())
 {
     if (function_exists("wp_remote_request")) {
         return wp_remote_request($url, array("headers" => $headers, "body" => $data));
     }
     return Requests::patch($url, $headers, $data);
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:7,代码来源:Client.php

示例3: request

 /**
  * Override the curl-based function to use baseline WordPress
  */
 protected function request($options)
 {
     if (!$this->api_token) {
         return FALSE;
     }
     //end if
     $url = $this->api_url . $options['function'];
     $args = array('method' => $options['method'], 'user-agent' => $this->useragent, 'headers' => array('Token' => $this->api_token, 'Content-Type' => 'application/json'), 'sslverify' => $this->ssl_verifypeer);
     if ('POST' == $options['method'] || 'PUT' == $options['method']) {
         $args['body'] = json_encode($options['data']);
     }
     //end if
     $res = wp_remote_request(esc_url_raw($url), $args);
     if (is_wp_error($res)) {
         return FALSE;
     }
     //end if
     // the following variables are primarily for debugging purposes
     // Let's utilise the WP Remote functions to retrieve metadata
     $this->request_http_code = wp_remote_retrieve_response_code($res);
     $this->request_info = $res;
     $this->request_url = $url;
     $this->request_response = wp_remote_retrieve_body($res);
     $return = json_decode($this->request_response);
     return $return ?: $this->request_response;
 }
开发者ID:rickalee,项目名称:headlineenvy,代码行数:29,代码来源:wp-optimizely.php

示例4: send_request

 /**
  * Send request with the specified action and parameters
  *
  * @param string $action
  * @param array $parameters
  */
 private function send_request($end_point, $method = 'GET', array $data = array(), $expected_response_code = 200)
 {
     // Request
     $url = self::API_URL . $end_point;
     $response = wp_remote_request($url, array('method' => $method, 'headers' => array('Authorization' => 'Bearer ' . $this->api_key), 'body' => $data));
     // Response code
     $response_code = wp_remote_retrieve_response_code($response);
     if ($expected_response_code != $response_code) {
         // WPCS: loose comparison ok.
         $this->error = new WP_Error('mollie_error', 'Unexpected response code.');
     }
     // Body
     $body = wp_remote_retrieve_body($response);
     $data = json_decode($body);
     if (!is_object($data)) {
         $this->error = new WP_Error('mollie_error', 'Could not parse response.');
         return false;
     }
     // Mollie error
     if (isset($data->error, $data->error->message)) {
         $this->error = new WP_Error('mollie_error', $data->error->message, $data->error);
         return false;
     }
     return $data;
 }
开发者ID:wp-pay-gateways,项目名称:mollie,代码行数:31,代码来源:Client.php

示例5: update

 public function update($body, $path)
 {
     global $wp_version;
     $params = array('api_key' => $this->api_key, 'expires' => time() + 900);
     $path = '/v2/assets/' . $path;
     $params['signature'] = $this->sign_request(array('path' => $path, 'method' => 'PATCH', 'body' => $body), $params);
     foreach ($params as &$param) {
         $param = rawurlencode($param);
     }
     $url = add_query_arg($params, 'https://api.ooyala.com' . $path);
     if ($wp_version >= 3.4) {
         return wp_remote_request($url, array('headers' => array('Content-Type' => 'application/json'), 'method' => 'PATCH', 'body' => $body, 'timeout' => apply_filters('ooyala_http_request_timeout', 10)));
     }
     // Workaround for core bug - http://core.trac.wordpress.org/ticket/18589
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
     curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($curl);
     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array('body' => $response, 'response' => array('code' => $status));
 }
开发者ID:humanmade,项目名称:vip-mu-plugins-public,代码行数:25,代码来源:class-wp-ooyala-backlot-api.php

示例6: get_version_info

 function get_version_info($cache = true)
 {
     $raw_response = get_transient('slideshow_update_info');
     if (!$cache) {
         $raw_response = false;
     }
     if (!$raw_response) {
         $options = array('method' => 'POST', 'timeout' => 20);
         $options['headers'] = array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'User-Agent' => 'WordPress/' . get_bloginfo("version"), 'Referer' => home_url());
         $request_url = SLIDESHOW_MANAGER_URL . 'updates/13/' . $this->get_remote_request_params();
         $raw_response = wp_remote_request($request_url, $options);
         set_transient('slideshow_update_info', $raw_response, 43200);
     }
     if (is_wp_error($raw_response) || 200 != $raw_response['response']['code']) {
         return array("is_valid_key" => "1", "version" => "", "url" => "");
     } else {
         $array = explode("||", $raw_response['body']);
         $url = $array[2];
         //$url = "https://downloads.wordpress.org/plugin/slideshow-gallery.latest-stable.zip";
         $info = array("is_valid_key" => $array[0], "version" => $array[1], "url" => $url, "item_id" => $array[4]);
         if (count($array) == 4) {
             $info["expiration_time"] = $array[3];
         }
         return $info;
     }
 }
开发者ID:networksoft,项目名称:sharesystem.co,代码行数:26,代码来源:class.update.php

示例7: __construct

 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects, 'reject_unsafe_urls' => true);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default WP user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         $res = wp_remote_request($url, $args);
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
     } else {
         $this->error = '';
         $this->success = false;
     }
 }
开发者ID:jospintedjou,项目名称:wordpress,代码行数:31,代码来源:class-feed.php

示例8: http

 function http($url, $method, $postfields = NULL)
 {
     $this->http_info = null;
     // this is never used
     $options = array('method' => $method, 'timeout' => $this->timeout, 'user-agent' => $this->useragent, 'sslverify' => $this->ssl_verifypeer);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $options['body'] = $postfields;
             }
             break;
         case 'DELETE':
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     $response = wp_remote_request($url, $options);
     if (is_wp_error($response)) {
         $this->http_code = null;
         $this->http_header = array();
         return false;
     }
     $this->http_code = $response['response']['code'];
     $this->http_header = $response['headers'];
     return $response['body'];
 }
开发者ID:rmccue,项目名称:TwitterOAuthWP,代码行数:26,代码来源:TwitterOAuthWP.php

示例9: locate

 function locate($ip = null)
 {
     global $_SERVER;
     if (is_null($ip)) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     $host = str_replace('{IP}', $ip, $this->host);
     $host = str_replace('{CURRENCY}', $this->currency, $host);
     $data = array();
     /* Updated this class so it uses wp_remote_request instead of curl */
     $geodata = wp_remote_request($host);
     if (!empty($geodata)) {
         $response = $geodata['body'];
         $data = unserialize($response);
         //set the geoPlugin vars
         $this->ip = $ip;
         $this->city = $data['geoplugin_city'];
         $this->region = $data['geoplugin_region'];
         $this->areaCode = $data['geoplugin_areaCode'];
         $this->dmaCode = $data['geoplugin_dmaCode'];
         $this->countryCode = $data['geoplugin_countryCode'];
         $this->countryName = $data['geoplugin_countryName'];
         $this->continentCode = $data['geoplugin_continentCode'];
         $this->latitude = $data['geoplugin_latitude'];
         $this->longitude = $data['geoplugin_longitude'];
         $this->currencyCode = $data['geoplugin_currencyCode'];
         $this->currencySymbol = $data['geoplugin_currencySymbol'];
         $this->currencyConverter = $data['geoplugin_currencyConverter'];
     }
 }
开发者ID:phanhoanglong2610,项目名称:flowershop,代码行数:30,代码来源:geoplugin.class.php

示例10: send

 /**
  * Send the data to the collection server
  *
  * @since 2.1.0
  * @return array|mixed
  */
 public function send()
 {
     // Set the destination URL.
     $url = 'https://trends.optinmonster.com/api/v1/site';
     // Bring in the data.
     $body = $this->data;
     // Add the site ID to the URL and token to the body if we're updating.
     if ('PUT' == $this->request_type) {
         $url = $url . '/' . $this->auth['id'];
         $body['token'] = $this->auth['token'];
     }
     // JSON encode the body for sending.
     $body = json_encode($body);
     // Setup the request arguments.
     $args = array('method' => $this->request_type, 'headers' => array('Content-Type' => 'application/json', 'Content-Length' => strlen($body)), 'body' => $body);
     // Disable SSL checking.
     add_filter('http_request_args', array($this, 'http_request_args'), 10, 2);
     // Onward!
     $response = wp_remote_request($url, $args);
     // Decode the returned data.
     $returned = json_decode(wp_remote_retrieve_body($response));
     // Save the auth data if it was a first-time request.
     if ('POST' == $this->request_type && property_exists($returned, 'data')) {
         update_option('awesomemotive_auth', (array) $returned->data);
     }
     return $returned;
 }
开发者ID:venturepact,项目名称:blog,代码行数:33,代码来源:reporter.php

示例11: makeRequest

 /**
  * @param string $crowdskoutUrl
  * @param string $type
  *
  * @return array|WP_Error
  */
 protected function makeRequest($crowdskoutUrl, $type)
 {
     $cskt_request = json_encode(array('url' => $this->url, 'topics' => $this->topics));
     /** Send Request to the Crowdskout Database */
     $response = wp_remote_request($crowdskoutUrl, array('method' => $type, 'headers' => array('Content-Type' => 'application/json'), 'body' => $cskt_request));
     return $response;
 }
开发者ID:Elite50,项目名称:crowdskout-wp,代码行数:13,代码来源:topics.php

示例12: remote

 public static function remote($url = FALSE, $post_vars = FALSE, $args = array())
 {
     static $http_response_filtered = false;
     /* Apply GZ filters only once. */
     /**/
     $args = !is_array($args) ? array() : $args;
     /* Disable SSL verifications. */
     $args["sslverify"] = !isset($args["sslverify"]) ? false : $args["sslverify"];
     /**/
     if (!$http_response_filtered && ($http_response_filtered = true)) {
         add_filter("http_response", "c_ws_plugin__qcache_utils_urls::_remote_gz_variations");
     }
     /**/
     if ($url) {
         if (preg_match("/^https/i", $url) && strtolower(substr(PHP_OS, 0, 3)) === "win") {
             add_filter("use_curl_transport", "__return_false", $curl_disabled = 1352);
         }
         /**/
         if ((is_array($post_vars) || is_string($post_vars)) && !empty($post_vars)) {
             $args = array_merge($args, array("method" => "POST", "body" => $post_vars));
         }
         /**/
         $body = wp_remote_retrieve_body(wp_remote_request($url, $args));
         /**/
         if ($curl_was_disabled_by_this_routine_with_1352_priority = $curl_disabled) {
             remove_filter("use_curl_transport", "__return_false", 1352);
         }
         /**/
         return $body;
         /* The body content received. */
     }
     /**/
     return false;
     /* Else return false. */
 }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:35,代码来源:utils-urls.inc.php

示例13: make_request

 /**
  * Make API request.
  * 
  * @access public
  * @param string $action
  * @param array $options (default: array())
  * @param string $method (default: 'GET')
  * @return void
  */
 public function make_request($action = null, $options = array(), $method = 'GET', $return_key = null)
 {
     /* Build request options string. */
     $request_options = $method == 'GET' && !empty($options) ? '?' . http_build_query($options) : '';
     /* Build request URL. */
     $request_url = $this->api_url . $action . $request_options;
     /* Prepare request and execute. */
     $args = array('headers' => $this->request_headers(), 'method' => $method);
     if ($method == 'POST') {
         $args['body'] = json_encode($options);
     }
     $response = wp_remote_request($request_url, $args);
     /* If WP_Error, die. Otherwise, return decoded JSON. */
     if (is_wp_error($response)) {
         die('Request failed. ' . $response->get_error_message());
     } else {
         $response = json_decode($response['body'], true);
         if (isset($response['errors'])) {
             throw new Exception($response['errors'][0]);
         }
         if (isset($response['warnings'])) {
             throw new Exception($response['warnings'][0]);
         }
         return empty($return_key) ? $response : $response[$return_key];
     }
 }
开发者ID:wp-premium,项目名称:gravityformsicontact,代码行数:35,代码来源:class-icontact.php

示例14: __construct

 function __construct($data)
 {
     // This could be a URL, an wp_remote_request() return value,
     // or just some JSON/JSONP in a string.
     if (is_string($data)) {
         // See if it parses.
         $this->text = $data;
         $this->parse();
         if (is_null($this->data)) {
             // Does it look like a URL?
             $bits = parse_url($this->text);
             if (isset($bits['scheme'])) {
                 $this->text = NULL;
                 $this->url = $data;
                 $data = wp_remote_request($this->url);
             }
         }
     }
     if (is_null($this->data) and $this->is_jsonp($data)) {
         // Got a HTTP reply from wp_remote_request
         $this->text = $data['body'];
     } else {
         $this->text = NULL;
     }
     if (!is_null($this->text)) {
         $this->parse();
     }
 }
开发者ID:radgeek,项目名称:occupysandy,代码行数:28,代码来源:sahanageojsonp.class.php

示例15: _purge_content

 /**
  * Purge content
  *
  * @param string $path
  * @param int $type
  * @param string $error
  * @return boolean
  */
 function _purge_content($path, $type, &$error)
 {
     $url = sprintf(W3TC_CDN_EDGECAST_PURGE_URL, $this->_config['account']);
     $args = array('method' => 'PUT', 'user-agent' => W3TC_POWERED_BY, 'headers' => array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => sprintf('TOK:%s', $this->_config['token'])), 'body' => json_encode(array('MediaPath' => $path, 'MediaType' => $type)));
     $response = wp_remote_request($url, $args);
     if (is_wp_error($response)) {
         $error = implode('; ', $response->get_error_messages());
         return false;
     }
     switch ($response['response']['code']) {
         case 200:
             return true;
         case 400:
             $error = __('Invalid Request Parameter', 'w3-total-cache');
             return false;
         case 403:
             $error = __('Authentication Failure or Insufficient Access Rights', 'w3-total-cache');
             return false;
         case 404:
             $error = __('Invalid Request URI', 'w3-total-cache');
             return false;
         case 405:
             $error = __('Invalid Request', 'w3-total-cache');
             return false;
         case 500:
             $error = __('Server Error', 'w3-total-cache');
             return false;
     }
     $error = 'Unknown error';
     return false;
 }
开发者ID:gumbysgoo,项目名称:bestilblomster,代码行数:39,代码来源:Edgecast.php


注:本文中的wp_remote_request函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。