{"id":16251901,"date":"2022-12-01T14:34:01","date_gmt":"2022-12-01T14:34:01","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/output-buffer-error-2\/"},"modified":"2022-12-01T14:34:01","modified_gmt":"2022-12-01T14:34:01","slug":"output-buffer-error-2","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/output-buffer-error-2\/","title":{"rendered":"output buffer error"},"content":{"rendered":"<p>Hi! There seems to be an error in your code, within this file:<br \/>\nwp-content\\plugins\\post-grid\\includes\\classes\\class-admin-notices.php<br \/>\nfrom line 33. you have a similar code structure:<\/p>\n<pre><code>if ($screen-&gt;id == &#039;edit-post_grid_layout&#039; ... ) :\n\n\tob_start();\n\n\tif ( ... ) :\n        ...\n\tendif;\n\nendif;\n\necho(ob_get_clean());<\/code><\/pre>\n<p>The problem with this is, that you have &#8220;ob_get_clean&#8221; outside the &#8220;if&#8221;, where &#8220;ob_start&#8221; is. This way when you won&#8217;t go inside that &#8220;if&#8221;, you are closing the output buffer which wasn&#8217;t started by you. So the fix I&#8217;m suggesting is this:<\/p>\n<pre><code>if ($screen-&gt;id == &#039;edit-post_grid_layout&#039; ... ) :\n\n\tob_start();\n\n\tif ( ... ) :\n        ...\n\tendif;\n\n\techo(ob_get_clean());\n\nendif;<\/code><\/pre>\n<p>to move the &#8220;ob_get_clean&#8221; inside the &#8220;if&#8221; too. Would it be possible for you to modify your code to this?<\/p>\n<p>If you need a test, you could use for example this code within the functions.php file of your theme:<\/p>\n<pre><code>add_action(&#039;admin_notices&#039;, &#039;start_test&#039;, 1);\nadd_action(&#039;admin_notices&#039;, &#039;end_test&#039;, 11);\n\nfunction start_test() {\n\tob_start();\n}\n\nfunction end_test() {\n\tob_get_clean();\n}<\/code><\/pre>\n<p>and visit a page, where your &#8220;if&#8221; doesn&#8217;t runs, like in the wp-admin area the Posts or Plugins page. This code will mess up the page, until the fix is done.<\/p>\n","protected":false},"template":"","class_list":["post-16251901","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16251901","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\/16251901\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16251901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}