}
/**
- * Filter the nav_menu term retrieved for wp_get_nav_menu_object().
+ * Filters the nav_menu term retrieved for wp_get_nav_menu_object().
*
* @since 4.3.0
*
}
/**
- * Register navigation menus for a theme.
+ * Registers navigation menu locations for a theme.
*
* @since 3.0.0
*
}
/**
- * Unregisters a navigation menu for a theme.
+ * Unregisters a navigation menu location for a theme.
*
* @global array $_wp_registered_nav_menus
*
}
/**
- * Register a navigation menu for a theme.
+ * Registers a navigation menu location for a theme.
*
* @since 3.0.0
*
register_nav_menus( array( $location => $description ) );
}
/**
- * Returns an array of all registered navigation menus in a theme
+ * Retrieves all registered navigation menu locations in a theme.
*
* @since 3.0.0
*
* @global array $_wp_registered_nav_menus
*
- * @return array
+ * @return array Registered navigation menu locations. If none are registered, an empty array.
*/
function get_registered_nav_menus() {
global $_wp_registered_nav_menus;
}
/**
- * Returns an array with the registered navigation menu locations and the menu assigned to it
+ * Retrieves all registered navigation menu locations and the menus assigned to them.
*
* @since 3.0.0
- * @return array
+ *
+ * @return array Registered navigation menu locations and the menus assigned them.
+ * If none are registered, an empty array.
*/
function get_nav_menu_locations() {
}
/**
- * Whether a registered nav menu location has a menu assigned to it.
+ * Determines whether a registered nav menu location has a menu assigned to it.
*
* @since 3.0.0
*
}
/**
- * Filter whether a nav menu is assigned to the specified location.
+ * Filters whether a nav menu is assigned to the specified location.
*
* @since 4.3.0
*
}
/**
- * Determine whether the given ID is a nav menu item.
+ * Determines whether the given ID is a nav menu item.
*
* @since 3.0.0
*
}
/**
- * Create a Navigation Menu.
+ * Creates a navigation menu.
+ *
+ * Note that `$menu_name` is expected to be pre-slashed.
*
* @since 3.0.0
*
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
*/
function wp_create_nav_menu( $menu_name ) {
+ // expected_slashed ($menu_name)
return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
}
/**
* Save the properties of a menu or create a new menu with those properties.
*
+ * Note that `$menu_data` is expected to be pre-slashed.
+ *
* @since 3.0.0
*
* @param int $menu_id The ID of the menu or "0" to create a new menu.
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
*/
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
+ // expected_slashed ($menu_data)
$menu_id = (int) $menu_id;
$_menu = wp_get_nav_menu_object( $menu_id );
/**
* Save the properties of a menu item or create a new one.
*
+ * The menu-item-title, menu-item-description, and menu-item-attr-title are expected
+ * to be pre-slashed since they are passed directly into `wp_insert_post()`.
+ *
* @since 3.0.0
*
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
$original_title = $original_object->post_title;
} elseif ( 'post_type_archive' == $args['menu-item-type'] ) {
$original_object = get_post_type_object( $args['menu-item-object'] );
- $original_title = $original_object->labels->archives;
+ if ( $original_object ) {
+ $original_title = $original_object->labels->archives;
+ }
}
if ( $args['menu-item-title'] == $original_title )
* @since 4.1.0 Default value of the 'orderby' argument was changed from 'none'
* to 'name'.
*
- * @param array $args Optional. Array of arguments passed on to {@see get_terms()}.
+ * @param array $args Optional. Array of arguments passed on to get_terms().
* Default empty array.
* @return array Menu objects.
*/
$args = wp_parse_args( $args, $defaults );
/**
- * Filter the navigation menu objects being returned.
+ * Filters the navigation menu objects being returned.
*
* @since 3.0.0
*
* @staticvar array $fetched
*
* @param string $menu Menu name, ID, or slug.
- * @param array $args Optional. Arguments to pass to {@see get_posts()}.
+ * @param array $args Optional. Arguments to pass to get_posts().
* @return false|array $items Array of menu items, otherwise false.
*/
function wp_get_nav_menu_items( $menu, $args = array() ) {
$items = array_map( 'wp_setup_nav_menu_item', $items );
- if ( ! is_admin() ) { // Remove invalid items only in frontend
+ if ( ! is_admin() ) { // Remove invalid items only in front end
$items = array_filter( $items, '_is_valid_nav_menu_item' );
}
}
/**
- * Filter the navigation menu items being returned.
+ * Filters the navigation menu items being returned.
*
* @since 3.0.0
*
$menu_item->url = get_permalink( $menu_item->object_id );
$original_object = get_post( $menu_item->object_id );
- $original_title = $original_object->post_title;
+ /** This filter is documented in wp-includes/post-template.php */
+ $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
if ( '' === $original_title ) {
/* translators: %d: ID of a post */
$object = get_post_type_object( $menu_item->object );
if ( $object ) {
$menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title;
+ $post_type_description = $object->description;
} else {
$menu_item->_invalid = true;
+ $post_type_description = '';
}
$menu_item->type_label = __( 'Post Type Archive' );
- $menu_item->description = '';
+ $post_content = wp_trim_words( $menu_item->post_content, 200 );
+ $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 );
$menu_item->target = ! isset( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;
/**
- * Filter a navigation menu item's title attribute.
+ * Filters a navigation menu item's title attribute.
*
* @since 3.0.0
*
if ( ! isset( $menu_item->description ) ) {
/**
- * Filter a navigation menu item's description.
+ * Filters a navigation menu item's description.
*
* @since 3.0.0
*
}
/**
- * Filter a navigation menu item object.
+ * Filters a navigation menu item object.
*
* @since 3.0.0
*
}
/**
- * Callback for handling a menu item when its original object is deleted.
+ * Serves as a callback for handling a menu item when its original object is deleted.
*
* @since 3.0.0
* @access private
*
- * @param int $object_id The ID of the original object being trashed.
- *
+ * @param int $object_id Optional. The ID of the original object being trashed. Default 0.
+ * @param int $tt_id Term taxonomy ID. Unused.
+ * @param string $taxonomy Taxonomy slug.
*/
function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
$object_id = (int) $object_id;