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

StackOverflow https://stackoverflow.com/questions/18041225

  •  23-06-2022
  •  | 
  •  

Pregunta

I've had a look at a lot of the similar questions and I'm not getting it, with regards to my code.

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

and here is my code....

// 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

If I remove the section in the conditional below the comment "send it to wp_oembed to see if the link is oembed enabled.", but stranger still if I pass it a soundcloud link - no error, but if its a locally hosted file it goes tits up.

Any Help would be greatly appreciated.

after a bit of fidling - seems the problem is related to this function http://codex.wordpress.org/Function_Reference/wp_oembed_get

and what thats referencing in the incldued class-oembed.php says the following on line 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 ) ) ) {
¿Fue útil?

Solución 2

for the time being I'm avoided using wp_oembed_get altogether by swopping my conditionals and if its not an iframe or using the following which seems to determine whether its a locally hosted, or oembed link automagically....

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

and then echo'ing $post_embed

Otros consejos

You should not use assignments (=) inside your ternary expression as you will run into problems with operator precedence.

You could write it like:

$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>');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top