本文整理汇总了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;
}
示例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 .= '&showinfo=0&iv_load_policy=3&modestbranding=0&nologo=1&vq=large&autoplay=1&ps=docs&wmode=opaque&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
}