Make WordPress Core

Changeset 23565


Ignore:
Timestamp:
03/01/2013 05:06:35 PM (11 years ago)
Author:
SergeyBiryukov
Message:

Add a filter for attributes on menu item links. props simonwheatley, DrewAPicture, SergeyBiryukov, nacin. fixes #16738.

File:
1 edited

Legend:

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

    r23309 r23565  
    8181        $output .= $indent . '<li' . $id . $value . $class_names .'>';
    8282
    83         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
    84         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
    85         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
    86         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
     83        $atts = array();
     84        $atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
     85        $atts['target'] = ! empty( $item->target )     ? $item->target     : '';
     86        $atts['rel']    = ! empty( $item->xfn )        ? $item->xfn        : '';
     87        $atts['href']   = ! empty( $item->url )        ? $item->url        : '';
     88
     89        $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
     90
     91        $attributes = '';
     92        foreach ( $atts as $attr => $value ) {
     93            if ( ! empty( $value ) ) {
     94                $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
     95                $attributes .= ' ' . $attr . '="' . $value . '"';
     96            }
     97        }
    8798
    8899        $item_output = $args->before;
Note: See TracChangeset for help on using the changeset viewer.