{"id":18997528,"date":"2026-08-19T15:36:47","date_gmt":"2026-08-19T15:36:47","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/bug-report-undefined-variable-output-php-warning-in-su_feed-shortcode\/"},"modified":"2026-08-19T16:40:42","modified_gmt":"2026-08-19T16:40:42","slug":"bug-report-undefined-variable-output-php-warning-in-su_feed-shortcode","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/bug-report-undefined-variable-output-php-warning-in-su_feed-shortcode\/","title":{"rendered":"Bug Report: &#8220;Undefined variable $output&#8221; PHP warning in [su_feed] shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Bug Report: &#8220;Undefined variable $output&#8221; PHP warning in [su_feed] shortcode<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Plugin: Shortcodes Ultimate (shortcodes-ultimate)<br \/>Version: 7.8.4 (latest as of 2026-08-19)<br \/>WordPress: 7.0.4<br \/>PHP: 8.5.4<br \/>Status: Active Summary<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using the [su_feed] shortcode on a page emits a PHP warning on every render:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP Warning: Undefined variable $output in\n...\/shortcodes-ultimate\/includes\/shortcodes\/feed.php on line 83<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The shortcode still outputs the feed correctly \u2014 this is a log-noise warning,<br \/>not a visible break \u2014 but it fires on every page load that includes feed items,<br \/>which quickly floods the PHP-FPM\/nginx error log. Steps to reproduce<\/p>\n\n\n\n<ol>\n<li>Install Shortcodes Ultimate 7.8.4 on WordPress 7.0.4 with PHP 8.x.<\/li>\n\n\n\n<li>Add a page containing a feed shortcode with items available, e.g.:<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">[su_feed url=&#8221;https:\/\/example.com\/category\/news\/feed\/&#8221; limit=&#8221;-1&#8243;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(Also reproduced with limit=&#8221;3&#8243;. The site uses the compatibility prefix<br \/>option &#8220;su_&#8221;, so the tag is [su_feed].)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Load the page. The warning is emitted once per shortcode render. Root cause<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In includes\/shortcodes\/feed.php, the variable $output is used with the<br \/>concatenating assignment operator inside the foreach loop, but is never<br \/>initialized before the loop:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>foreach ( $items as $item ) {\n\n    $output .= sprintf(\n        '&lt;li&gt;&lt;a href=\"%s\" target=\"_%s\" title=\"%s\"&gt;%s&lt;\/a&gt;&lt;\/li&gt;',\n        esc_url( $item-&gt;get_permalink() ),\n        sanitize_key( $atts&#091;'target'] ),\n        esc_attr( $item-&gt;get_description() ),\n        wp_kses_post( $item-&gt;get_title() )\n    );\n\n}\n\nreturn sprintf(\n    '&lt;ul class=\"su-feed%s\"&gt;%s&lt;\/ul&gt;',\n    esc_attr( su_get_css_class( $atts ) ),\n    $output\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the first loop iteration, $output is undefined, so PHP 8 emits<br \/>&#8220;Undefined variable $output&#8221;. (PHP reports the warning at the line where the<br \/>sprintf argument list ends \u2014 line 83 in 7.8.4 \u2014 which made it slightly<br \/>confusing to track down at first.) Suggested fix (one line)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Initialize $output before the loop:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$output = '';\n\nforeach ( $items as $item ) {\n    ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(If the early-return guard &#8220;if ( ! count( $items ) )&#8221; were ever removed, the<br \/>same initialization would also protect the return statement below the loop.) Workaround<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For anyone hitting this before the fix ships: a must-use plugin that<br \/>re-registers the &#8220;feed&#8221; shortcode with a corrected callback (remove_shortcode +<br \/>add_shortcode on init, priority 50 \u2014 after SU registers at priority 40)<br \/>removes the warning without modifying plugin files. <br \/><br \/><strong>Notes<\/strong><\/p>\n\n\n\n<ul>\n<li>Warning is cosmetic: feed HTML output is correct.<\/li>\n\n\n\n<li>Occurs on PHP 8.x; will also affect PHP 9 when release notes inevitably<br \/>promote undefined-variable notices to errors (PHP 8.0+ already emits the<br \/>warning under error_reporting(E_ALL)).<\/li>\n\n\n\n<li>Only affects the free &#8220;feed&#8221; shortcode; other shortcodes were not checked<br \/>for the same pattern.<\/li>\n<\/ul>\n","protected":false},"template":"","class_list":["post-18997528","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18997528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18997528\/revisions"}],"predecessor-version":[{"id":18997533,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18997528\/revisions\/18997533"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18997528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}