Support

Account

Home Forums Feature Requests Options page: allow me to hide the Publish meta box Reply To: Options page: allow me to hide the Publish meta box

  • G’day Mate,

    the submit area is just a regular wp meta box. If it’s regular wp metabox, then it can be removed.

    with a quick deep following the breadcrumb, these are the general process for an option page:

    1) /pro/admin/admin-options-page.php line 29, which added the all acf options pages via the “admin_menu” hook

    2) inside the “admin_menu” hook’s function, it then add the admin_load function via the “load-{$slug}” actions. (where $slug is the acf option page slug)

    3) in that admin_load function, it then add add the admin_head function via the “acf/input/admin_head” action.

    4) in that admin_head function, that’s where the meta box is being added with “add_meta_box”. (line 200)

    which mean, we could just call ‘remove_meta_box’ after the “load-{$slug}” action to remove the metabox.

    But now you may ask, how in the heck can you get that $slug? well, if you look at the menu page function in the codex, https://developer.wordpress.org/reference/functions/add_submenu_page/ (line 1190)

    the $slug is get_plugin_page_hookname($menu_slug, $parent_slug), which the $menu_slug in acf is $page[‘menu_slug’] and $parent_slug is $page[‘parent_slug’].

    So, for example, if you have an option page that’s added with,

    acf_add_options_sub_page('Theme Tasks');,

    then, $page[‘parent_slug’] is “acf-options” and
    $page[‘menu_slug’] is 'acf-options-' . sanitize_title( $page['menu_title'] );,
    aka, ‘acf-options-theme-tasks’.

    Therefore, to retrieve the $slug, you can call get_plugin_page_hookname('acf-options-theme-tasks', 'acf-options')

    ======= with all info from above, we can then come up with =======

    
    acf_add_options_sub_page('Theme Tasks');
    
    add_action('admin_menu', 'maybe_find_and_remove_that_meta_box', 100, 0);
    
    function maybe_find_and_remove_that_meta_box() {
        $option_page_slug = get_plugin_page_hookname('acf-options-theme-tasks', 'acf-options');
    
        add_action("load-{$option_page_slug}", 'add_that_remove_meta_box_action', 11);
    }
    
    function add_that_remove_meta_box_action() {
        add_action('acf/input/admin_head', 'remove_that_damn_meta_box', 11);
    
        // also change it to 1 column, so you don't have empty sidebar 
        add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
    }
    
    function remove_that_damn_meta_box() {
        remove_meta_box('submitdiv', 'acf_options_page', 'side');
    }
    

    I know this might be a lot to take in. Have fun 🙂

    Cheers