WordPress.org

Make WordPress Core

Changeset 14944


Ignore:
Timestamp:
05/26/2010 03:41:21 PM (12 years ago)
Author:
ryan
Message:

Make classes property for menus an array. Props filosofo. fixes #13551

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/nav-menu.php

    r14943 r14944  
    133133                    <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
    134134                        <?php _e( 'CSS Classes (optional)' ); ?><br />
    135                         <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 ); ?>" />
     135                        <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 ) ); ?>" />
    136136                    </label>
    137137                </p>
  • trunk/wp-includes/nav-menu-template.php

    r14942 r14944  
    7373        $classes = array( 'menu-item', 'menu-item-type-' . $item->type );
    7474        if ( !empty($item->classes) )
    75             $classes = array_merge($classes, explode(' ', $item->classes) );
     75            $classes = array_merge( $classes, $item->classes );
    7676
    7777        if ( 'custom' != $item->type ) {
     
    171171        $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 ) .'" />';
    172172        $output .= '<input type="hidden" class="menu-item-description" name="menu-item[' . $possible_object_id . '][menu-item-description]" value="'. esc_attr( $item->description ) .'" />';
    173         $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( $item->classes ) .'" />';
     173        $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
    174174        $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
    175175    }
     
    339339            )
    340340        ) {
    341             $menu_items[$key]->classes = trim( $menu_items[$key]->classes . ' ' . 'current-menu-item' );
     341            $menu_items[$key]->classes[] = 'current-menu-item';
    342342            $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
    343343            $active_parent_object_ids[] = (int) $menu_item->post_parent;
     
    349349            $item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
    350350            if ( $item_url == $current_url ) {
    351                 $menu_items[$key]->classes = trim( $menu_item->classes . ' ' . 'current-menu-item' );
     351                $menu_items[$key]->classes[] = 'current-menu-item';
    352352                if ( untrailingslashit($current_url) == home_url() )
    353                     $menu_items[$key]->classes .= ' menu-item-home';
     353                    $menu_items[$key]->classes[] = 'menu-item-home';
    354354                $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
    355355                $active_parent_object_ids[] = (int) $menu_item->post_parent;
     
    360360        // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
    361361        if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
    362             $menu_items[$key]->classes = trim( $menu_items[$key]->classes . ' ' . 'current_page_parent' );
     362            $menu_items[$key]->classes[] = 'current_page_parent';
    363363    }
    364364
     
    375375            in_array( $parent_item->object_id, $queried_object->ancestors )
    376376        )
    377             $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $queried_object->post_type . '-ancestor current-menu-ancestor' );
     377            $menu_items[$key]->classes[] = 'current-' . $queried_object->post_type . '-ancestor current-menu-ancestor';
    378378        if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
    379             $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-menu-parent' );
     379            $menu_items[$key]->classes[] = 'current-menu-parent';
    380380        if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
    381             $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $active_object . '-parent' );
     381            $menu_items[$key]->classes[] = 'current-' . $active_object . '-parent';
    382382    }
    383383}
  • trunk/wp-includes/nav-menu.php

    r14937 r14944  
    254254 */
    255255function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
    256 
    257256    $menu_id = (int) $menu_id;
    258257    $menu_item_db_id = (int) $menu_item_db_id;
     
    371370        update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
    372371        update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
    373         // @todo sanitize_html_classes()
    374         foreach( array( 'menu-item-classes', 'menu-item-xfn') as $arg )
    375             $args[$arg] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args[$arg] ) ) );
     372       
     373        $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
     374        $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
    376375        update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
    377376        update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
     
    534533 * - target:        The target attribute of the link element for this menu item.
    535534 * - attr_title:    The title attribute of the link element for this menu item.
    536  * - classes:       The class attribute value for the link element of this menu item.
     535 * - classes:       The array of class attribute values for the link element of this menu item.
    537536 * - xfn:       The XFN relationship expressed in the link of this menu item.
    538537 * - description:   The description of this menu item.
     
    581580            $menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
    582581
    583             $menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );
     582            $menu_item->classes = (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true );
    584583            $menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
    585584        } else {
     
    599598            $menu_item->attr_title = apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt );
    600599            $menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
    601             $menu_item->classes = '';
     600            $menu_item->classes = array();
    602601            $menu_item->xfn = '';
    603602        }
     
    619618        $menu_item->attr_title = '';
    620619        $menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy );
    621         $menu_item->classes = '';
     620        $menu_item->classes = array();
    622621        $menu_item->xfn = '';
    623622
Note: See TracChangeset for help on using the changeset viewer.