• Resolved Zack Pyle

    (@zackpyle)


    A fatal error occurs when the plugin is active alongside WP Umbrella (and likely other plugins that trigger set_current_screen() during the wp_loaded action).

    Error:

    Uncaught Error: Call to undefined function remove_meta_box()
    in guest-author.php:174

    Root Cause

    remove_default_author_meta_box() is hooked to current_screen, but remove_meta_box() is defined in wp-admin/includes/template.php, which is not yet loaded at that point in the request lifecycle when current_screen is fired early (e.g. via a third-party plugin calling WP_Screen::set_current_screen() during wp_loaded).

    Suggested Fix

    In plugin_admin_setup(), change the hook for remove_default_author_meta_box from current_screen to add_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 time add_meta_boxes fires, and the method’s internal use of get_current_post_type() (which reads from $post, $typenow, and $current_screen) continues to work correctly at that hook.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Bug Report: Fatal Error – `remove_meta_box()` Called Too Early’ is closed to new replies.