• Resolved ace0930

    (@ace0930)


    I use the below code to remove the widget from the dashboard that a plugin adds.

    
    add_action ( 'do_meta_boxes', 'remove_plugin_metaboxes' );
    
    function remove_plugin_metaboxes () {
       remove_meta_box ( 'plugin_wwidget_id' , 'dashboard' , 'normal' );
    }
    

    Do I need to check if the meta box/ widget exists then only remove_meta_box?
    Because after looking at the source of https://developer.www.ads-software.com/reference/functions/remove_meta_box/
    I still cannot figure out if it has check it, if no, how do I check?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You don’t need to check. Code similar to if ( ! isset( $wp_meta_boxes[ $page ] ) ) in remove_meta_box() is the check. All meta box registration does is push a reference to the class object into a global array. So if the passed element key names are not set, the box is not registered.

    Even if there were no check at all, all that would happen is an “array key does not exist” warning is triggered. Other than filling up the error log, no other ill effect would occur. Bad coding to do no check anywhere, but no real harm done.

Viewing 1 replies (of 1 total)
  • The topic ‘Check if meta box exist’ is closed to new replies.