PHP in Widgets Disappearing / Theme Console Issue

Hello:

I enabled the use of PHP in widgets via functions.php. The code I’m using is:

function php_execute($html){
if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter(‘widget_text’,‘php_execute’,100);

It has worked great for the past year or so, but I noticed it recently stopped displaying in the admin. The PHP executes, because the front-end of the site is fine. When I go into the widget area and select the widget and text area the PHP is in, it flickers really fast and disappears. There’s no way to edit or remove it. You can only delete the text area and create a new one. In the console, I see this error:

I haven’t done anything to change any parent theme files. Can you point me in the right direction how to fix this?

I found a simliar post here, but didn’t find any resolve:

Hello There,

Thanks for posting in! Regretfully we cannot support this issue because it involves 3rd party script. Your script may have triggered an internal error with WordPress core. It has worked before and it stopped maybe because of the WordPress code updates. Please disable your code first and see if the JS error will still exist.

Please let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.