]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/nav-menu.php
WordPress 4.7
[autoinstalls/wordpress.git] / wp-includes / nav-menu.php
index ae573c5c3e9a1f8e8eae776864b0266bb9a27b74..30039f420e5d6b280e50b8e4fd389e45d5f2ba77 100644 (file)
@@ -12,8 +12,8 @@
  *
  * @since 3.0.0
  *
- * @param string $menu Menu ID, slug, or name - or the menu object.
- * @return object|false False if $menu param isn't supplied or term does not exist, menu object if successful.
+ * @param int|string|WP_Term $menu Menu ID, slug, or name - or the menu object.
+ * @return WP_Term|false False if $menu param isn't supplied or term does not exist, menu object if successful.
  */
 function wp_get_nav_menu_object( $menu ) {
        $menu_obj = false;
@@ -557,38 +557,6 @@ function wp_get_nav_menus( $args = array() ) {
        return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu',  $args), $args );
 }
 
-/**
- * Sort menu items by the desired key.
- *
- * @since 3.0.0
- * @access private
- *
- * @global string $_menu_item_sort_prop
- *
- * @param object $a The first object to compare
- * @param object $b The second object to compare
- * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.
- */
-function _sort_nav_menu_items( $a, $b ) {
-       global $_menu_item_sort_prop;
-
-       if ( empty( $_menu_item_sort_prop ) )
-               return 0;
-
-       if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )
-               return 0;
-
-       $_a = (int) $a->$_menu_item_sort_prop;
-       $_b = (int) $b->$_menu_item_sort_prop;
-
-       if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )
-               return 0;
-       elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )
-               return $_a < $_b ? -1 : 1;
-       else
-               return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
-}
-
 /**
  * Return if a menu item is valid.
  *
@@ -682,8 +650,9 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
        }
 
        if ( ARRAY_A == $args['output'] ) {
-               $GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
-               usort($items, '_sort_nav_menu_items');
+               $items = wp_list_sort( $items, array(
+                       $args['output_key'] => 'ASC',
+               ) );
                $i = 1;
                foreach ( $items as $k => $item ) {
                        $items[$k]->{$args['output_key']} = $i++;
@@ -747,6 +716,10 @@ function wp_setup_nav_menu_item( $menu_item ) {
                                        $menu_item->_invalid = true;
                                }
 
+                               if ( 'trash' === get_post_status( $menu_item->object_id ) ) {
+                                       $menu_item->_invalid = true;
+                               }
+
                                $menu_item->url = get_permalink( $menu_item->object_id );
 
                                $original_object = get_post( $menu_item->object_id );
@@ -772,7 +745,7 @@ function wp_setup_nav_menu_item( $menu_item ) {
 
                                $menu_item->type_label = __( 'Post Type Archive' );
                                $post_content = wp_trim_words( $menu_item->post_content, 200 );
-                               $post_type_description = '' == $post_content ? $post_type_description : $post_content; 
+                               $post_type_description = '' == $post_content ? $post_type_description : $post_content;
                                $menu_item->url = get_post_type_archive_link( $menu_item->object );
                        } elseif ( 'taxonomy' == $menu_item->type ) {
                                $object = get_taxonomy( $menu_item->object );