{"id":2617946,"date":"2012-03-09T01:06:15","date_gmt":"2012-03-09T01:06:15","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/plugin-multiple-sidebars-bugs-in-method-dynamic_sidebar\/"},"modified":"2016-08-20T05:28:21","modified_gmt":"2016-08-20T05:28:21","slug":"plugin-multiple-sidebars-bugs-in-method-dynamic_sidebar","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/plugin-multiple-sidebars-bugs-in-method-dynamic_sidebar\/","title":{"rendered":"[Plugin: Multiple Sidebars] Bugs in method dynamic_sidebar()"},"content":{"rendered":"<p>Hi,<\/p>\n<p>Me again. I&#8217;ve found two bugs in method dynamic_sidebar() in code fragment<\/p>\n<pre><code>$sidebars = explode(&quot;,&quot;, $sidebars);\nif(!$sidebars){\n\t$sidebars = &quot;multiple-sidebars-default&quot;;\n}\nforeach ($sidebars as $sidebar) {\n\tif (is_active_sidebar($sidebar)) {\n\t\tdynamic_sidebar($sidebar);\n\t}\n}<\/code><\/pre>\n<p>One problem is the use of the function explode(). If $sidebars is an empty string it returns an none empty array which contains one empty element (<code>count($sidebars)==1<\/code>). Thus the following if-statement <code>if(!$sidebars) { ... }<\/code> will always fail as the array is not empty. Finally the <code>foreach (...)<\/code> will loop and call function &#8216;is_active_sidebar($sidebar)` with an empty string. This will always fail and the default sidebar is never displayed as fallback.<\/p>\n<p>The second problem is the definition of the array for the name of the default sidebar <code>$sidebars = &quot;multiple-sidebars-default&quot;;<\/code>. The assignment of a string to a variable is not an array. You have to cast the string into an array before assignment <code>$sidebars = array(&quot;multiple-sidebars-default&quot;);<\/code>. But as this statement was never executed it had no effect on the code.<\/p>\n<p>Together with my suggestion from the other post the modified code could be<\/p>\n<pre><code>$sidebars = empty($sidebars) ? array(&#039;multiple-sidebars-default&#039;) : explode(&#039;,&#039;, $sidebars);\nforeach ($sidebars as $sidebar) {\n\tif (is_active_sidebar($sidebar)) {\n\t\t$success = dynamic_sidebar($sidebar) ? true : $success;\n\t}\n}<\/code><\/pre>\n<p>https:\/\/wordpress.org\/extend\/plugins\/multiple-sidebars\/<\/p>\n","protected":false},"template":"","class_list":["post-2617946","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2617946","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":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2617946\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2617946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}