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


PHP wp_remote_head函数代码示例

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


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

示例1: test_head_404

 function test_head_404()
 {
     $url = 'http://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     $response = wp_remote_head($url);
     $this->assertTrue(is_array($response));
     $this->assertEquals('404', wp_remote_retrieve_response_code($response));
 }
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:7,代码来源:functions.php

示例2: test_head_404

 function test_head_404()
 {
     $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
     $headers = wp_remote_head($url);
     $this->assertInternalType('array', $headers, "Reply wasn't array.");
     $this->assertEquals('404', wp_remote_retrieve_response_code($headers));
 }
开发者ID:plis197715,项目名称:wordpress-develop,代码行数:7,代码来源:functions.php

示例3: get_preview_from_url

 public static function get_preview_from_url($url)
 {
     $preview = '';
     $images = array('jpg', 'jpeg', 'bmp', 'gif', 'png');
     if (filter_var($url, FILTER_VALIDATE_URL) !== FALSE) {
         // check for extension, if it has extension then use it
         $info = pathinfo($url);
         if (isset($info['extension'])) {
             if (in_array($info['extension'], $images)) {
                 $preview = $url;
             } else {
                 $type = wp_ext2type($info['extension']);
                 if (is_null($type)) {
                     $type = 'default';
                 }
                 $preview = includes_url() . 'images/crystal/' . $type . '.png';
             }
         } else {
             // if no extension, try to discover from mime
             $mime = wp_remote_head($url);
             if (!is_wp_error($mime)) {
                 $mime = $mime['headers']['content-type'];
                 if (strpos($mime, 'image') === 0) {
                     $preview = $url;
                 } else {
                     $preview = wp_mime_type_icon($mime);
                 }
             } else {
                 $preview = includes_url() . 'images/crystal/' . 'default' . '.png';
             }
         }
     }
     return $preview;
 }
开发者ID:ntnvu,项目名称:tcb_online,代码行数:34,代码来源:res.php

示例4: mixcloud_shortcode

function mixcloud_shortcode($atts, $content = null)
{
    if (empty($atts[0]) && empty($content)) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    $regular_expression = "#((?<=mixcloud.com/)([A-Za-z0-9_-]+/[A-Za-z0-9_-]+))|^([A-Za-z0-9_-]+/[A-Za-z0-9_-]+)#i";
    preg_match($regular_expression, $content, $match);
    if (!empty($match)) {
        $resource_id = trim($match[0]);
    } else {
        preg_match($regular_expression, $atts[0], $match);
        if (!empty($match)) {
            $resource_id = trim($match[0]);
        }
    }
    if (empty($resource_id)) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    $atts = shortcode_atts(array('width' => 300, 'height' => 300), $atts, 'mixcloud');
    // Build URL
    $url = add_query_arg($atts, "http://api.mixcloud.com/{$resource_id}/embed-html/");
    $head = wp_remote_head($url);
    if (is_wp_error($head) || 200 != $head['response']['code']) {
        return "<!-- mixcloud error: invalid mixcloud resource -->";
    }
    return sprintf('<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url($url));
}
开发者ID:moushegh,项目名称:blog-source-configs,代码行数:27,代码来源:mixcloud.php

示例5: url_exists

 function url_exists($url)
 {
     $remote_head = wp_remote_head($url);
     if (is_wp_error($remote_head)) {
         return false;
     } else {
         return 404 !== $remote_head['response']['code'];
     }
 }
开发者ID:jimmyandrade,项目名称:flegondavid.com.br,代码行数:9,代码来源:template-tags.php

示例6: src_exists

 /**
  * Asserts an image actually exists as quickly as possible by sending a HEAD
  * request
  * @param string $src
  * @return boolean
  */
 protected function src_exists($src)
 {
     $results = wp_remote_head($src);
     if (is_array($results) && !$results instanceof WP_Error) {
         return strpos($results['headers']['content-type'], "image") !== FALSE;
     } else {
         return FALSE;
     }
 }
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:15,代码来源:EE_Admin_File_Uploader_Display_Strategy.strategy.php

示例7: goodreads_user_id_exists

 function goodreads_user_id_exists($user_id)
 {
     $url = "http://www.goodreads.com/user/show/{$user_id}/";
     $response = wp_remote_head($url, array('httpversion' => '1.1', 'timeout' => 3, 'redirection' => 2));
     if (wp_remote_retrieve_response_code($response) === 200) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:10,代码来源:goodreads.php

示例8: get_thumbnail_url

 public function get_thumbnail_url($id)
 {
     $maxres = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
     $response = wp_remote_head($maxres);
     if (!is_wp_error($response) && $response['response']['code'] == '200') {
         $result = $maxres;
     } else {
         $result = 'http://img.youtube.com/vi/' . $id . '/0.jpg';
     }
     return $result;
 }
开发者ID:congtrieu112,项目名称:anime,代码行数:11,代码来源:class-youtube-thumbnails.php

示例9: mgm_check_http_range_support

/**
 * check http range support for heavy download
 */
function mgm_check_http_range_support($key = NULL)
{
    // sample
    //$sample_url = site_url('wp-content/plugins/magicmembers/core/assets/images/logo.png');
    // sample
    $sample_url = MGM_ASSETS_URL . 'images/logo.png';
    // headers
    $h = wp_remote_head($sample_url, array('timeout' => 30));
    // return
    return isset($h['headers']['accept-ranges']) && $h['headers']['accept-ranges'] == 'bytes' ? true : false;
}
开发者ID:jervy-ez,项目名称:magic-members-test,代码行数:14,代码来源:mgm_dependency_functions.php

示例10: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $env = Validators::validateEnv($input->getOption('env'));
     $root = $this->skeleton->getWebRoot();
     $plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env));
     require $root . '/wp-load.php';
     require ABSPATH . 'wp-admin/includes/admin.php';
     require ABSPATH . 'wp-admin/includes/plugin-install.php';
     foreach ($plugins as $slug => $version) {
         $plugin = plugins_api('plugin_information', array('slug' => $slug));
         if (is_wp_error($plugin)) {
             throw new \Exception('Could not get plugin information for ' . $slug);
         }
         if ($version) {
             list($prefix) = explode($slug, $plugin->download_link);
             $link = sprintf('%s%s.%s.zip', $prefix, $slug, $version);
             $response = wp_remote_head($link);
             if (!isset($response['response']['code']) || $response['response']['code'] != 200) {
                 throw new \Exception('Unable to verify ' . $link);
             }
             $plugin->download_link = $link;
             $plugin->version = $version;
         }
         require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         $status = install_plugin_install_status($plugin);
         $upgrader = new \Plugin_Upgrader(new UpgraderSkin($output));
         $current = current(get_plugins("/{$slug}"));
         switch ($status['status']) {
             case 'install':
                 $output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version));
                 $upgrader->install($plugin->download_link);
                 break;
             case 'update_available':
                 if ($plugin->version == $current['Version']) {
                     $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version));
                 } else {
                     $output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                     $file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}")));
                     $upgrader->upgrade($file);
                 }
                 break;
             case 'latest_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version']));
                 break;
             case 'newer_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                 break;
         }
     }
     if ($plugins) {
         $output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name));
     }
 }
开发者ID:ericclemmons,项目名称:wordpress-generator,代码行数:53,代码来源:InstallPluginsWordPressCommand.php

示例11: check

 public function check()
 {
     $response = wp_remote_head($this->args['domain']);
     $this->ok = !is_wp_error($response);
     if ($this->ok) {
         $this->info = __('Your server can connect to the themes demo content data', 'lambda-admin-td');
         $this->value = $response['response']['code'] . ' - ' . $response['response']['message'];
     } else {
         $this->info = __('Your server can not connect to the themes demo content data', 'lambda-admin-td');
         $this->value = $response->get_error_message();
     }
 }
开发者ID:ntngiri,项目名称:Wordpress-dhaba,代码行数:12,代码来源:OxygennaOutConnectCheck.php

示例12: pp_enqueue_jquery

/**
 * Enqueue jQuery from Google CDN with fallback to local WordPress
 * First we have a really complex method of loading jQuery from the CDN or local
 * should the CDN fail. The code is adapted from https://gist.github.com/wpsmith/4083811.
 * Then we load basic styles.
 *
 * @package pp
 * @subpackage boilerplate-theme_filters+hooks
 * @internal only called by `wp_enqueue_scripts` action
 *
 * @link https://gist.github.com/wpsmith/4083811.
 * @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script
 * @link http://codex.wordpress.org/Function_Reference/wp_register_script
 * @link http://codex.wordpress.org/Function_Reference/wp_deregister_script
 * @link http://codex.wordpress.org/Function_Reference/get_bloginfo
 * @link http://codex.wordpress.org/Function_Reference/is_wp_error
 * @link http://codex.wordpress.org/Function_Reference/set_transient
 * @link http://codex.wordpress.org/Function_Reference/get_transient
 *
 * @uses get_transient()		  Get the value of a transient.
 * @uses set_transient()		  Set/update the value of a transient.
 * @uses is_wp_error()			 Check whether the passed variable is a WordPress Error.
 * @uses get_bloginfo()			returns information about your site.
 * @uses wp_deregister_script() Deregisters javascripts for use with wp_enqueue_script() later.
 * @uses wp_register_script()	Registers javascripts for use with wp_enqueue_script() later.
 * @uses wp_enqueue_script()	 Enqueues javascript.
 */
function pp_enqueue_jquery()
{
    $script_location = 'js/dist/application.js';
    $script_head_location = 'js/dist/application-head.js';
    // Setup Google URI, default
    $protocol = isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS'] ? 'https' : 'http';
    // Get Latest Version
    $url = $protocol . '://code.jquery.com/jquery-1.11.3.min.js';
    // Get Specific Version
    //$url = $protocol . '://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js';
    // Setup WordPress URI
    $wpurl = get_bloginfo('template_directory') . '/js/src/vendor/jquery-1.11.3.min.js';
    // Setup version
    $ver = null;
    // Deregister WordPress default jQuery
    wp_deregister_script('jquery');
    // Check transient, if false, set URI to WordPress URI
    delete_transient('google_jquery');
    if ('false' == ($google = get_transient('google_jquery'))) {
        $url = $wpurl;
    } elseif (false === $google) {
        // Ping Google
        $resp = wp_remote_head($url);
        // Use Google jQuery
        if (!is_wp_error($resp) && 200 == $resp['response']['code']) {
            // Set transient for 5 minutes
            set_transient('google_jquery', 'true', 60 * 5);
        } else {
            // Set transient for 5 minutes
            set_transient('google_jquery', 'false', 60 * 5);
            // Use WordPress URI
            $url = $wpurl;
            // Set jQuery Version, WP stanards
            $ver = '1.8.2';
        }
    }
    // Register surefire jQuery
    wp_register_script('jquery', $url, array(), $ver, true);
    // Enqueue jQuery
    wp_enqueue_script('jquery');
    // Now load basic site js
    wp_enqueue_script('pp-theme-head', get_bloginfo('template_directory') . '/' . $script_head_location, array('jquery'), '1.0');
    wp_enqueue_script('pp-theme', get_bloginfo('template_directory') . '/' . $script_location, array('jquery'), '1.0', true);
    // Add some site information to a WP js object
    $wp_object = array('templateUrl' => get_bloginfo('template_url'), 'stylesheetUrl' => get_bloginfo('stylesheet_url'), 'stylesheetDirectory' => get_bloginfo('stylesheet_directory'), 'siteName' => get_bloginfo('name'), 'description' => get_bloginfo('description'), 'currentTheme' => wp_get_theme(), 'url' => get_bloginfo('url'));
    wp_localize_script('basic', 'ppWP', $wp_object);
    // For comment reply form
    if (is_singular() && get_option('thread_comments') && comments_open()) {
        wp_enqueue_script('comment-reply');
    }
}
开发者ID:nathansh,项目名称:penguinpress-theme,代码行数:78,代码来源:scripts.php

示例13: get_banner_tint

 /**
  * Won't work with soil-relative-urls
  */
 private static function get_banner_tint($url)
 {
     $banner_tint = '#5c5d5f';
     $thumb_request = wp_remote_head($url);
     if (is_wp_error($url)) {
         return $banner_tint;
     }
     $tonesque_exists = class_exists('Tonesque');
     $is_404_error = 404 === $thumb_request['response']['code'];
     if (!$tonesque_exists || $is_404_error) {
         return $banner_tint;
     }
     $tonesque = new \Tonesque($thumb);
     return '#' . $tonesque->color('hex');
 }
开发者ID:jimmyandrade,项目名称:flegondavid.com.br,代码行数:18,代码来源:class-customizer.php

示例14: getImg

 /**
  * 投稿の最初の画像についてsrcとsrcsetを探す
  * @return array src文字列 srcset文字列 alt文字列
  */
 protected function getImg()
 {
     if (\has_post_thumbnail($this->post->ID)) {
         $target = \get_the_post_thumbnail($this->post->ID);
     } else {
         $target = $this->getContent();
     }
     $patterns = ["img" => "/<img [^>]+>/i", "src" => "/src=(?P<q>\"|')(?P<src>.*?)(?P=q)/", "srcset" => "/srcset=(?P<q>\"|')(?P<srcset>.*?)(?P=q)/", "alt" => "/alt=(?P<q>\"|')(?P<alt>.*?)(?P=q)/"];
     $src = "";
     $srcset = "";
     $alt = "";
     $result = \preg_match($patterns["img"], $target, $m);
     if ($result) {
         $img = $m[0];
         if (\preg_match($patterns["src"], $img, $m2)) {
             $src = $m2["src"];
         }
         if (\preg_match($patterns["srcset"], $img, $m3)) {
             $srcset = $m3["srcset"];
         }
         if (\preg_match($patterns["alt"], $img, $m4)) {
             $alt = $m4["alt"];
         }
     }
     if (!$result) {
         //youtubeの埋め込みコードを探す
         $yt_patterns = ["@<iframe\\b[^>]+src=['\"]https?://www\\.youtube\\.com/embed/(?P<id>[a-zA-Z0-9_\\-]+)@"];
         foreach ($yt_patterns as $p) {
             $result = \preg_match($p, $target, $match);
             if ($result) {
                 $id = $match["id"];
                 $src = "https://i.ytimg.com/vi/{$id}/0.jpg";
                 $temp = ["https://i.ytimg.com/vi/{$id}/default.jpg 120w", "https://i.ytimg.com/vi/{$id}/mqdefault.jpg 320w", "https://i.ytimg.com/vi/{$id}/0.jpg 480w"];
                 //maxresdefault.jpgが存在するかチェック
                 $maxQ = "https://i.ytimg.com/vi/{$id}/maxresdefault.jpg";
                 $resp = \wp_remote_head($maxQ);
                 if (!\is_wp_error($resp) && in_array(\wp_remote_retrieve_response_code($resp), [200, 301, 302])) {
                     //あった
                     //maxresdefaultは1980等の場合もある 注意
                     \array_push($temp, $maxQ . " 1280w");
                 }
                 $srcset = \implode(" ,", $temp);
                 break;
             }
         }
     }
     return ["src" => $src, "srcset" => $srcset, "alt" => $alt];
 }
开发者ID:Aquei,项目名称:purely,代码行数:52,代码来源:LinkCard.php

示例15: testOembedTestURLsResolve

 /**
  * Test the tests
  *
  * @group external-oembed
  * @ticket 28507
  * @ticket 32360
  *
  * @dataProvider oEmbedProviderData
  */
 public function testOembedTestURLsResolve($match, array $urls)
 {
     if (empty($urls)) {
         $this->markTestIncomplete();
     }
     foreach ($urls as $url) {
         $msg = sprintf('Test URL: %s', $url);
         $r = wp_remote_head($url, array('redirection' => 3));
         if (is_wp_error($r)) {
             $this->fail(sprintf("%s (%s)\n%s", $r->get_error_message(), $r->get_error_code(), $msg));
         }
         $http_code = wp_remote_retrieve_response_code($r);
         $http_message = wp_remote_retrieve_response_message($r);
         $this->assertSame(200, $http_code, "{$msg}\n- HTTP response code: {$http_code} {$http_message}");
     }
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:25,代码来源:oembed.php


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