Bug Report: Fatal Error – `remove_meta_box()` Called Too Early
-
A fatal error occurs when the plugin is active alongside WP Umbrella (and likely other plugins that trigger
set_current_screen()during thewp_loadedaction).Error:
Uncaught Error: Call to undefined function remove_meta_box() in guest-author.php:174Root Cause
remove_default_author_meta_box()is hooked tocurrent_screen, butremove_meta_box()is defined inwp-admin/includes/template.php, which is not yet loaded at that point in the request lifecycle whencurrent_screenis fired early (e.g. via a third-party plugin callingWP_Screen::set_current_screen()duringwp_loaded).Suggested Fix
In
plugin_admin_setup(), change the hook forremove_default_author_meta_boxfromcurrent_screentoadd_meta_boxes:// Before: add_action('current_screen', array($this, 'remove_default_author_meta_box')); // After: add_action('add_meta_boxes', array($this, 'remove_default_author_meta_box'));remove_meta_box()is guaranteed to be available by the timeadd_meta_boxesfires, and the method’s internal use ofget_current_post_type()(which reads from$post,$typenow, and$current_screen) continues to work correctly at that hook.
The topic ‘Bug Report: Fatal Error – `remove_meta_box()` Called Too Early’ is closed to new replies.