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


PHP wp_safe_remote_get函数代码示例

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


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

示例1: _retrieve_videos

 /**
  * Load the videos from a specified page. Is partly recursive.
  *
  * @param $url
  *
  * @return array
  */
 public function _retrieve_videos($url)
 {
     $body = wp_remote_retrieve_body(wp_safe_remote_get($url));
     if ('' === $body) {
         return false;
     }
     $dom = new DOMDocument();
     libxml_use_internal_errors(true);
     $dom->loadHTML($body);
     libxml_clear_errors();
     $finder = new DOMXPath($dom);
     $videos = $finder->query('//*[contains(@class, "video-list")]/li');
     $older_videos = $finder->query('//*[contains(@class, "nav-previous")]/a');
     $data = array('videos' => '', 'total_videos' => $videos->length);
     /** @var $reply \DOMNode */
     foreach ($videos as $video) {
         $img = $finder->query('*[contains(@class, "video-thumbnail")]/img', $video)->item(0)->getAttribute('src');
         $a_text = $finder->query('*[contains(@class, "video-description")]/h4/a', $video)->item(0)->nodeValue;
         $a_href = $finder->query('*[contains(@class, "video-description")]/h4/a', $video)->item(0)->getAttribute('href');
         $event = $finder->query('*[contains(@class, "video-description")]/*[contains(@class, "video-events")]/a', $video)->item(0)->nodeValue;
         $description = $finder->query('*[contains(@class, "video-description")]/*[contains(@class, "video-excerpt")]/p', $video)->item(0)->nodeValue;
         preg_match('/^((?:\\S+\\s+){2}\\S+).*/', $description, $matches);
         $description = str_replace('&#8212', '–', $description);
         $date = new DateTime($matches[1]);
         $data['videos'][] = array('title' => $a_text, 'date' => $date->format('Y-m-d'), 'url' => $a_href, 'image' => $img, 'event' => $event, 'description' => $description);
     }
     if ($older_videos->length) {
         $more_videos = $this->_retrieve_videos($older_videos->item(0)->getAttribute('href'));
         $data['videos'] = array_merge($data['videos'], $more_videos['videos']);
         $data['total_videos'] += $more_videos['total_videos'];
     }
     return $data;
 }
开发者ID:Steadroy,项目名称:wptalents,代码行数:40,代码来源:WordPressTv_Collector.php

示例2: _wpsc_get_exchange_rate

function _wpsc_get_exchange_rate($from, $to)
{
    if ($from == $to) {
        return 1;
    }
    $key = "wpsc_exchange_{$from}_{$to}";
    if ($rate = get_transient($key)) {
        return (double) $rate;
    }
    $url = add_query_arg(array('a' => '1', 'from' => $from, 'to' => $to), 'http://www.google.com/finance/converter');
    $url = esc_url_raw(apply_filters('_wpsc_get_exchange_rate_service_endpoint', $url, $from, $to));
    $response = wp_remote_retrieve_body(wp_safe_remote_get($url, array('timeout' => 10)));
    if (has_filter('_wpsc_get_exchange_rate')) {
        return (double) apply_filters('_wpsc_get_exchange_rate', $response, $from, $to);
    }
    if (empty($response)) {
        return $response;
    } else {
        $rate = explode('bld>', $response);
        $rate = explode($to, $rate[1]);
        $rate = trim($rate[0]);
        set_transient($key, $rate, DAY_IN_SECONDS);
        return (double) $rate;
    }
}
开发者ID:ashik968,项目名称:digiplot,代码行数:25,代码来源:currency.helpers.php

示例3: download

 public static function download($sURL, $iTimeOut = 300)
 {
     if (false === filter_var($sURL, FILTER_VALIDATE_URL)) {
         return false;
     }
     $_sTmpFileName = self::setTempPath(self::getBaseNameOfURL($sURL));
     if (!$_sTmpFileName) {
         return false;
     }
     $_aoResponse = wp_safe_remote_get($sURL, array('timeout' => $iTimeOut, 'stream' => true, 'filename' => $_sTmpFileName));
     if (is_wp_error($_aoResponse)) {
         unlink($_sTmpFileName);
         return false;
     }
     if (200 != wp_remote_retrieve_response_code($_aoResponse)) {
         unlink($_sTmpFileName);
         return false;
     }
     $_sContent_md5 = wp_remote_retrieve_header($_aoResponse, 'content-md5');
     if ($_sContent_md5) {
         $_boIsMD5 = verify_file_md5($_sTmpFileName, $_sContent_md5);
         if (is_wp_error($_boIsMD5)) {
             unlink($_sTmpFileName);
             return false;
         }
     }
     return $_sTmpFileName;
 }
开发者ID:jaime5x5,项目名称:seamless-donations,代码行数:28,代码来源:AdminPageFramework_WPUtility_File.php

示例4: import

 public function import($attachment)
 {
     $saved_image = $this->_return_saved_image($attachment);
     if ($saved_image) {
         return $saved_image;
     }
     // Extract the file name and extension from the url
     $filename = basename($attachment['url']);
     if (function_exists('file_get_contents')) {
         $options = ['http' => ['user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686 on x86_64; rv:49.0) Gecko/20100101 Firefox/49.0']];
         $context = stream_context_create($options);
         $file_content = file_get_contents($attachment['url'], false, $context);
     } else {
         $file_content = wp_remote_retrieve_body(wp_safe_remote_get($attachment['url']));
     }
     if (empty($file_content)) {
         return false;
     }
     $upload = wp_upload_bits($filename, null, $file_content);
     $post = ['post_title' => $filename, 'guid' => $upload['url']];
     $info = wp_check_filetype($upload['file']);
     if ($info) {
         $post['post_mime_type'] = $info['type'];
     } else {
         // For now just return the origin attachment
         return $attachment;
         //return new \WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'elementor' ) );
     }
     $post_id = wp_insert_attachment($post, $upload['file']);
     wp_update_attachment_metadata($post_id, wp_generate_attachment_metadata($post_id, $upload['file']));
     update_post_meta($post_id, '_elementor_source_image_hash', $this->_get_hash_image($attachment['url']));
     $new_attachment = ['id' => $post_id, 'url' => $upload['url']];
     $this->_replace_image_ids[$attachment['id']] = $new_attachment;
     return $new_attachment;
 }
开发者ID:pojome,项目名称:elementor,代码行数:35,代码来源:class-import-images.php

示例5: generate_metadata

 protected function generate_metadata($url)
 {
     $response = wp_safe_remote_get($url);
     if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
         return false;
     }
     $body = wp_remote_retrieve_body($response);
     $metadata = sprintf('sha384-%s', base64_encode(hash('sha384', $body, true)));
     $this->meta->set($url, $metadata);
     return true;
 }
开发者ID:ssnepenthe,项目名称:homonoia,代码行数:11,代码来源:class-sri-generator.php

示例6: test_get_language_pack_uri

 function test_get_language_pack_uri()
 {
     global $woocommerce_wpml, $woocommerce;
     //use stable version to test
     $pack_uri = $woocommerce_wpml->languages_upgrader->get_language_pack_uri('uk_UA', $woocommerce_wpml->get_stable_wc_version());
     $response = wp_safe_remote_get($pack_uri, array('timeout' => 60));
     $response_result = false;
     if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
         $response_result = true;
     }
     $this->assertTrue($response_result);
 }
开发者ID:helgatheviking,项目名称:woocommerce-multilingual,代码行数:12,代码来源:test-urls.php

示例7: output

 /**
  * Handles output of the reports page in admin.
  */
 public static function output()
 {
     if (false === ($addons = get_transient('woocommerce_addons_data'))) {
         $addons_json = wp_safe_remote_get('http://d3t0oesq8995hv.cloudfront.net/woocommerce-addons.json', array('user-agent' => 'WooCommerce Addons Page'));
         if (!is_wp_error($addons_json)) {
             $addons = json_decode(wp_remote_retrieve_body($addons_json));
             if ($addons) {
                 set_transient('woocommerce_addons_data', $addons, WEEK_IN_SECONDS);
             }
         }
     }
     include_once 'views/html-admin-page-addons.php';
 }
开发者ID:rahul13bhati,项目名称:woocommerce,代码行数:16,代码来源:class-wc-admin-addons.php

示例8: refresh

 public function refresh($url)
 {
     if (!is_string($url)) {
         throw new \InvalidArgumentException(sprintf('The url parameter is required to be string, was: %s', gettype($url)));
     }
     $r = false;
     $args = ['blocking' => false, 'headers' => apply_filters(sprintf('%s\\refresh_headers', __NAMESPACE__), ['X-Nginx-Cache-Purge' => '1']), 'sslverify' => apply_filters(sprintf('%s\\sslverify', __NAMESPACE__), true), 'timeout' => 1];
     $response = wp_safe_remote_get($url, $args);
     if (!is_wp_error($response)) {
         $r = true;
     }
     return $r;
 }
开发者ID:ssnepenthe,项目名称:cache-manager,代码行数:13,代码来源:FastCGIHTTP.php

示例9: wc_rest_upload_image_from_url

/**
 * Upload image from URL.
 *
 * @since 2.6.0
 * @param string $image_url
 * @return array|WP_Error Attachment data or error message.
 */
function wc_rest_upload_image_from_url($image_url)
{
    $file_name = basename(current(explode('?', $image_url)));
    $parsed_url = @parse_url($image_url);
    // Check parsed URL.
    if (!$parsed_url || !is_array($parsed_url)) {
        return new WP_Error('woocommerce_rest_invalid_image_url', sprintf(__('Invalid URL %s.', 'woocommerce'), $image_url), array('status' => 400));
    }
    // Ensure url is valid.
    $image_url = esc_url_raw($image_url);
    // Get the file.
    $response = wp_safe_remote_get($image_url, array('timeout' => 10));
    if (is_wp_error($response)) {
        return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url) . ' ' . sprintf(__('Error: %s.', 'woocommerce'), $response->get_error_message()), array('status' => 400));
    } elseif (200 !== wp_remote_retrieve_response_code($response)) {
        return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url), array('status' => 400));
    }
    // Ensure we have a file name and type.
    $wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
    if (!$wp_filetype['type']) {
        $headers = wp_remote_retrieve_headers($response);
        if (isset($headers['content-disposition']) && strstr($headers['content-disposition'], 'filename=')) {
            $disposition = end(explode('filename=', $headers['content-disposition']));
            $disposition = sanitize_file_name($disposition);
            $file_name = $disposition;
        } elseif (isset($headers['content-type']) && strstr($headers['content-type'], 'image/')) {
            $file_name = 'image.' . str_replace('image/', '', $headers['content-type']);
        }
        unset($headers);
        // Recheck filetype
        $wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
        if (!$wp_filetype['type']) {
            return new WP_Error('woocommerce_rest_invalid_image_type', __('Invalid image type.', 'woocommerce'), array('status' => 400));
        }
    }
    // Upload the file.
    $upload = wp_upload_bits($file_name, '', wp_remote_retrieve_body($response));
    if ($upload['error']) {
        return new WP_Error('woocommerce_rest_image_upload_error', $upload['error'], array('status' => 400));
    }
    // Get filesize.
    $filesize = filesize($upload['file']);
    if (0 == $filesize) {
        @unlink($upload['file']);
        unset($upload);
        return new WP_Error('woocommerce_rest_image_upload_file_error', __('Zero size file downloaded.', 'woocommerce'), array('status' => 400));
    }
    do_action('woocommerce_rest_api_uploaded_image_from_url', $upload, $image_url);
    return $upload;
}
开发者ID:tlovett1,项目名称:woocommerce,代码行数:57,代码来源:wc-rest-functions.php

示例10: _retrieve_data

 /**
  * @access protected
  *
  * @return bool
  */
 public function _retrieve_data()
 {
     $profile = Helper::get_talent_meta($this->post, 'profile');
     $url = str_replace('https://secure.gravatar.com/avatar/', 'https://www.gravatar.com/', $profile['avatar']);
     $url = remove_query_arg(array('s', 'd'), $url) . '.json';
     $body = wp_remote_retrieve_body(wp_safe_remote_get($url));
     if ('' === $body) {
         return false;
     }
     $body = json_decode($body);
     if (null === $body) {
         return false;
     }
     if (!isset($body->entry[0])) {
         return false;
     }
     $social = get_post_meta($this->post->ID, 'social', true);
     if (isset($social[0]) && is_array($social[0])) {
         foreach ($social[0] as $key => $value) {
             $social[$key] = $value;
         }
         unset($social[0]);
     }
     if (isset($body->entry[0]->accounts)) {
         foreach ($body->entry[0]->accounts as $account) {
             switch ($account->shortname) {
                 case 'linkedin':
                     $social['linkedin'] = $account->url;
                     break;
                 case 'twitter':
                 case 'facebook':
                     $social[$account->shortname] = $account->username;
                     break;
                 case 'google':
                     $social['google-plus'] = $account->userid;
                     break;
                 case 'wordpress':
                     $social['url'] = $account->url;
                 default:
                     break;
             }
         }
     }
     if (!empty($body->entry[0]->urls)) {
         $social['url'] = $body->entry[0]->urls[0]->value;
     }
     return (bool) update_post_meta($this->post->ID, 'social', $social);
 }
开发者ID:Steadroy,项目名称:wptalents,代码行数:53,代码来源:Gravatar_Collector.php

示例11: getJsonData

 private function getJsonData($default_url)
 {
     // Setup our header and auth information
     $args = array('headers' => array('Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->api_key));
     $response = wp_safe_remote_get($default_url, $args);
     $response['my_url'] = $default_url;
     $response['my_args'] = $args;
     if (is_wp_error($response)) {
         $json = json_encode($return->get_error_message());
     } elseif (wp_remote_retrieve_response_code($response) != 200) {
         $json = json_encode(wp_remote_retrieve_body($response));
     } else {
         $json = wp_remote_retrieve_body($response);
     }
     return $json;
 }
开发者ID:agentE,项目名称:coc-api-wordpress-smartcode,代码行数:16,代码来源:CoC_API.php

示例12: _retrieve_data

 /**
  * @access protected
  *
  * @return bool
  */
 public function _retrieve_data()
 {
     $results_url = add_query_arg(array('q' => 'props+' . $this->options['username'], 'noquickjump' => '1', 'changeset' => 'on'), 'https://core.trac.wordpress.org/search');
     $results = wp_remote_retrieve_body(wp_safe_remote_get($results_url));
     if (is_wp_error($results)) {
         return false;
     }
     $pattern = '/<meta name="totalResults" content="(\\d*)" \\/>/';
     preg_match($pattern, $results, $matches);
     $count = 0;
     if (isset($matches[1])) {
         $count = intval($matches[1]);
     }
     $data = array('data' => $count, 'expiration' => time() + $this->expiration);
     update_post_meta($this->post->ID, '_changeset_count', $data);
     return $data;
 }
开发者ID:Steadroy,项目名称:wptalents,代码行数:22,代码来源:Changeset_Collector.php

示例13: get_section_data

 /**
  * Get section content for the addons screen.
  *
  * @param  string $section_id
  *
  * @return array
  */
 public static function get_section_data($section_id)
 {
     $section = self::get_section($section_id);
     $section_data = '';
     if (!empty($section->endpoint)) {
         if (false === ($section_data = get_transient('wc_addons_section_' . $section_id))) {
             $raw_section = wp_safe_remote_get(esc_url_raw($section->endpoint), array('user-agent' => 'WooCommerce Addons Page'));
             if (!is_wp_error($raw_section)) {
                 $section_data = json_decode(wp_remote_retrieve_body($raw_section));
                 if (!empty($section_data->products)) {
                     set_transient('wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS);
                 }
             }
         }
     }
     return apply_filters('woocommerce_addons_section_data', $section_data->products, $section_id);
 }
开发者ID:robbenz,项目名称:plugs,代码行数:24,代码来源:class-wc-admin-addons.php

示例14: get

 /**
  * Send a GET request to the given endpoint.
  *
  * @param  string $endpoint Appended to $url_root to create the URL.
  *
  * @return array
  *
  * @throws \InvalidArgumentException When endpoint is not a string.
  * @throws \RuntimeException When $response is a WP_Error.
  */
 public function get($endpoint)
 {
     if (!is_string($endpoint)) {
         throw new \InvalidArgumentException(sprintf('The endpoint parameter is required to be string, was: %s', gettype($endpoint)));
     }
     $endpoint = ltrim($endpoint, '/\\');
     $url = sprintf('https://wpvulndb.com/api/v2/%s', $endpoint);
     $name = 'Soter Security Checker';
     $version = '0.3.0';
     $soter_url = 'https://github.com/ssnepenthe/soter';
     $args = ['user-agent' => sprintf('%s | v%s | %s', $name, $version, $soter_url)];
     $response = wp_safe_remote_get($url, $args);
     if (is_wp_error($response)) {
         throw new \RuntimeException(sprintf('WP Error: %s', $response->get_error_message()));
     }
     return [wp_remote_retrieve_response_code($response), wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response)];
 }
开发者ID:ssnepenthe,项目名称:soter,代码行数:27,代码来源:WPClient.php

示例15: _retrieve_data

 /**
  * @access protected
  *
  * @return bool
  */
 public function _retrieve_data()
 {
     $results_url = add_query_arg(array('action' => 'query', 'list' => 'users', 'ususers' => $this->options['username'], 'usprop' => 'editcount', 'format' => 'json'), 'https://codex.wordpress.org/api.php');
     $results = wp_remote_retrieve_body(wp_safe_remote_get($results_url));
     if (is_wp_error($results)) {
         return false;
     }
     $raw = json_decode($results);
     if (isset($raw->query->users[0]->editcount)) {
         $count = (int) $raw->query->users[0]->editcount;
     } else {
         $count = 0;
     }
     $data = array('data' => $count, 'expiration' => time() + $this->expiration);
     update_post_meta($this->post->ID, '_codex_count', $data);
     return $data;
 }
开发者ID:Steadroy,项目名称:wptalents,代码行数:22,代码来源:Codex_Collector.php


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