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


PHP WP_Http类代码示例

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


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

示例1: post_to_third_party

function post_to_third_party($entry, $form)
{
    $post_url = 'http://thirdparty.com';
    $body = array('first_name' => rgar($entry, '1.3'), 'last_name' => rgar($entry, '1.6'), 'message' => rgar($entry, '3'));
    $request = new WP_Http();
    $response = $request->post($post_url, array('body' => $body));
}
开发者ID:hansstam,项目名称:makerfaire,代码行数:7,代码来源:gf-makerspace-api.php

示例2: socialdiscuss_http_post

function socialdiscuss_http_post($link, $body)
{
    if (!$link) {
        return array(500, 'Invalid Link');
    }
    require_once ABSPATH . WPINC . '/class-snoopy.php';
    $snoop = new Snoopy();
    if ($snoop->submit($link, $body)) {
        if (strpos($snoop->response_code, '200')) {
            $response = $snoop->results;
            return array(200, $response);
        }
    }
    if (!class_exists('WP_Http')) {
        include_once ABSPATH . WPINC . '/class-http.php';
    }
    if (!class_exists('WP_Http')) {
        return array(500, $snoop->response_code);
    }
    $request = new WP_Http();
    $response_full = $request->request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers));
    if (isset($response_full->errors)) {
        return array(500, 'Unknown Error');
    }
    $response_code = $response_full['response']['code'];
    if ($response_code === 200) {
        $response = $response_full['body'];
        return array($response_code, $response);
    }
    $response_msg = $response_full['response']['message'];
    return array($response_code, $response_msg);
}
开发者ID:hypenotic,项目名称:slowfood,代码行数:32,代码来源:social-discussions-utility-fns.php

示例3: ml_send_notification

function ml_send_notification($alert, $sound = true, $badge = NULL, $custom_properties = NULL, $tags = NULL, $remote_identifier = NULL)
{
    global $ml_api_key, $ml_secret_key;
    //push notification only when api key is set
    if (($ml_api_key == NULL || strlen($ml_api_key) < 5) && ($ml_secret_key == NULL || strlen($ml_secret_key) < 5)) {
        return false;
    }
    $notification = array('alert' => $alert);
    if ($sound) {
        $notification['sound'] = $sound;
    }
    if ($badge) {
        $notification['badge'] = $badge;
    }
    if ($custom_properties) {
        $notification['custom_properties'] = $custom_properties;
    }
    if ($tags) {
        $notification['tags'] = $tags;
    }
    $parameters = array('api_key' => $ml_api_key, 'secret_key' => $ml_secret_key, 'notification' => $notification);
    //postID
    if ($remote_identifier) {
        $parameters['remote_identifier'] = "{$remote_identifier}";
    }
    $request = new WP_Http();
    $result = $request->request(MOBILOUD_PUSH_API_PUBLISH_URL, array('method' => 'POST', 'timeout' => 10, 'body' => $parameters));
    return false;
}
开发者ID:a-i-ko93,项目名称:ipl-foodblog,代码行数:29,代码来源:push-tags.php

示例4: jws_fetchUrl

 function jws_fetchUrl($url)
 {
     //Can we use cURL?
     if (is_callable('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 20);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         $feedData = curl_exec($ch);
         curl_close($ch);
         //If not then use file_get_contents
     } elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
         $feedData = @file_get_contents($url);
         //Or else use the WP HTTP API
     } else {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $request = new WP_Http();
         $result = $request->request($url);
         $feedData = $result['body'];
     }
     /*    echo $feedData;
     		exit;*/
     return $feedData;
 }
开发者ID:ICONVI,项目名称:sigmacatweb,代码行数:27,代码来源:core-functions.php

示例5: prli_get_main_message

function prli_get_main_message($message = '', $expiration = 1800)
{
    global $prli_update;
    // Set the default message
    if (empty($message)) {
        $message = __("Get started by <a href=\"?page=pretty-link&action=new\">" . "adding a URL</a> that you want to turn into a pretty link.<br/>" . "Come back to see how many times it was clicked.", 'pretty-link');
    }
    $messages = get_site_transient('_prli_messages');
    // if the messages array has expired go back to the mothership
    if (!$messages) {
        $remote_controller = $prli_update->pro_is_installed_and_authorized() ? 'prlipro' : 'prli';
        $message_mothership = "http://prettylinkpro.com/index.php?controller={$remote_controller}&action=json_messages";
        if (!class_exists('WP_Http')) {
            include_once ABSPATH . WPINC . '/class-http.php';
        }
        $http = new WP_Http();
        $response = $http->request($message_mothership);
        if (isset($response) and is_array($response) and isset($response['body']) and !empty($response['body'])) {
            $messages = json_decode($response['body']);
        } else {
            $messages = array($message);
        }
        set_site_transient("_prli_messages", $messages, $expiration);
    }
    if (empty($messages) or !$messages or !is_array($messages)) {
        return $message;
    } else {
        return $messages[array_rand($messages)];
    }
}
开发者ID:phpwomen,项目名称:combell,代码行数:30,代码来源:models.inc.php

示例6: load_ipn_ips

 /**
  * Load IPN IP List
  * @since 1.1
  * @version 1.0
  */
 public function load_ipn_ips()
 {
     $request = new WP_Http();
     $data = $request->request('http://www.zombaio.com/ip_list.txt');
     $data = explode('|', $data['body']);
     return $data;
 }
开发者ID:socialray,项目名称:surfied-2-0,代码行数:12,代码来源:zombaio.php

示例7: embed_github_gist

/**
 * Gets content from GitHub Gist
 * 
 * @param int $id GitHub Gist ID
 * @param int $ttl How long to cache (in seconds)
 * @param string $bump Bump value to force cache expirey.
 * @param string $file Name of file
 */
function embed_github_gist($id, $ttl = null, $bump = null, $file = null)
{
    $gist = '';
    if (!class_exists('WP_Http')) {
        require_once ABSPATH . WPINC . '/class-http.php';
    }
    $key = embed_github_gist_build_cache_key($id, $bump);
    if (embed_github_gist_bypass_cache() or false === ($gist = get_transient($key))) {
        $http = new WP_Http();
        if (embed_github_gist_prefer_inline_html() and function_exists('json_decode')) {
            $result = $http->request('https://gist.github.com/' . $id . '.json');
            $json = json_decode($result['body']);
            $gist = $json->div;
        } else {
            if (!$file) {
                $file = 'file';
            }
            $result = $http->request('https://gist.github.com/raw/' . $id . '/' . $file);
            $gist = '<script src="https://gist.github.com/' . $id . '.js?file=' . $file . '%5B345%5D" type="text/javascript"></script>';
            $gist .= '<noscript><div class="embed-github-gist-source"><code><pre>';
            $gist .= htmlentities($result['body']);
            $gist .= '</pre></code></div></noscript>';
        }
        unset($result, $http);
        if (!embed_github_gist_bypass_cache()) {
            if (!$ttl) {
                $ttl = EMBED_GISTHUB_DEFAULT_TTL;
            }
            set_transient($key, $gist, $ttl);
        }
    }
    return $gist;
}
开发者ID:rud,项目名称:embed-github-gist,代码行数:41,代码来源:embed-github-gist.php

示例8: genesis_purchase_themes_admin

function genesis_purchase_themes_admin()
{
    ?>
	
<div class="wrap purchase-themes">
	<?php 
    screen_icon('themes');
    ?>
	<h2><?php 
    echo 'Genesis ';
    _e('- Purchase Themes', 'genesis');
    ?>
</h2>
	
	<?php 
    $store = get_transient('genesis-remote-store');
    if (!$store) {
        $request = new WP_Http();
        $store = $request->request('http://www.studiopress.com/store.php');
        set_transient('genesis-remote-store', $store, 60 * 60 * 12);
        // store for 12 hours
    }
    echo $store['body'];
    ?>
	
</div>
<?php 
}
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:28,代码来源:purchase_themes.php

示例9: request

 /**
  * Send an authenticated request to the Urban Airship API. The request is
  * authenticated with the key and secret.
  *
  * @param string  $method      REST method for request
  * @param mixed   $body        Body of request, optional
  * @param string  $uri         URI for this request
  * @param string  $contentType Content type for the request, optional
  * @param int     $version     version # for API, optional, default is 3
  * @param mixed   $request     Request object for this operation (PushRequest, etc)
  *   optional
  * @return \Httpful\associative|string
  * @throws AirshipException
  */
 public function request($method, $body, $uri, $contentType = null, $version = 3, $request = null)
 {
     // As a result of replacing Httpful/Request with WP HTTP,
     // We need to map WP_HTTP response object to Httpful/Request properties as a shim,
     // Action is not necessary but looks a bit cleaner
     add_action('http_api_debug', array($this, 'set_mock_response_object'), 10, 5);
     $headers = array('Authorization' => 'Basic ' . base64_encode("{$this->key}:{$this->secret}"), "Accept" => sprintf(self::VERSION_STRING, $version));
     if (!is_null($contentType)) {
         $headers["Content-type"] = $contentType;
     }
     $request = new \WP_Http();
     /**
      * Logger is disabled in production, so this won't do nothing unless WP_DEBUG is enabled
      *
      * @var [type]
      */
     $logger = UALog::getLogger();
     $logger->debug("Making request", array("method" => $method, "uri" => $uri, "headers" => $headers, "body" => $body));
     // Make a request (fires http_api_debug action that sets object property $mock_response)
     $response = $request->request($uri, array('method' => $method, 'body' => $body, 'headers' => $headers));
     // Check the response for wp_error (that's what WP HTTP throws when there was an issue with request)
     if (is_wp_error($response)) {
         return $response;
     }
     // Check for "successful" WP HTTP request and see if UA returns any non-2xx response code
     if (300 <= $response['response']['code']) {
         throw AirshipException::fromResponse($this->mock_response);
     }
     $logger->debug("Received response", array("status" => $this->mock_response->code, "headers" => $this->mock_response->raw_headers, "body" => $this->mock_response->raw_body));
     // Return mock response object for any components of UA library that make requests
     return $this->mock_response;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:46,代码来源:class.wpairship.php

示例10: do_request

 function do_request($url, $oauth_header, $body_params = '')
 {
     $request = new WP_Http();
     $params = array();
     if ($body_params) {
         foreach ($body_params as $key => $value) {
             $body_params[$key] = $value;
         }
         $params['body'] = $body_params;
     }
     $params['method'] = 'POST';
     $params['headers'] = array('Authorization' => $oauth_header);
     $result = $request->request($url, $params);
     if (!is_wp_error($result)) {
         $this->response_code = $result['response']['code'];
         if ($result['response']['code'] == '200') {
             return $result['body'];
         } else {
             switch ($result['response']['code']) {
                 case 403:
                     $this->duplicate_tweet = true;
                     break;
             }
             $error_message_found = preg_match('#<error>(.*)</error>#i', $result['body'], $matches);
             if ($error_message_found) {
                 $this->error_message = $matches[1];
             }
         }
     }
     return false;
 }
开发者ID:MediehusetNettavisenAS,项目名称:wp-blogsoft,代码行数:31,代码来源:oauth-blogsoft.php

示例11: cff_fetchUrl

function cff_fetchUrl($url)
{
    //Can we use cURL?
    if (is_callable('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
        $feedData = curl_exec($ch);
        curl_close($ch);
        //If not then use file_get_contents
    } elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
        $feedData = @file_get_contents($url);
        //Or else use the WP HTTP API
    } else {
        $request = new WP_Http();
        $response = $request->request($urls, array('timeout' => 60, 'sslverify' => false));
        if (is_wp_error($response)) {
            //Don't display an error, just use the Server config Error Reference message
            echo '';
        } else {
            $feedData = wp_remote_retrieve_body($response);
        }
    }
    return $feedData;
}
开发者ID:treydonovan,项目名称:innergame-anna,代码行数:28,代码来源:connect.php

示例12: kpg_read_file

function kpg_read_file($f, $method = 'GET')
{
    // try this using Wp_Http
    if (!class_exists('WP_Http')) {
        include_once ABSPATH . WPINC . '/class-http.php';
    }
    $request = new WP_Http();
    $parms = array();
    $parms['timeout'] = 10;
    // bump timeout a little we are timing out in google
    $parms['method'] = $method;
    $result = $request->request($f, $parms);
    // see if there is anything there
    if (empty($result)) {
        return '';
    }
    if (is_array($result)) {
        $ansa = $result['body'];
        return $ansa;
    }
    if (is_object($result)) {
        $ansa = 'ERR: ' . $result->get_error_message();
        return $ansa;
        // return $ansa when debugging
        //return '';
    }
    return '';
}
开发者ID:healthcommcore,项目名称:osnap,代码行数:28,代码来源:stop-spam-utils.php

示例13: rest_api_call

 /**
  * Method responsible for making Rest API calls @ Return $response from rest api.
  *
  * @return $response
  */
 public function rest_api_call()
 {
     try {
         if (!class_exists('WP_Http')) {
             include_once ABSPATH . WPINC . '/class-http.php';
         }
         $request = new WP_Http();
         $postfields = $this->getPostfields();
         $header = $this->getHeaders();
         $url = $this->getApiUrl();
         $options = array('headers' => $header, 'method' => $this->method, 'timeout' => ConfigSDK::TIMEOUT);
         if (!is_null($postfields)) {
             $options['body'] = $postfields;
         }
         //SSL PROBLEMS
         $options['sslverify'] = false;
         $result = $request->request($url, $options);
         if (!is_wp_error($result)) {
             $json = $result['body'];
             $response = json_decode($json, true);
             $response_status = $result['response']['code'];
             $this->setLastStatusCode($response_status);
         } else {
             $this->setLastStatusCode(0);
         }
         if ($this->authorization->is_preauthorized_request) {
             $this->authorization->setAccessParams($response);
         }
         return $response;
     } catch (Exception $e) {
         throw new Exception('Failed to send Data in rest_api_call: ' . $e);
     }
 }
开发者ID:acasado86,项目名称:sdk-php,代码行数:38,代码来源:WP_NimbleAPI.php

示例14: getFeed

 /**
  * Gets an instagram feed
  *
  * @param string $username Username
  * @param integer $limit Number of images to return
  * @return array
  */
 protected function getFeed($username = null, $limit = 5)
 {
     if (empty($username)) {
         return array();
     }
     $results = get_transient('InstagramWidget::getFeed');
     if ($results === false) {
         $request = new WP_Http();
         $response = $request->get("http://ink361.com/feed/user/{$username}");
         $results = array();
         if (!is_a($response, 'WP_Error')) {
             try {
                 $resultsXml = new SimpleXMLElement($response['body']);
                 foreach ($resultsXml->channel[0]->item as $node) {
                     // ink361 sends <a href="ink361.com"><img src="image.jpg"></a>
                     try {
                         $imageNode = new DOMDocument();
                         $imageNode->loadHTML($node->description);
                         $img = $imageNode->getElementsByTagName('img');
                         $results[] = $img->item(0)->getAttribute('src');
                         if (count($results) == $limit) {
                             break;
                         }
                     } catch (Exception $e) {
                     }
                 }
                 set_transient('InstagramWidget::getFeed', $results, HOUR_IN_SECONDS);
             } catch (Exception $e) {
             }
         }
     }
     return $results;
 }
开发者ID:spiff888,项目名称:rockharbor,代码行数:40,代码来源:instagram_widget.php

示例15: rpc_call

 /**
  * rpc_call function.
  * 
  * @access public
  * @param string $method. (default: '')
  * @param array $params. (default: array())
  * @return void
  */
 function rpc_call($method = '', $params = array())
 {
     $request = new WP_Http();
     if (function_exists('xmlrpc_encode_request')) {
         $params = xmlrpc_encode_request($method, $params);
     }
     return $request->request($this->getServiceUrl(), array('method' => 'POST', 'body' => $params));
 }
开发者ID:billadams,项目名称:forever-frame,代码行数:16,代码来源:WPSDSoaHelper.php


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