• Bug Report: “Undefined variable $output” PHP warning in [su_feed] shortcode

    Plugin: Shortcodes Ultimate (shortcodes-ultimate)
    Version: 7.8.4 (latest as of 2026-08-19)
    WordPress: 7.0.4
    PHP: 8.5.4
    Status: Active Summary

    Using the [su_feed] shortcode on a page emits a PHP warning on every render:

    PHP Warning: Undefined variable $output in
    .../shortcodes-ultimate/includes/shortcodes/feed.php on line 83

    The shortcode still outputs the feed correctly — this is a log-noise warning,
    not a visible break — but it fires on every page load that includes feed items,
    which quickly floods the PHP-FPM/nginx error log. Steps to reproduce

    1. Install Shortcodes Ultimate 7.8.4 on WordPress 7.0.4 with PHP 8.x.
    2. Add a page containing a feed shortcode with items available, e.g.:

    [su_feed url=”https://example.com/category/news/feed/” limit=”-1″]

    (Also reproduced with limit=”3″. The site uses the compatibility prefix
    option “su_”, so the tag is [su_feed].)

    Load the page. The warning is emitted once per shortcode render. Root cause

    In includes/shortcodes/feed.php, the variable $output is used with the
    concatenating assignment operator inside the foreach loop, but is never
    initialized before the loop:

    foreach ( $items as $item ) {
    
        $output .= sprintf(
            '<li><a href="%s" target="_%s" title="%s">%s</a></li>',
            esc_url( $item->get_permalink() ),
            sanitize_key( $atts['target'] ),
            esc_attr( $item->get_description() ),
            wp_kses_post( $item->get_title() )
        );
    
    }
    
    return sprintf(
        '<ul class="su-feed%s">%s</ul>',
        esc_attr( su_get_css_class( $atts ) ),
        $output
    );

    On the first loop iteration, $output is undefined, so PHP 8 emits
    “Undefined variable $output”. (PHP reports the warning at the line where the
    sprintf argument list ends — line 83 in 7.8.4 — which made it slightly
    confusing to track down at first.) Suggested fix (one line)

    Initialize $output before the loop:

    $output = '';
    
    foreach ( $items as $item ) {
        ...

    (If the early-return guard “if ( ! count( $items ) )” were ever removed, the
    same initialization would also protect the return statement below the loop.) Workaround

    For anyone hitting this before the fix ships: a must-use plugin that
    re-registers the “feed” shortcode with a corrected callback (remove_shortcode +
    add_shortcode on init, priority 50 — after SU registers at priority 40)
    removes the warning without modifying plugin files.

    Notes

    • Warning is cosmetic: feed HTML output is correct.
    • Occurs on PHP 8.x; will also affect PHP 9 when release notes inevitably
      promote undefined-variable notices to errors (PHP 8.0+ already emits the
      warning under error_reporting(E_ALL)).
    • Only affects the free “feed” shortcode; other shortcodes were not checked
      for the same pattern.
    • This topic was modified 2 weeks, 3 days ago by Hayward.

You must be logged in to reply to this topic.