本文整理汇总了PHP中wp_mediaelement_fallback函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_mediaelement_fallback函数的具体用法?PHP wp_mediaelement_fallback怎么用?PHP wp_mediaelement_fallback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_mediaelement_fallback函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_video_shortcode
//.........这里部分代码省略.........
$type = wp_check_filetype($atts[$ext], wp_get_mime_types());
if (strtolower($type['ext']) === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$atts['src'] = wp_get_attachment_url($video->ID);
if (empty($atts['src'])) {
return;
}
array_unshift($default_types, 'src');
}
/**
* Filter the media library used for the video shortcode.
*
* @since 3.6.0
*
* @param string $library Media library used for the video shortcode.
*/
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
if ('mediaelement' === $library && did_action('init')) {
wp_enqueue_style('wp-mediaelement');
wp_enqueue_script('wp-mediaelement');
}
/**
* Filter the class attribute for the video shortcode output container.
*
* @since 3.6.0
*
* @param string $class CSS class or list of space-separated classes.
*/
$html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instance), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload']);
// These ones should just be omitted altogether if they are blank
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($html_atts[$a])) {
unset($html_atts[$a]);
}
}
$attr_strings = array();
foreach ($html_atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html = '';
if ('mediaelement' === $library && 1 === $instance) {
$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
}
$html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty($atts[$fallback])) {
if (empty($fileurl)) {
$fileurl = $atts[$fallback];
}
if ('src' === $fallback && $is_youtube) {
$type = array('type' => 'video/youtube');
} elseif ('src' === $fallback && $is_vimeo) {
$type = array('type' => 'video/vimeo');
} else {
$type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
}
$url = add_query_arg('_', $instance, $atts[$fallback]);
$html .= sprintf($source, $type['type'], esc_url($url));
}
}
if (!empty($content)) {
if (false !== strpos($content, "\n")) {
$content = str_replace(array("\r\n", "\n", "\t"), '', $content);
}
$html .= trim($content);
}
if ('mediaelement' === $library) {
$html .= wp_mediaelement_fallback($fileurl);
}
$html .= '</video>';
$width_rule = '';
if (!empty($atts['width'])) {
$width_rule = sprintf('width: %dpx; ', $atts['width']);
}
$output = sprintf('<div style="%s" class="wp-video">%s</div>', $width_rule, $html);
/**
* Filter the output of the video shortcode.
*
* @since 3.6.0
*
* @param string $output Video shortcode HTML output.
* @param array $atts Array of video shortcode attributes.
* @param string $video Video file.
* @param int $post_id Post ID.
* @param string $library Media library used for the video shortcode.
*/
return apply_filters('wp_video_shortcode', $output, $atts, $video, $post_id, $library);
}
示例2: custom_video_shortcode
//.........这里部分代码省略.........
return $html;
}
$video = null;
$default_types = wp_get_video_extensions();
$defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'height' => 1080, 'width' => empty($content_width) ? 1920 : $content_width, 'size' => '');
foreach ($default_types as $type) {
$defaults_atts[$type] = '';
}
$atts = shortcode_atts($defaults_atts, $attr, 'video');
extract($atts);
$w = $width;
$h = $height;
if (is_admin() && $width > 600) {
$w = 1920;
} elseif (!is_admin() && $w > $defaults_atts['width']) {
$w = $defaults_atts['width'];
}
if ($w < $width) {
$height = round($h * $w / $width);
}
$width = $w;
$primary = false;
if (!empty($src)) {
$type = wp_check_filetype($src, wp_get_mime_types());
if (!in_array(strtolower($type['ext']), $default_types)) {
return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($src), esc_html($src));
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty(${$ext})) {
$type = wp_check_filetype(${$ext}, wp_get_mime_types());
if (strtolower($type['ext']) === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$src = wp_get_attachment_url($video->ID);
if (empty($src)) {
return;
}
array_unshift($default_types, 'src');
}
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
/*if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}
/*$atts = array(
'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
'id' => sprintf( 'video-%d-%d', $post_id, $instances ),
'width' => absint( $width ),
'height' => absint( $height ),
'poster' => esc_url( $poster ),
'loop' => $loop,
'autoplay' => $autoplay,
'preload' => $preload,
);*/
// These ones should just be omitted altogether if they are blank
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($atts[$a])) {
unset($atts[$a]);
}
}
$attr_strings = array();
foreach ($atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html .= '<video id="videoplayer" class="video-js vjs-mnml ' . $size . '" controls="controls" data-setup>';
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty(${$fallback})) {
if (empty($fileurl)) {
$fileurl = ${$fallback};
}
$type = wp_check_filetype(${$fallback}, wp_get_mime_types());
// m4v sometimes shows up as video/mpeg which collides with mp4
if ('m4v' === $type['ext']) {
$type['type'] = 'video/m4v';
}
$html .= sprintf($source, $type['type'], esc_url(${$fallback}));
}
}
if ('mediaelement' === $library) {
$html .= wp_mediaelement_fallback($fileurl);
}
$html .= '</video>';
$html = sprintf('<div class="wp-video">%s</div>', $html);
return apply_filters('wp_video_shortcode', $html, $atts, $video, $post_id, $library);
}
示例3: wp_video_shortcode
//.........这里部分代码省略.........
* @return string HTML content to display video.
*/
function wp_video_shortcode($attr)
{
global $content_width;
$post_id = get_post() ? get_the_ID() : 0;
static $instances = 0;
$instances++;
$video = null;
$default_types = wp_get_video_extensions();
$defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'height' => 360, 'width' => empty($content_width) ? 640 : $content_width);
foreach ($default_types as $type) {
$defaults_atts[$type] = '';
}
$atts = shortcode_atts($defaults_atts, $attr, 'video');
extract($atts);
$w = $width;
$h = $height;
if (is_admin() && $width > 600) {
$w = 600;
} elseif (!is_admin() && $w > $defaults_atts['width']) {
$w = $defaults_atts['width'];
}
if ($w < $width) {
$height = round($h * $w / $width);
}
$width = $w;
$primary = false;
if (!empty($src)) {
$type = wp_check_filetype($src, wp_get_mime_types());
if (!in_array($type['ext'], $default_types)) {
return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($src), esc_html($src));
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty(${$ext})) {
$type = wp_check_filetype(${$ext}, wp_get_mime_types());
if ($type['ext'] === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$src = wp_get_attachment_url($video->ID);
if (empty($src)) {
return;
}
array_unshift($default_types, 'src');
}
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
if ('mediaelement' === $library && did_action('init')) {
wp_enqueue_style('wp-mediaelement');
wp_enqueue_script('wp-mediaelement');
}
$atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instances), 'width' => absint($width), 'height' => absint($height), 'poster' => esc_url($poster), 'loop' => $loop, 'autoplay' => $autoplay, 'preload' => $preload);
// These ones should just be omitted altogether if they are blank
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($atts[$a])) {
unset($atts[$a]);
}
}
$attr_strings = array();
foreach ($atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html = '';
if ('mediaelement' === $library && 1 === $instances) {
$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
}
$html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty(${$fallback})) {
if (empty($fileurl)) {
$fileurl = ${$fallback};
}
$type = wp_check_filetype(${$fallback}, wp_get_mime_types());
// m4v sometimes shows up as video/mpeg which collides with mp4
if ('m4v' === $type['ext']) {
$type['type'] = 'video/m4v';
}
$html .= sprintf($source, $type['type'], esc_url(${$fallback}));
}
}
if ('mediaelement' === $library) {
$html .= wp_mediaelement_fallback($fileurl);
}
$html .= '</video>';
$html = sprintf('<div style="width: %dpx; max-width: 100%%;">%s</div>', $width, $html);
return apply_filters('wp_video_shortcode', $html, $atts, $video, $post_id, $library);
}
示例4: wp_video_shortcode
/**
* The Video shortcode.
*
* This implements the functionality of the Video Shortcode for displaying
* WordPress mp4s in a post.
*
* @since 3.6.0
*
* @param array $attr Attributes of the shortcode.
* @return string HTML content to display video.
*/
function wp_video_shortcode($attr)
{
global $content_width;
$post_id = get_post() ? get_the_ID() : 0;
static $instances = 0;
$instances++;
$video = null;
$default_types = wp_get_video_extensions();
$defaults_atts = array('src' => '', 'poster' => '', 'height' => 360, 'width' => empty($content_width) ? 640 : $content_width);
foreach ($default_types as $type) {
$defaults_atts[$type] = '';
}
$atts = shortcode_atts($defaults_atts, $attr, 'video');
extract($atts);
$w = $width;
$h = $height;
if (is_admin() && $width > 600) {
$w = 600;
} elseif (!is_admin() && $w > $defaults_atts['width']) {
$w = $defaults_atts['width'];
}
if ($w < $width) {
$height = round($h * $w / $width);
}
$width = $w;
$primary = false;
if (!empty($src)) {
$type = wp_check_filetype($src);
if (!in_array($type['ext'], $default_types)) {
return sprintf('<a class="wp-post-format-link-video" href="%1$s">%1$s</a>', $src);
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty(${$ext})) {
$type = wp_check_filetype(${$ext});
if ($type['ext'] === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_video($post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$src = wp_get_attachment_url($video->ID);
if (empty($src)) {
return;
}
array_unshift($default_types, 'src');
}
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
if ('mediaelement' === $library && did_action('init')) {
wp_enqueue_style('wp-mediaelement');
wp_enqueue_script('wp-mediaelement');
}
$atts = array(sprintf('class="%s"', apply_filters('wp_video_shortcode_class', 'wp-video-shortcode')), sprintf('id="video-%d-%d"', $post_id, $instances), sprintf('width="%d"', $width), sprintf('height="%d"', $height));
if (!empty($poster)) {
$atts[] = sprintf('poster="%s"', esc_url($poster));
}
$html = sprintf('<video %s controls="controls" preload="none">', join(' ', $atts));
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty(${$fallback})) {
if (empty($fileurl)) {
$fileurl = ${$fallback};
}
$type = wp_check_filetype(${$fallback});
// m4v sometimes shows up as video/mpeg which collides with mp4
if ('m4v' === $type['ext']) {
$type['type'] = 'video/m4v';
}
$html .= sprintf($source, $type['type'], ${$fallback});
}
}
if ('mediaelement' === $library) {
$html .= wp_mediaelement_fallback($fileurl);
}
$html .= '</video>';
return apply_filters('wp_video_shortcode', $html, $atts, $video, $post_id);
}
示例5: video_shortcode
//.........这里部分代码省略.........
// Skrollr : add Dailymotion pattern
$dm_pattern = '#^https?://(?:www\\.)?(?:dailymotion\\.com/video/|dai\\.ly/)#';
// End Skrollr
$primary = false;
if (!empty($atts['src'])) {
if (!preg_match($yt_pattern, $atts['src']) && !preg_match($dm_pattern, $atts['src'])) {
// Skrollr : add Dailymotion pattern
$type = wp_check_filetype($atts['src'], wp_get_mime_types());
if (!in_array(strtolower($type['ext']), $default_types)) {
return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src']));
}
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty($atts[$ext])) {
$type = wp_check_filetype($atts[$ext], wp_get_mime_types());
if (strtolower($type['ext']) === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$atts['src'] = wp_get_attachment_url($video->ID);
if (empty($atts['src'])) {
return;
}
array_unshift($default_types, 'src');
}
/**
* Filter the class attribute for the video shortcode output container.
*
* @since 3.6.0
*
* @param string $class CSS class or list of space-separated classes.
*/
$html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instances), 'width' => '100%', 'height' => '100%', 'poster' => esc_url($atts['poster']), 'loop' => $atts['loop'], 'autoplay' => $atts['autoplay'], 'preload' => $atts['preload']);
// These ones should just be omitted altogether if they are blank
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($html_atts[$a])) {
unset($html_atts[$a]);
}
}
$attr_strings = array();
foreach ($html_atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html = '';
$html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty($atts[$fallback])) {
if (empty($fileurl)) {
$fileurl = $atts[$fallback];
}
if ('src' === $fallback && preg_match($yt_pattern, $atts['src'])) {
$type = array('type' => 'video/youtube');
} else {
if ('src' === $fallback && preg_match($dm_pattern, $atts['src'])) {
// Skrollr : add Dailymotion pattern
$type = array('type' => 'video/dailymotion');
} else {
$type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
}
}
// Skrollr : remove '_' in URL query args
$url = $atts[$fallback];
$html .= sprintf($source, $type['type'], esc_url($url));
}
}
if (!empty($content)) {
if (false !== strpos($content, "\n")) {
$content = str_replace(array("\r\n", "\n", "\t"), '', $content);
}
$html .= trim($content);
}
$html .= wp_mediaelement_fallback($fileurl);
$html .= '</video>';
// use the post content as a legend
global $post;
$content = strip_shortcodes(get_the_content());
if (trim($content) != '') {
$html .= "<figcaption ";
$html .= "data--0p-bottom-top=\"opacity:1\" ";
$html .= "data--100p-bottom-top=\"opacity:1\" ";
$html .= "data--120p-bottom-top=\"opacity:0\"";
$html .= "data-anchor-target=\"#{$post->post_name}\" ";
$html .= ">{$content}</figcaption>";
}
// Skrollr : remove width and height rules
return sprintf('<div class="wp-video">%s</div>', $html);
}
示例6: video
public static function video($attr)
{
$post_id = get_post() ? get_the_ID() : 0;
static $instances = 0;
$instances++;
$video = null;
$default_types = wp_get_video_extensions();
$defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360);
foreach ($default_types as $type) {
$defaults_atts[$type] = '';
}
$atts = shortcode_atts($defaults_atts, $attr, 'video');
$yt_pattern = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#';
$primary = false;
if (!empty($atts['src'])) {
if (!preg_match($yt_pattern, $atts['src'])) {
$type = wp_check_filetype($atts['src'], wp_get_mime_types());
if (!in_array(strtolower($type['ext']), $default_types)) {
return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src']));
}
}
$primary = true;
array_unshift($default_types, 'src');
} else {
foreach ($default_types as $ext) {
if (!empty($atts[$ext])) {
$type = wp_check_filetype($atts[$ext], wp_get_mime_types());
if (strtolower($type['ext']) === $ext) {
$primary = true;
}
}
}
}
if (!$primary) {
$videos = get_attached_media('video', $post_id);
if (empty($videos)) {
return;
}
$video = reset($videos);
$atts['src'] = wp_get_attachment_url($video->ID);
if (empty($atts['src'])) {
return;
}
array_unshift($default_types, 'src');
}
$library = apply_filters('wp_video_shortcode_library', 'mediaelement');
if ('mediaelement' === $library && did_action('init')) {
wp_enqueue_style('wp-mediaelement');
wp_enqueue_script('wp-mediaelement');
}
$html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instances), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => $atts['loop'], 'autoplay' => $atts['autoplay'], 'preload' => $atts['preload']);
foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
if (empty($html_atts[$a])) {
unset($html_atts[$a]);
}
}
$attr_strings = array();
foreach ($html_atts as $k => $v) {
$attr_strings[] = $k . '="' . esc_attr($v) . '"';
}
$html = '';
if ('mediaelement' === $library && 1 === $instances) {
$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
}
$html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ($default_types as $fallback) {
if (!empty($atts[$fallback])) {
if (empty($fileurl)) {
$fileurl = $atts[$fallback];
}
if ('src' === $fallback && preg_match($yt_pattern, $atts['src'])) {
$type = array('type' => 'video/youtube');
} else {
$type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
}
$url = add_query_arg('_', $instances, $atts[$fallback]);
$html .= sprintf($source, $type['type'], esc_url($url));
}
}
if ('mediaelement' === $library) {
$html .= wp_mediaelement_fallback($fileurl);
}
$html .= '</video>';
$width_rule = $height_rule = '';
if (!empty($atts['width'])) {
$width_rule = sprintf('width: %dpx; ', $atts['width']);
}
if (!empty($atts['height'])) {
$height_rule = sprintf('height: %dpx;', $atts['height']);
}
$output = sprintf('<div style="%s%s" class="wp-video">%s</div>', $width_rule, $height_rule, $html);
return $output;
}