Make classes property for menus an array. Props filosofo. fixes #13551
git-svn-id: http://svn.automattic.com/wordpress/trunk@14944 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1fa281b08c
commit
65c6c9a3bd
|
@ -132,7 +132,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
|
|||
<p class="field-css-classes description description-thin">
|
||||
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
|
||||
<?php _e( 'CSS Classes (optional)' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->classes ); ?>" />
|
||||
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="field-xfn description description-thin">
|
||||
|
|
|
@ -72,7 +72,7 @@ class Walker_Nav_Menu extends Walker {
|
|||
|
||||
$classes = array( 'menu-item', 'menu-item-type-' . $item->type );
|
||||
if ( !empty($item->classes) )
|
||||
$classes = array_merge($classes, explode(' ', $item->classes) );
|
||||
$classes = array_merge( $classes, $item->classes );
|
||||
|
||||
if ( 'custom' != $item->type ) {
|
||||
$classes[] = 'menu-item-object-' . $item->object;
|
||||
|
@ -170,7 +170,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
|
|||
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-description" name="menu-item[' . $possible_object_id . '][menu-item-description]" value="'. esc_attr( $item->description ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( $item->classes ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
|
||||
}
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ function _wp_menu_item_classes_by_context( &$menu_items = array() ) {
|
|||
( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) )
|
||||
)
|
||||
) {
|
||||
$menu_items[$key]->classes = trim( $menu_items[$key]->classes . ' ' . 'current-menu-item' );
|
||||
$menu_items[$key]->classes[] = 'current-menu-item';
|
||||
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
|
||||
$active_parent_object_ids[] = (int) $menu_item->post_parent;
|
||||
$active_object = $menu_item->object;
|
||||
|
@ -348,9 +348,9 @@ function _wp_menu_item_classes_by_context( &$menu_items = array() ) {
|
|||
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
$item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
|
||||
if ( $item_url == $current_url ) {
|
||||
$menu_items[$key]->classes = trim( $menu_item->classes . ' ' . 'current-menu-item' );
|
||||
$menu_items[$key]->classes[] = 'current-menu-item';
|
||||
if ( untrailingslashit($current_url) == home_url() )
|
||||
$menu_items[$key]->classes .= ' menu-item-home';
|
||||
$menu_items[$key]->classes[] = 'menu-item-home';
|
||||
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
|
||||
$active_parent_object_ids[] = (int) $menu_item->post_parent;
|
||||
$active_object = $menu_item->object;
|
||||
|
@ -359,7 +359,7 @@ function _wp_menu_item_classes_by_context( &$menu_items = array() ) {
|
|||
|
||||
// back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
|
||||
if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
|
||||
$menu_items[$key]->classes = trim( $menu_items[$key]->classes . ' ' . 'current_page_parent' );
|
||||
$menu_items[$key]->classes[] = 'current_page_parent';
|
||||
}
|
||||
|
||||
$active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
|
||||
|
@ -374,11 +374,11 @@ function _wp_menu_item_classes_by_context( &$menu_items = array() ) {
|
|||
is_post_type_hierarchical( $queried_object->post_type ) &&
|
||||
in_array( $parent_item->object_id, $queried_object->ancestors )
|
||||
)
|
||||
$menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $queried_object->post_type . '-ancestor current-menu-ancestor' );
|
||||
$menu_items[$key]->classes[] = 'current-' . $queried_object->post_type . '-ancestor current-menu-ancestor';
|
||||
if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
|
||||
$menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-menu-parent' );
|
||||
$menu_items[$key]->classes[] = 'current-menu-parent';
|
||||
if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
|
||||
$menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $active_object . '-parent' );
|
||||
$menu_items[$key]->classes[] = 'current-' . $active_object . '-parent';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,6 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
|
|||
* @return int The menu item's database ID or WP_Error object on failure.
|
||||
*/
|
||||
function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
|
||||
|
||||
$menu_id = (int) $menu_id;
|
||||
$menu_item_db_id = (int) $menu_item_db_id;
|
||||
|
||||
|
@ -370,9 +369,9 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
|
|||
update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id'] );
|
||||
update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
|
||||
update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
|
||||
// @todo sanitize_html_classes()
|
||||
foreach( array( 'menu-item-classes', 'menu-item-xfn') as $arg )
|
||||
$args[$arg] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args[$arg] ) ) );
|
||||
|
||||
$args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
|
||||
$args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
|
||||
update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
|
||||
update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
|
||||
|
||||
|
@ -533,7 +532,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
|||
* - title: The title of this menu item.
|
||||
* - target: The target attribute of the link element for this menu item.
|
||||
* - attr_title: The title attribute of the link element for this menu item.
|
||||
* - classes: The class attribute value for the link element of this menu item.
|
||||
* - classes: The array of class attribute values for the link element of this menu item.
|
||||
* - xfn: The XFN relationship expressed in the link of this menu item.
|
||||
* - description: The description of this menu item.
|
||||
*
|
||||
|
@ -580,7 +579,7 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt );
|
||||
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
|
||||
|
||||
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );
|
||||
$menu_item->classes = (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true );
|
||||
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
|
||||
} else {
|
||||
$menu_item->db_id = 0;
|
||||
|
@ -598,7 +597,7 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
|
||||
$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt );
|
||||
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
|
||||
$menu_item->classes = '';
|
||||
$menu_item->classes = array();
|
||||
$menu_item->xfn = '';
|
||||
}
|
||||
} elseif ( isset( $menu_item->taxonomy ) ) {
|
||||
|
@ -618,7 +617,7 @@ function wp_setup_nav_menu_item( $menu_item ) {
|
|||
$menu_item->target = '';
|
||||
$menu_item->attr_title = '';
|
||||
$menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy );
|
||||
$menu_item->classes = '';
|
||||
$menu_item->classes = array();
|
||||
$menu_item->xfn = '';
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue