git-svn-id: https://develop.svn.wordpress.org/trunk@14031 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e12a085938
commit
96ea328c0a
@ -55,7 +55,7 @@ function wp_nav_menu_post_type_metaboxes() {
|
|||||||
|
|
||||||
foreach ( $post_types as $post_type ) {
|
foreach ( $post_types as $post_type ) {
|
||||||
$id = $post_type->name;
|
$id = $post_type->name;
|
||||||
add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type );
|
add_meta_box( "add-{$id}", sprintf( __('Add %s'), $post_type->label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +72,7 @@ function wp_nav_menu_taxonomy_metaboxes() {
|
|||||||
|
|
||||||
foreach ( $taxonomies as $tax ) {
|
foreach ( $taxonomies as $tax ) {
|
||||||
$id = $tax->name;
|
$id = $tax->name;
|
||||||
|
add_meta_box( "add-{$id}", sprintf( __('Add %s'), $tax->label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax );
|
||||||
add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ require_once( 'admin-header.php' );
|
|||||||
<div id="menu-container" class="postbox">
|
<div id="menu-container" class="postbox">
|
||||||
<h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3>
|
<h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3>
|
||||||
<div class="inside">
|
<div class="inside">
|
||||||
<?php echo wp_get_nav_menu( array( 'context' => 'backend', 'menu' => $nav_menu_selected_id ) ); ?>
|
<?php wp_nav_menu( array( 'menu' => $nav_menu_selected_id, 'context' => 'backend' ) ); ?>
|
||||||
</div><!-- /.inside -->
|
</div><!-- /.inside -->
|
||||||
<!-- /#nav-menu-canvas .postbox-->
|
<!-- /#nav-menu-canvas .postbox-->
|
||||||
</div>
|
</div>
|
||||||
|
@ -113,6 +113,7 @@ textarea,
|
|||||||
h3#comments-title,
|
h3#comments-title,
|
||||||
h3#reply-title,
|
h3#reply-title,
|
||||||
#access .menu,
|
#access .menu,
|
||||||
|
#access div.menu ul,
|
||||||
#cancel-comment-reply-link,
|
#cancel-comment-reply-link,
|
||||||
.form-allowed-tags,
|
.form-allowed-tags,
|
||||||
#site-info,
|
#site-info,
|
||||||
@ -153,6 +154,7 @@ code {
|
|||||||
|
|
||||||
/* The main theme structure */
|
/* The main theme structure */
|
||||||
#access .menu-header,
|
#access .menu-header,
|
||||||
|
div.menu,
|
||||||
#colophon,
|
#colophon,
|
||||||
#branding,
|
#branding,
|
||||||
#main,
|
#main,
|
||||||
@ -360,15 +362,15 @@ a:hover {
|
|||||||
display:block;
|
display:block;
|
||||||
float:left;
|
float:left;
|
||||||
}
|
}
|
||||||
#access .menu-header {
|
#access .menu-header, div.menu {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
margin-left: 12px;
|
margin-left: 12px;
|
||||||
}
|
}
|
||||||
#access .menu-header ul {
|
#access .menu-header ul, div.menu ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
#access .menu-header li {
|
#access .menu-header li, div.menu li {
|
||||||
float:left;
|
float:left;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1178,7 @@ class Walker_Nav_Menu extends Walker {
|
|||||||
* @param object $item Menu item data object.
|
* @param object $item Menu item data object.
|
||||||
* @param int $depth Depth of menu item. Used for padding.
|
* @param int $depth Depth of menu item. Used for padding.
|
||||||
* @param int $current_page Menu item ID.
|
* @param int $current_page Menu item ID.
|
||||||
* @param array $args
|
* @param object $args
|
||||||
*/
|
*/
|
||||||
function start_el(&$output, $item, $depth, $args) {
|
function start_el(&$output, $item, $depth, $args) {
|
||||||
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
||||||
@ -1217,7 +1217,6 @@ class Walker_Nav_Menu extends Walker {
|
|||||||
function end_el(&$output, $item, $depth) {
|
function end_el(&$output, $item, $depth) {
|
||||||
$output .= "</li>\n";
|
$output .= "</li>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
* link_before - Text before the link.
|
* link_before - Text before the link.
|
||||||
* link_after - Text after the link.
|
* link_after - Text after the link.
|
||||||
* echo - Whether to echo the menu or return it. Defaults to echo.
|
* echo - Whether to echo the menu or return it. Defaults to echo.
|
||||||
* show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link.
|
*
|
||||||
|
* @todo show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link.
|
||||||
*
|
*
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
@ -31,7 +32,7 @@
|
|||||||
function wp_nav_menu( $args = array() ) {
|
function wp_nav_menu( $args = array() ) {
|
||||||
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
|
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
|
||||||
'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
|
'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
|
||||||
'depth' => 0, 'walker' => '' );
|
'depth' => 0, 'walker' => '', 'context' => 'frontend' );
|
||||||
|
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$args = wp_parse_args( $args, $defaults );
|
||||||
$args = apply_filters( 'wp_nav_menu_args', $args );
|
$args = apply_filters( 'wp_nav_menu_args', $args );
|
||||||
@ -51,70 +52,26 @@ function wp_nav_menu( $args = array() ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $menu && ! is_wp_error( $menu ) )
|
|
||||||
$args->menu = $menu->term_id;
|
|
||||||
$nav_menu = '';
|
|
||||||
|
|
||||||
if ( 'div' == $args->container ) {
|
|
||||||
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : '';
|
|
||||||
|
|
||||||
if ( is_nav_menu($menu) ) {
|
|
||||||
$nav_menu .= '<div id="menu-' . $menu->slug . '"'. $class .'>';
|
|
||||||
} else {
|
|
||||||
$nav_menu .= '<div'. $class .'>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$nav_menu .= wp_get_nav_menu( $args );
|
|
||||||
|
|
||||||
if ( 'div' == $args->container )
|
|
||||||
$nav_menu .= '</div>';
|
|
||||||
|
|
||||||
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
|
|
||||||
|
|
||||||
if ( $args->echo )
|
|
||||||
echo $nav_menu;
|
|
||||||
else
|
|
||||||
return $nav_menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a Navigation Menu.
|
|
||||||
*
|
|
||||||
* See wp_nav_menu() for args.
|
|
||||||
*
|
|
||||||
* @since 3.0.0
|
|
||||||
*
|
|
||||||
* @param array $args Arguments
|
|
||||||
* @return mixed $output False if menu doesn't exists, else, returns the menu.
|
|
||||||
**/
|
|
||||||
function wp_get_nav_menu( $args = array() ) {
|
|
||||||
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend', 'depth' => 0,
|
|
||||||
'fallback_cb' => '', 'walker' => '', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', );
|
|
||||||
|
|
||||||
$args = wp_parse_args( $args, $defaults );
|
|
||||||
$args = apply_filters( 'wp_get_nav_menu_args', $args );
|
|
||||||
$args = (object) $args;
|
|
||||||
|
|
||||||
// Variable setup
|
|
||||||
$nav_menu = '';
|
|
||||||
$items = '';
|
|
||||||
|
|
||||||
// Get the menu object
|
|
||||||
$menu = wp_get_nav_menu_object( $args->menu );
|
|
||||||
|
|
||||||
// If the menu exists, get it's items.
|
// If the menu exists, get it's items.
|
||||||
if ( $menu && !is_wp_error($menu) )
|
if ( $menu && !is_wp_error($menu) )
|
||||||
$menu_items = wp_get_nav_menu_items( $menu->term_id, $args->context );
|
$menu_items = wp_get_nav_menu_items( $menu->term_id, $args->context );
|
||||||
|
|
||||||
// If no menu was found or if the menu has no items, call the fallback_cb
|
// If no menu was found or if the menu has no items, call the fallback_cb
|
||||||
if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) {
|
if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) {
|
||||||
if ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb ) ) {
|
if ( 'frontend' == $args->context && ( function_exists($args->fallback_cb) || is_callable( $args->fallback_cb ) ) ) {
|
||||||
$_args = array_merge( (array) $args, array('echo' => false) );
|
return call_user_func( $args->fallback_cb, (array) $args );
|
||||||
return call_user_func( $args->fallback_cb, $_args );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nav_menu = '';
|
||||||
|
$items = '';
|
||||||
|
$container_allowedtags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'p', 'nav' ) );
|
||||||
|
|
||||||
|
if ( in_array( $args->container, $container_allowedtags ) ) {
|
||||||
|
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-'. $menu->slug .'-container"';
|
||||||
|
$nav_menu .= '<'. $args->container . $class .'>';
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the $menu_item variables
|
// Set up the $menu_item variables
|
||||||
foreach ( (array) $menu_items as $key => $menu_item )
|
foreach ( (array) $menu_items as $key => $menu_item )
|
||||||
@ -122,9 +79,11 @@ function wp_get_nav_menu( $args = array() ) {
|
|||||||
|
|
||||||
$items .= walk_nav_menu_tree( $menu_items, $args->depth, $args );
|
$items .= walk_nav_menu_tree( $menu_items, $args->depth, $args );
|
||||||
|
|
||||||
// CSS class
|
// Attributes
|
||||||
$ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
|
$attributes = ' id="menu-' . $menu->slug . '"';
|
||||||
$nav_menu .= '<ul'. $ul_class .'>';
|
$attributes .= $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
|
||||||
|
|
||||||
|
$nav_menu .= '<ul'. $attributes .'>';
|
||||||
|
|
||||||
// Allow plugins to hook into the menu to add their own <li>'s
|
// Allow plugins to hook into the menu to add their own <li>'s
|
||||||
if ( 'frontend' == $args->context ) {
|
if ( 'frontend' == $args->context ) {
|
||||||
@ -137,7 +96,15 @@ function wp_get_nav_menu( $args = array() ) {
|
|||||||
|
|
||||||
$nav_menu .= '</ul>';
|
$nav_menu .= '</ul>';
|
||||||
|
|
||||||
return apply_filters( 'wp_get_nav_menu', $nav_menu );
|
if ( in_array( $args->container, $container_allowedtags ) )
|
||||||
|
$nav_menu .= '</'. $args->container .'>';
|
||||||
|
|
||||||
|
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
|
||||||
|
|
||||||
|
if ( $args->echo )
|
||||||
|
echo $nav_menu;
|
||||||
|
else
|
||||||
|
return $nav_menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +128,7 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
|
|||||||
|
|
||||||
$output .= $args->before;
|
$output .= $args->before;
|
||||||
$output .= '<a'. $attributes .'>';
|
$output .= '<a'. $attributes .'>';
|
||||||
$output .= $args->link_before . apply_filters('the_title', $menu_item->title) . $args->link_after;
|
$output .= $args->link_before . apply_filters( 'the_title', $menu_item->title ) . $args->link_after;
|
||||||
$output .= '</a>';
|
$output .= '</a>';
|
||||||
$output .= $args->after;
|
$output .= $args->after;
|
||||||
|
|
||||||
@ -218,6 +185,6 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return apply_filters( 'wp_get_nav_menu_item', $output, $context, $args );
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -178,7 +178,7 @@ function walk_nav_menu_tree( $items, $depth, $r ) {
|
|||||||
$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
|
$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
|
||||||
$args = array( $items, $depth, $r );
|
$args = array( $items, $depth, $r );
|
||||||
|
|
||||||
return call_user_func_array(array(&$walker, 'walk'), $args);
|
return call_user_func_array( array(&$walker, 'walk'), $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -202,17 +202,19 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
|
|||||||
if ( 'post_type' == $menu_item->type ) {
|
if ( 'post_type' == $menu_item->type ) {
|
||||||
$object = get_post_type_object( $menu_item->object );
|
$object = get_post_type_object( $menu_item->object );
|
||||||
$menu_item->append = $object->singular_label;
|
$menu_item->append = $object->singular_label;
|
||||||
|
$menu_item->url = get_permalink( $menu_item->object_id );
|
||||||
|
|
||||||
} elseif ( 'taxonomy' == $menu_item->type ) {
|
} elseif ( 'taxonomy' == $menu_item->type ) {
|
||||||
$object = get_taxonomy( $menu_item->object );
|
$object = get_taxonomy( $menu_item->object );
|
||||||
$menu_item->append = $object->singular_label;
|
$menu_item->append = $object->singular_label;
|
||||||
|
$menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$menu_item->append = __('Custom');
|
$menu_item->append = __('Custom');
|
||||||
|
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu_item->title = $menu_item->post_title;
|
$menu_item->title = $menu_item->post_title;
|
||||||
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
|
|
||||||
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
||||||
|
|
||||||
$menu_item->attr_title = strip_tags( $menu_item->post_excerpt );
|
$menu_item->attr_title = strip_tags( $menu_item->post_excerpt );
|
||||||
@ -221,7 +223,7 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
|
|||||||
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );
|
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );
|
||||||
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
|
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'custom':
|
case 'custom':
|
||||||
$menu_item->db_id = 0;
|
$menu_item->db_id = 0;
|
||||||
$menu_item->object_id = (int) $menu_item->ID;
|
$menu_item->object_id = (int) $menu_item->ID;
|
||||||
@ -235,8 +237,8 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
|
|||||||
$menu_item->title = $menu_item->post_title;
|
$menu_item->title = $menu_item->post_title;
|
||||||
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
|
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
|
||||||
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
||||||
$menu_item->classes = '';
|
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_target', true );
|
||||||
$menu_item->xfn = '';
|
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'post_type':
|
case 'post_type':
|
||||||
@ -273,11 +275,12 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
|
|||||||
$menu_item->url = get_term_link( $menu_item, $menu_item_object );
|
$menu_item->url = get_term_link( $menu_item, $menu_item_object );
|
||||||
$menu_item->target = '';
|
$menu_item->target = '';
|
||||||
$menu_item->attr_title = '';
|
$menu_item->attr_title = '';
|
||||||
$menu_item->description = strip_tags( $menu_item->description );
|
$menu_item->description = '';
|
||||||
$menu_item->classes = '';
|
$menu_item->classes = '';
|
||||||
$menu_item->xfn = '';
|
$menu_item->xfn = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $menu_item;
|
|
||||||
|
return apply_filters( 'wp_setup_nav_menu_item', $menu_item, $menu_item_type, $menu_item_object );
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user