X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..fa11948979fd6a4ea5705dc613b239699a459db3:/wp-includes/nav-menu.php diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 7a5da9e2..cf9ac142 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -127,7 +127,8 @@ function get_registered_nav_menus() { */ function get_nav_menu_locations() { - return get_theme_mod( 'nav_menu_locations' ); + $locations = get_theme_mod( 'nav_menu_locations' ); + return ( is_array( $locations ) ) ? $locations : array(); } /** @@ -188,6 +189,14 @@ function wp_delete_nav_menu( $menu ) { $result = wp_delete_term( $menu->term_id, 'nav_menu' ); + // Remove this menu from any locations. + $locations = get_nav_menu_locations(); + foreach ( $locations as $location => $menu_id ) { + if ( $menu_id == $menu->term_id ) + $locations[ $location ] = 0; + } + set_theme_mod( 'nav_menu_locations', $locations ); + if ( $result && !is_wp_error($result) ) do_action( 'wp_delete_nav_menu', $menu->term_id ); @@ -327,13 +336,12 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $original_title = $original_object->post_title; } - if ( empty( $args['menu-item-title'] ) || $args['menu-item-title'] == $original_title ) { + if ( $args['menu-item-title'] == $original_title ) $args['menu-item-title'] = ''; - // hack to get wp to create a post object when too many properties are empty - if ( empty( $args['menu-item-description'] ) ) - $args['menu-item-description'] = ' '; - } + // hack to get wp to create a post object when too many properties are empty + if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] ) + $args['menu-item-description'] = ' '; } // Populate the menu item object @@ -468,8 +476,6 @@ function _is_valid_nav_menu_item( $item ) { * @return mixed $items array of menu items, else false. */ function wp_get_nav_menu_items( $menu, $args = array() ) { - global $_wp_using_ext_object_cache; - $menu = wp_get_nav_menu_object( $menu ); if ( ! $menu ) @@ -496,7 +502,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) { return false; // Get all posts and terms at once to prime the caches - if ( empty( $fetched[$menu->term_id] ) || $_wp_using_ext_object_cache ) { + if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) { $fetched[$menu->term_id] = true; $posts = array(); $terms = array(); @@ -633,6 +639,9 @@ function wp_setup_nav_menu_item( $menu_item ) { $menu_item->object = $object->name; $menu_item->type_label = $object->labels->singular_name; + if ( '' === $menu_item->post_title ) + $menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID ); + $menu_item->title = $menu_item->post_title; $menu_item->url = get_permalink( $menu_item->ID ); $menu_item->target = ''; @@ -674,9 +683,10 @@ function wp_setup_nav_menu_item( $menu_item ) { * * @param int $object_id The ID of the original object. * @param string $object_type The type of object, such as "taxonomy" or "post_type." + * @param string $taxonomy If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to * @return array The array of menu item IDs; empty array if none; */ -function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type' ) { +function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) { $object_id = (int) $object_id; $menu_item_ids = array(); @@ -692,7 +702,8 @@ function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_ ); foreach( (array) $menu_items as $menu_item ) { if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) { - if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) != $object_type ) + if ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) !== $object_type || + get_post_meta( $menu_item->ID, '_menu_item_object', true ) !== $taxonomy ) continue; $menu_item_ids[] = (int) $menu_item->ID; @@ -730,10 +741,10 @@ function _wp_delete_post_menu_item( $object_id = 0 ) { * @param int $object_id The ID of the original object being trashed. * */ -function _wp_delete_tax_menu_item( $object_id = 0 ) { +function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) { $object_id = (int) $object_id; - $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy' ); + $menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy ); foreach( (array) $menu_item_ids as $menu_item_id ) { wp_delete_post( $menu_item_id, true );