mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
Turn the Nav Menu meta boxes into an accordion. Less sprawling and overwhelming.
* Registration stays the same — they're meta boxes * Call `do_accordion_sections()` instead of `do_meta_boxes()` and they render as an accordion props DrewAPicture, lessbloat, jkudish. fixes #23450. see #23449 git-svn-id: https://develop.svn.wordpress.org/trunk@23707 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -387,11 +387,11 @@ function _wp_ajax_menu_quick_search( $request = array() ) {
|
||||
function wp_nav_menu_setup() {
|
||||
// Register meta boxes
|
||||
wp_nav_menu_post_type_meta_boxes();
|
||||
add_meta_box( 'add-custom-links', __( 'Add Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
|
||||
add_meta_box( 'add-custom-links', __( 'Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
|
||||
wp_nav_menu_taxonomy_meta_boxes();
|
||||
|
||||
// Register advanced menu items (columns)
|
||||
add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns');
|
||||
add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
|
||||
|
||||
// If first time editing, disable advanced items by default.
|
||||
if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
|
||||
@@ -447,7 +447,9 @@ function wp_nav_menu_post_type_meta_boxes() {
|
||||
$post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
|
||||
if ( $post_type ) {
|
||||
$id = $post_type->name;
|
||||
add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
|
||||
// give pages a higher priority
|
||||
$priority = ( 'page' == $post_type->name ? 'core' : 'default' );
|
||||
add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -565,21 +567,20 @@ function wp_nav_menu_item_link_meta_box() {
|
||||
|
||||
?>
|
||||
<div class="customlinkdiv" id="customlinkdiv">
|
||||
<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
|
||||
<p id="menu-item-url-wrap">
|
||||
<label class="howto" for="custom-menu-item-url">
|
||||
<span><?php _e('URL'); ?></span>
|
||||
<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
|
||||
<p id="menu-item-url-wrap">
|
||||
<label class="howto" for="custom-menu-item-url">
|
||||
<span><?php _e('URL'); ?></span>
|
||||
<input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p id="menu-item-name-wrap">
|
||||
<label class="howto" for="custom-menu-item-name">
|
||||
<span><?php _e( 'Link Text' ); ?></span>
|
||||
<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<p id="menu-item-name-wrap">
|
||||
<label class="howto" for="custom-menu-item-name">
|
||||
<span><?php _e( 'Link Text' ); ?></span>
|
||||
<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<span class="add-to-menu">
|
||||
@@ -683,10 +684,22 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
|
||||
?>
|
||||
<div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
|
||||
<ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
|
||||
<li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent"><?php _e('Most Recent'); ?></a></li>
|
||||
<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li>
|
||||
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li>
|
||||
</ul>
|
||||
<li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-most-recent" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent">
|
||||
<?php _e( 'Most Recent' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all">
|
||||
<?php _e( 'View All' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-search" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
|
||||
<?php _e( 'Search'); ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul><!-- .posttype-tabs -->
|
||||
|
||||
<div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php
|
||||
echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
|
||||
@@ -893,10 +906,22 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
|
||||
?>
|
||||
<div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
|
||||
<ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
|
||||
<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
|
||||
<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"><?php _e('View All'); ?></a></li>
|
||||
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"><?php _e('Search'); ?></a></li>
|
||||
</ul>
|
||||
<li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop">
|
||||
<?php _e( 'Most Used' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all">
|
||||
<?php _e( 'View All' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
|
||||
<a class="nav-tab-link" data-type="tabs-panel-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
|
||||
<?php _e( 'Search' ); ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul><!-- .taxonomy-tabs -->
|
||||
|
||||
<div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php
|
||||
echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
|
||||
|
||||
@@ -967,6 +967,70 @@ function remove_meta_box($id, $screen, $context) {
|
||||
$wp_meta_boxes[$page][$context][$priority][$id] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta Box Accordion Template Function
|
||||
*
|
||||
* Largely made up of abstracted code from {@link do_meta_boxes()}, this
|
||||
* function serves to build meta boxes as list items for display as
|
||||
* a collapsible accordion.
|
||||
*
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
|
||||
*
|
||||
* @param string|object $screen The screen identifier.
|
||||
* @param string $context The meta box context.
|
||||
* @param mixed $object gets passed to the section callback function as first parameter.
|
||||
* @return int number of meta boxes as accordion sections.
|
||||
*/
|
||||
function do_accordion_sections( $screen, $context, $object ) {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
if ( empty( $screen ) )
|
||||
$screen = get_current_screen();
|
||||
elseif ( is_string( $screen ) )
|
||||
$screen = convert_to_screen( $screen );
|
||||
|
||||
$page = $screen->id;
|
||||
|
||||
$hidden = get_hidden_meta_boxes( $screen );
|
||||
?>
|
||||
<div id="side-sortables" class="accordion-container">
|
||||
<ul class="outer-border">
|
||||
<?php
|
||||
$i = 0;
|
||||
do {
|
||||
if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
|
||||
break;
|
||||
|
||||
foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
|
||||
if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
|
||||
foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
|
||||
if ( false == $box || ! $box['title'] )
|
||||
continue;
|
||||
$i++;
|
||||
$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
|
||||
?>
|
||||
<li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
|
||||
<h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3>
|
||||
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
|
||||
<div class="inside">
|
||||
<?php call_user_func( $box['callback'], $object, $box ); ?>
|
||||
</div><!-- .inside -->
|
||||
</div><!-- .accordion-section-content -->
|
||||
</li><!-- .accordion-section -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(0);
|
||||
?>
|
||||
</ul><!-- .outer-border -->
|
||||
</div><!-- .accordion-container -->
|
||||
<?php
|
||||
return $i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to a settings page.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user