Shortcode breaks site on PHP 8.1
-
Hi, I tried upgrading my development environment to PHP 8.1 and encountered issues with some plugins I’ve created. These plugins register shortcodes which require PHP files. The code generally looks like this:
function shortcode($attributes = []) { ob_start(); include 'path/to/file.php'; return ob_get_contents(); } add_shortcode('my-plugin', __NAMESPACE__ . '\\shortcode');
Notice I am using namespaces. This code works on PHP 7.4. When using PHP 8.1, I get two main errors: when trying to edit the page on which the shortcode is included, I get a fatal error; when displaying the page on which the shortcode is used, the get_footer function does not load (in other words, the shortcode runs and then there is no more output). I can’t seem to find any clues in the WordPress updates concerning PHP 8, but I do see that there are some support tickets about plugins with shortcodes crashing after an update. Any help?
- The topic ‘Shortcode breaks site on PHP 8.1’ is closed to new replies.