• Resolved HighKay

    (@hlorenz)


    Hi,

    since I changed to PHP 8.0 I get this error-Message:

    plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 11

    How can I find out, which snippet is causing this error?

    Thanks for your help
    Heike

    • This topic was modified 1 year, 8 months ago by HighKay.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi Heike,

    Do you have the full error message available? All I can tell you from that is that the error occurred on line 11 of a snippet.

    Thread Starter HighKay

    (@hlorenz)

    Hi @bungeshea ,

    here is the complete error message:

    Undefined variable $post in xxxxx/wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()'d code on line 11
    
    Attempt to read property "ID" on null in xxxxx/wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()'d code on line 11

    I found the snippet that is causing the error – thanks to your help with the search function ??

    But now I’m stuck, cause I don’t know how to repair the snippet code – would you mind helping me?

    Here is the code:

    // Add featured image to RSS feed
    add_filter('the_excerpt_rss', 'j0e_imagetoRSS');
    add_filter('the_content_feed', 'j0e_imagetoRSS');
    
    function j0e_imagetoRSS($content)
    {
    $label = 'Tags: ';
    
    if (has_post_thumbnail()) {
    $content = '
    
    
    ' . get_the_post_thumbnail($post->ID, 'zuki-medium-portrait', array('style' => 'max-width: 100%; height: auto; margin-bottom: 10px;')) . '
    ' . $content .
    '
    
    ' . $label . j0e_show_tags() . '';
    }
    return $content;
    }
    
    // Creates the tags list
    function j0e_show_tags()
    {
    $post_tags = get_the_tags();
    $separator = ' | ';
    $output = '';
    if (!empty($post_tags)) {
    foreach ($post_tags as $tag) {
    $output .= 'term_id)) . '">#' . $tag->name . '' . $separator;
    }
    }
    return trim($output, $separator);
    }

    It is the line with the “$post->ID” in it.

    That would be really really kind ??

    Thanks
    Heike

    • This reply was modified 1 year, 8 months ago by HighKay.
    Plugin Author Shea Bunge

    (@bungeshea)

    Looks like some of that snippet is missing – specifically the part that creates the tag links. I’ve tried to recreate it where I can, and hopefully strengthened the code to prevent PHP errors.

    $callback = function ( $content ) {
    	if ( has_post_thumbnail() ) {
    		$thumbnail = get_the_post_thumbnail(
    			null,
    			'zuki-medium-portrait',
    			array( 'style' => 'max-width: 100%; height: auto; margin-bottom: 10px;' )
    		);
    
    		$tags = '';
    		$tag_objects = get_the_tags();
    
    		if ( $tag_objects ) {
    			$tag_links = [];
    
    			foreach ( $tag_objects as $tag ) {
    				$tag_links[] = sprintf(
    					'<a href="%s">#%s</a>',
    					esc_url( get_tag_link( $tag ) ),
    					esc_html( $tag->name )
    				);
    			}
    
    			$label = 'Tags: ';
    			$tags = $label . join( ' | ', $tag_links );
    		}
    
    		$content = $thumbnail . $content . $tags;
    	}
    
    	return $content;
    };
    
    // Add featured image to RSS feed
    add_filter( 'the_excerpt_rss', $callback );
    add_filter( 'the_content_feed', $callback );
    Thread Starter HighKay

    (@hlorenz)

    @bungeshea – Thank you sooooooo much!!!!

    That works perfectly ??

    I really appreciate your fast & perfect support!

    Thanks a lot ??

    • This reply was modified 1 year, 8 months ago by HighKay.
    Plugin Author Shea Bunge

    (@bungeshea)

    Glad to hear!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP error / eval()’d code’ is closed to new replies.