严格标准:在第116行的wordpress/wp-includes/class-oembed.php中,只有变量应该通过


Strict Standards: Only variables should be passed by reference in wordpress/wp-includes/class-oembed.php on line 116

我已经看了很多类似的问题,但我没有得到关于我的代码的答案。

错误: Strict Standards: Only variables should be passed by reference in wordpress/wp-includes/class-oembed.php on line 116

这是我的代码。。。。

// Get Ready Display the Audio
$embedCheck     = array("<embed", "<ifram");// only checking against the first 6
$mykey_values   = get_post_custom_values('_format_audio_embed');
$content_oembed = '';
// check if the audio metabox is used
if ( isset($mykey_values) && !empty($mykey_values) ) {
    // iterate over values passed
    foreach ( $mykey_values as $key => $value ) {
         $url = $value;
         $wtf = wp_oembed_get($url);
         if ( !empty($url) ) {
            $firstCar = substr($url, 0, 6); // get the first 6 char.
            // if its a http(s).
            if ( strpos($firstCar, "http:/" ) !== false || strpos($firstCar, "https:" ) !== false ) {
                // send it to wp_oembed to see if the link is oembed enabled.

                    $content_oembed = ($wtf !==false)
                  ? ('"<div class="audio" style="width:100%; overflow:hidden;">' .$wtf.'</div>')
                  : ('<audio src="'.$url.'" preload="none" type="audio/mpeg"></audio>');
            }
            // if its the embed code that matches our array defined above.
            else if ( audio_strpos_arr($firstCar, $embedCheck ) !== false ) {
                $content_oembed = '<div class="video" style="width:100%; overflow:hidden;">' .$url. '</div>';
            }
        }
    }; // end foreach
} // end conditional

如果我删除了下面条件中的部分,评论"将其发送到wp_oembed,看看链接是否已启用oembed。",但如果我给它传递一个声音云链接,那就更奇怪了——没有错误,但如果它是本地托管的文件,它就会被打开。

如有任何帮助,我们将不胜感激。

在有点坐立不安之后-问题似乎与这个功能有关http://codex.wordpress.org/Function_Reference/wp_oembed_get

在included class-oembed.php中引用的内容在第116行中如下所示

112         function discover( $url ) {
113                 $providers = array();
114 
115                 // Fetch URL content
116                 if ( $html = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ) ) {

您不应该在三元表达式中使用赋值(=),因为您会遇到运算符优先级的问题。

你可以这样写:

$content_oembed = (wp_oembed_get($url) !==false)
                  ? ('<div class="audio" style="width:100%; overflow:hidden;">' . wp_oembed_get($url).'</div>')
                  : ('<audio src="'.$url.'" preload="none" type="audio/mpeg"></audio>');

暂时我避免使用wp_oembed_get,因为我切换了我的条件,如果它不是iframe,或者使用以下内容来自动确定它是本地托管的还是oembed链接。。。。

global $wp_embed;
$post_embed = $wp_embed->run_shortcode('[embed]'.$url.'[/embed]');

然后echo'ing$post_embed