0

I know Customizer exists. Some clients do not, or do not want to use it, and use the traditional menu editor. However, the traditional menu editor has "some" quirks.

This is what the menu editor looks to me, the first admin user on the site I'm building:

first admin

This is what I want it to look like, for all users that can edit the menu. However, I do not supply the content on the site, so we created another admin user, but the editor looks like this to him:

second

It took me about 10 minutes to find out why, and I've been working with WP since 3.6. This is a major UX issue, and I need to deal with it. The issue is simple, those "accordions" are actually metaboxes in the eyes of WordPress, and are disabled by default.

screen opts

How do I tick these on programmatically, so it doesn't happen ever again? I don't want to enable all of them, so fine control is necessary.

I could write a few lines of JavaScript, but that's hacky.

I tried looking it up (writing this took time), but didn't find anything useful. This doesn't help me: How to set default screen options?

1 Answer 1

1

The initial nav menu metaboxes are

$initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' );

They register after first time user enter the menus section. So you can register them first after you create a new user.

The function wp_initial_nav_menu_meta_boxes() is setting the user_option metaboxhidden_nav-menus with array of the hidden metaboxes.

And if the user_option already exists its don't do anything. so create this user_option

function change_menu_hidden_metaboxes($user_id) {
    $hidden_metaboxes = array(); // empty array
    update_user_option( $user_id, 'metaboxhidden_nav-menus', $hidden_metaboxes ); // update the user metaboxes
}
add_action( 'user_register', 'change_menu_hidden_metaboxes', 10, 1 );

This function will set empty array for the hidden metaboxes. so all the post types and taxonomies will show. you can add to the array post types or taxonomies that you want to hide.

1
  • I'd rather have global options with no user override, but I guess this'll have to do. Thanks :)
    – Christian
    Commented Dec 14, 2017 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.