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


PHP WP_oEmbed::fetch方法代码示例

本文整理汇总了PHP中WP_oEmbed::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_oEmbed::fetch方法的具体用法?PHP WP_oEmbed::fetch怎么用?PHP WP_oEmbed::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_oEmbed的用法示例。


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

示例1: get_data

 public function get_data($url = '', $args = '')
 {
     if ($url) {
         $this->url = $url;
     }
     if (!$this->url) {
         return false;
     }
     //if it was already fetched
     if ($this->data) {
         return $this->data;
     }
     $provider = self::$oembed->get_provider($this->url, $args);
     if (!$provider) {
         return false;
     }
     $data = self::$oembed->fetch($provider, $this->url, $args);
     if (!$data) {
         return false;
     }
     $this->data = $data;
     return $this->data;
 }
开发者ID:markc,项目名称:mediapress,代码行数:23,代码来源:class-mpp-oembed.php

示例2: ale_get_embed_video

function ale_get_embed_video($url)
{
    require_once ABSPATH . WPINC . '/class-oembed.php';
    $WP_oEmbed = new WP_oEmbed();
    $provider = $WP_oEmbed->discover($url);
    $data = $WP_oEmbed->fetch($provider, $url);
    return $data;
}
开发者ID:BMNTeam,项目名称:myFirstThemeToTf,代码行数:8,代码来源:images_media.php

示例3: orbitnews_fancy_video

/**
 * Add Meta Keys for Fancybox Link & Embed for Video Posts 
 */
function orbitnews_fancy_video($post_ID)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (get_post_status($post_ID) != 'publish') {
        return;
    }
    /* Delete Existing Metakeys */
    delete_post_meta($post_ID, '_orn_oembed_body');
    delete_post_meta($post_ID, '_orn_embed_link');
    // Video Formats
    $video_link = trim(get_post_meta($post_ID, "orn_oembed_videos", true));
    $video_format = has_post_format('video', $post_ID);
    // Video Type Embed
    if (!empty($video_link) && $video_format) {
        // Get Video Data with wordpress oembed class
        require_once ABSPATH . WPINC . '/class-oembed.php';
        $oembed = new WP_oEmbed();
        $provider = $oembed->discover($video_link);
        $data = $oembed->fetch($provider, $video_link);
        if (isset($data) && $data != false) {
            // Setup variables
            $provider = $data->provider_name;
            // Video Provider Name
            $html_embed = $data->html;
            // Video Embed html
            $thumb_link = $data->thumbnail_url;
            // Video Post Thumbnail
            preg_match('/<iframe.*src=\\"(.*)\\".*><\\/iframe>/isU', $html_embed, $url_embed);
            $url_embed = $url_embed[1];
            // Embed Url
            $filename = sanitize_title($data->title);
            // Create filename from video title
            //Set meta key with feteched video embed html
            update_post_meta($post_ID, '_orn_oembed_body', $html_embed);
            //Video link and thumbnail for video posts
            switch ($provider) {
                case 'YouTube':
                    $url_embed .= '&amp;showinfo=0&amp;iv_load_policy=3&amp;modestbranding=0&amp;nologo=1&amp;vq=large&amp;autoplay=1&amp;ps=docs&amp;wmode=opaque&amp;rel=0';
                    break;
                case 'Vimeo':
                    $thumb_link = str_replace('_295.jpg', '_640.jpg', $thumb_link);
                    break;
                default:
                    // do nothing;
                    break;
            }
            //end switch
            // Add Meta key with embed link
            update_post_meta($post_ID, '_orn_embed_link', $url_embed);
            if (!has_post_thumbnail($post_ID)) {
                //Fetch and Store the Image
                $remote_file = wp_remote_get($thumb_link, array('sslverify' => false));
                $file_type = wp_remote_retrieve_header($remote_file, 'content-type');
                // Get image type
                $filename .= '-' . rawurldecode(basename($thumb_link));
                // add image file name to file
                $local_file_url = wp_upload_bits($filename, '', $remote_file['body']);
                // save image in local server
                //Attachment options
                $attachment = array('post_title' => $filename, 'post_mime_type' => $file_type, 'post_content' => '', 'post_status' => 'inherit', 'ping_status' => 'closed');
                // Add the image to your media library and set as featured image
                $attach_id = wp_insert_attachment($attachment, $local_file_url['file'], $post_ID);
                $attach_data = wp_generate_attachment_metadata($attach_id, $local_file_url['file']);
                wp_update_attachment_metadata($attach_id, $attach_data);
                set_post_thumbnail($post_ID, $attach_id);
            }
            // end !has_post_thumbnail()
        }
        //end isset( $data )
    }
    //end $video_link empty
}
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:77,代码来源:extras.php

示例4: audiotheme_video_sideload_thumbnail

/**
 * Import a video thumbnail from an oEmbed endpoint into the media library.
 *
 * @todo Considering doing video URL comparison rather than oembed thumbnail
 *       comparison?
 *
 * @since 1.8.0
 *
 * @param int $post_id Video post ID.
 * @param string $url Video URL.
 */
function audiotheme_video_sideload_thumbnail($post_id, $url)
{
    require_once ABSPATH . WPINC . '/class-oembed.php';
    $oembed = new \WP_oEmbed();
    $provider = $oembed->get_provider($url);
    if (!$provider || false === ($data = $oembed->fetch($provider, $url)) || !isset($data->thumbnail_url)) {
        return;
    }
    $current_thumb_id = get_post_thumbnail_id($post_id);
    $oembed_thumb_id = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', true);
    $oembed_thumb_url = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', true);
    // Re-use the existing oEmbed data instead of making another copy of the thumbnail.
    if ($data->thumbnail_url == $oembed_thumb_url && (!$current_thumb_id || $current_thumb_id != $oembed_thumb_id)) {
        set_post_thumbnail($post_id, $oembed_thumb_id);
    } elseif (!$current_thumb_id || $data->thumbnail_url != $oembed_thumb_url) {
        $attachment_id = audiotheme_video_sideload_image($data->thumbnail_url, $post_id);
        if (!empty($attachment_id) && !is_wp_error($attachment_id)) {
            set_post_thumbnail($post_id, $attachment_id);
            // Store the oEmbed thumb data so the same image isn't copied on repeated requests.
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', $attachment_id);
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', $data->thumbnail_url);
        }
    }
}
开发者ID:sewmyheadon,项目名称:audiotheme,代码行数:35,代码来源:videos.php


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