Skip to content

Commit

Permalink
Merge branch 'add/lights-switcher' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
madalingorbanescu committed Nov 17, 2020
2 parents 09ba85d + 136aa56 commit 36885d0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions inc/admin/class-admin-nav-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function __construct() {
// Handle custom fields
add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'add_custom_fields' ), 5, 2 );
add_action( 'wp_update_nav_menu_item', array( $this, 'save_custom_fields' ), 10, 3 );
// Make sure that out menu boxes appear by default (the core hides them by default).
add_filter( "update_user_metadata", array( $this, 'unhide_our_menu_boxes' ), 10, 5 );

add_filter( 'wp_setup_nav_menu_item', array( $this, 'setup_nav_menu_item' ), 10, 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_styles' ), 10, 1 );
Expand Down Expand Up @@ -254,6 +256,24 @@ public function save_custom_fields( $menu_id, $menu_item_db_id, $args ) {
}
}

public function unhide_our_menu_boxes( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
global $wp_meta_boxes;

if ( $meta_key !== 'metaboxhidden_nav-menus' || ! is_array( $meta_value ) || get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) {
// Nothing to do.
return $check;
}

// We will remove our menu boxes from the $meta_value.
foreach ( $this->menu_items_boxes_config as $box_id => $box_config ) {
if ( false !== $key = array_search( $box_id, $meta_value ) ) {
unset( $meta_value[ $key ] );
}
}

return add_metadata( 'user', $object_id, $meta_key, $meta_value );
}

public function add_extras_items( $object ) {
global $nav_menu_selected_id;

Expand Down

0 comments on commit 36885d0

Please sign in to comment.