Video 通过自定义上传插件在评论中输出Youtube视频

Video 通过自定义上传插件在评论中输出Youtube视频,video,comments,youtube-api,wordpress,Video,Comments,Youtube Api,Wordpress,我正在为一个客户端开发一个插件,它允许用户上传视频,以便轻松上传视频并显示视频以供评论。通过Youtube API,用户将填写视频信息,并在我的客户网站的评论部分上传视频。pluggin将同时将视频上传到社区Youtube帐户,并在评论中显示视频 Youtube视频以url的形式存储在WordPress站点的评论元中 我已经成功创建了上传Youtube和存储结果URL的系统 我的问题在于试图显示视频。我发现WordPress不想这样做。我尝试了四种不同的方法来达到我的效果,但都没有效果 尝试1:

我正在为一个客户端开发一个插件,它允许用户上传视频,以便轻松上传视频并显示视频以供评论。通过Youtube API,用户将填写视频信息,并在我的客户网站的评论部分上传视频。pluggin将同时将视频上传到社区Youtube帐户,并在评论中显示视频

Youtube视频以url的形式存储在WordPress站点的评论元中

我已经成功创建了上传Youtube和存储结果URL的系统

我的问题在于试图显示视频。我发现WordPress不想这样做。我尝试了四种不同的方法来达到我的效果,但都没有效果

尝试1:已处理的短代码

add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){

  if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
    $youtube = '[video src="http://www.youtube.com/watch?v='.$youtube.'" ]';
    $text = do_shortcode($youtube) . '<p>' . $text . '</p>';
  }
  return $text;
}
add_filter('comment_text','modify_comment');
函数修改注释($text){
if($youtube=get_comment_meta(get_comment_ID(),'youtube',true)){
$youtube='[video src=”http://www.youtube.com/watch?v=“.$youtube.”“];
$text=do_shortcode($youtube)。“”。$text.“

”; } 返回$text; }
输出:可点击的URL

尝试2:普通短代码

add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){

  if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
    $youtube = '[video src="http://www.youtube.com/watch?v='.$youtube.'" ]';
    $text = $youtube . '<p>' . $text . '</p>';
  }
  return $text;
}
add_filter('comment_text','modify_comment');
函数修改注释($text){
if($youtube=get_comment_meta(get_comment_ID(),'youtube',true)){
$youtube='[video src=”http://www.youtube.com/watch?v=“.$youtube.”“];
$text=$youtube.“”.$text.“

”; } 返回$text; }
输出:将短代码显示为纯文本

尝试3:构造iFrame

    add_filter( 'comment_text', 'modify_comment');
    function modify_comment( $text ){

      if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
        $youtube = '<div><iframe title="YouTube video player" class="youtube-player" type="text/html" width="640"
height="390" src="http://www.youtube.com/watch?v='.$youtube.'" frameborder="0"
allowFullScreen></iframe></div>';
        $text = $youtube . $text;
      }
      return $text;
    }
add_filter('comment_text','modify_comment');
函数修改注释($text){
if($youtube=get_comment_meta(get_comment_ID(),'youtube',true)){
$youtube='';
$text=$youtube.$text;
}
返回$text;
}
输出:空的白色框(断开的iFrame)

尝试4:只是URL

add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){

  if( $youtube = get_comment_meta( get_comment_ID(), 'youtube', true ) ) {
    $youtube = 'http://www.youtube.com/watch?v='.$youtube.';
    $text = $youtube . '<p>' . $text . '</p>';
  }
  return $text;
 }
add_filter('comment_text','modify_comment');
函数修改注释($text){
if($youtube=get_comment_meta(get_comment_ID(),'youtube',true)){
$youtube=http://www.youtube.com/watch?v=“.$youtube”;
$text=$youtube.“”.$text.“

”; } 返回$text; }
输出:纯文本URL(有点像预期的那样)


以前有人尝试过吗?你能想出其他方法吗?

FYI这是否已经达到你的目的了?非常相似,但不完全相同。我从这个插件中得到了一些灵感。Youtube上传小部件插件是用于创建帖子的,我正试图为评论者提供类似的功能。