WordPress.org

Make WordPress Core

Ticket #16799: 16799.trim-filter.diff

File 16799.trim-filter.diff, 1.7 KB (added by duck_, 7 years ago)

Alternatively, wp_trim_words() on nav_menu_description filter

  • wp-includes/nav-menu.php

     
    618618                        $menu_item->target = empty( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;
    619619
    620620                        $menu_item->attr_title = empty( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title;
     621                        $menu_item->description = empty( $menu_item->description ) ? apply_filters( 'nav_menu_description', $menu_item->post_content ) : $menu_item->description;
    621622
    622                         if ( empty( $menu_item->description ) )
    623                                 $menu_item->description = apply_filters( 'nav_menu_description',  wp_trim_words( $menu_item->post_content, 200 ) );
    624 
    625623                        $menu_item->classes = empty( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes;
    626624                        $menu_item->xfn = empty( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn;
    627625                } else {
     
    669667}
    670668
    671669/**
     670 * Trim a nav menu item description to 200 words.
     671 *
     672 * Hooked into the nav_menu_description filter.
     673 *
     674 * @access private
     675 * @since 3.3.0
     676 *
     677 * @param string $description The full length description.
     678 * @return string Trimmed description.
     679 */
     680function _wp_trim_nav_menu_description( $description ) {
     681        return ! empty( $description ) ? wp_trim_words( $description, 200 ) : '';
     682}
     683add_filter( 'nav_menu_description', '_wp_trim_nav_menu_description' );
     684
     685/**
    672686 * Get the menu items associated with a particular object.
    673687 *
    674688 * @since 3.0.0