Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP Oembed未通过“;自动播放=1”;变量_Php_Javascript_Wordpress_Youtube_Oembed - Fatal编程技术网

Php WP Oembed未通过“;自动播放=1”;变量

Php WP Oembed未通过“;自动播放=1”;变量,php,javascript,wordpress,youtube,oembed,Php,Javascript,Wordpress,Youtube,Oembed,我有这个问题 我正在通过一个自定义字段传递它 (注意“autoplay=1”) 但是当我用wp\u oembed\u get加载我的主题视频时。。。它可以很好地显示视频,但不监听我正在传递的autoplay=1变量 我需要在加载页面时播放视频。查找功能wp\u oembed\u获取并使用args传递自动播放。。。应该行得通。只需粘贴在视频的url中,而不是自动播放(&autoplay)。。。您将把它编码到函数的args部分。通过将wp includes/media.php中的wp_oembed_

我有这个问题

我正在通过一个自定义字段传递它

(注意“autoplay=1”)

但是当我用
wp\u oembed\u get
加载我的主题视频时。。。它可以很好地显示视频,但不监听我正在传递的
autoplay=1
变量


我需要在加载页面时播放视频。

查找功能wp\u oembed\u获取并使用args传递自动播放。。。应该行得通。只需粘贴在视频的url中,而不是自动播放(&autoplay)。。。您将把它编码到函数的args部分。

通过将wp includes/media.php中的wp_oembed_get()函数修改为:

function wp_oembed_get( $url, $args = '' ) {
    // Manually build the IFRAME embed with the related videos option disabled and autoplay turned on
    if(preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)){
        return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $aMatch[1] . '?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
    }

    require_once( ABSPATH . WPINC . '/class-oembed.php' );
    $oembed = _wp_oembed_get_object();
    return $oembed->get_html( $url, $args );
}
函数wp_oembed_get($url,$args=''){
//在禁用相关视频选项并启用自动播放的情况下手动构建IFRAME嵌入
if(preg_match(“/youtube.com\/watch\?v=([^&]+)/i”,$url,$aMatch)){
返回“”;
}
require_once(ABSPATH.WPINC.'/class oembed.php');
$oembed=_wp_oembed_get_object();
返回$oembed->get_html($url,$args);
}

我认为这样做的方法是使用wordpress过滤器:

function modify_youtube_embed_url($html) {
    return str_replace("?feature=oembed", "?feature=oembed&autoplay=1", $html);
}
add_filter('oembed_result', 'modify_youtube_embed_url');

这是我在functions.php中的解决方案

function embed_responsive_autoplay($code){
    if(strpos($code, 'youtu.be') !== false || strpos($code, 'youtube.com') !== false){
        $return = preg_replace('@embed/([^"&]*)@', 'embed/$1&showinfo=0&autoplay=1', $code);
        return '<div class="embed-container">' . $return . '</div>';
    }
    return '<div class="embed-container">' . $code . '</div>';
}

add_filter( 'embed_oembed_html', 'embed_responsive_autoplay');
add_filter( 'video_embed_html', 'embed_responsive_autoplay' ); // Jetpack
函数嵌入\响应\自动播放($code){
if(strpos($code,'youtu.be')!==false | | strpos($code,'youtube.com')!==false){
$return=preg_replace('@embed/([^“&]*)@','embed/$1&showinfo=0&autoplay=1',$code);
返回“.$return.”;
}
返回“.$code.”;
}
添加过滤器('embed_oembed_html','embed_responsive_autoplay');
添加过滤器('video_embed_html','embed_responsive_autoplay');//Jetpack

享受吧!

因此,在对此进行了一些研究之后,最好的方法是利用
oembed_fetch_url
过滤器钩子向oembed请求url添加额外参数。我的具体目标是允许自动播放参数,但此方法易于根据您需要的任何oembed参数进行定制

首先,将其添加到
functions.php


这是一个非常有帮助的评论!…你找到解决方案了吗?我还试图在我的php脚本中传递这个值。^^不,我不得不通过一个自定义字段传递它。另外,在进行此更改后,请确保运行以下SQL查询,以便刷新嵌入:从wp_posteta中删除,其中的meta_键类似于“\u oembed_%”
[embed autoplay="true"]https://vimeo.com/1234567890/1234567890[/embed]