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


PHP WP_oEmbed::discover方法代码示例

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


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

示例1: 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

示例2: 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


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