WordPress.org

Make WordPress Core

Ticket #33955: 33955.patch

File 33955.patch, 27.9 KB (added by sebastian.pisula, 6 years ago)
  • wp-includes/nav-menu.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
    <+><?php\n/**\n * Navigation Menu functions\n *\n * @package WordPress\n * @subpackage Nav_Menus\n * @since 3.0.0\n */\n\n/**\n * Returns a navigation menu object.\n *\n * @since 3.0.0\n *\n * @uses get_term\n * @uses get_term_by\n *\n * @param string $menu Menu id, slug or name\n * @return mixed false if $menu param isn't supplied or term does not exist, menu object if successful.\n */\nfunction wp_get_nav_menu_object( $menu ) {\n\tif ( ! $menu )\n\t\treturn false;\n\n\t$menu_obj = get_term( $menu, 'nav_menu' );\n\n\tif ( ! $menu_obj )\n\t\t$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );\n\n\tif ( ! $menu_obj )\n\t\t$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );\n\n\tif ( ! $menu_obj )\n\t\t$menu_obj = false;\n\n\treturn $menu_obj;\n}\n\n/**\n * Check if the given ID is a navigation menu.\n *\n * Returns true if it is; false otherwise.\n *\n * @since 3.0.0\n *\n * @param int|string $menu The menu to check (id, slug, or name)\n * @return bool Whether the menu exists.\n */\nfunction is_nav_menu( $menu ) {\n\tif ( ! $menu )\n\t\treturn false;\n\n\t$menu_obj = wp_get_nav_menu_object( $menu );\n\n\tif (\n\t\t$menu_obj &&\n\t\t! is_wp_error( $menu_obj ) &&\n\t\t! empty( $menu_obj->taxonomy ) &&\n\t\t'nav_menu' == $menu_obj->taxonomy\n\t)\n\t\treturn true;\n\n\treturn false;\n}\n\n/**\n * Register navigation menus for a theme.\n *\n * @since 3.0.0\n *\n * @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text.\n */\nfunction register_nav_menus( $locations = array() ) {\n\tglobal $_wp_registered_nav_menus;\n\n\tadd_theme_support( 'menus' );\n\n\t$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );\n}\n\n/**\n * Unregisters a navigation menu for a theme.\n *\n * @param array $location the menu location identifier\n *\n * @return bool True on success, false on failure.\n */\nfunction unregister_nav_menu( $location ) {\n\tglobal $_wp_registered_nav_menus;\n\n\tif ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) {\n\t\tunset( $_wp_registered_nav_menus[$location] );\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Register a navigation menu for a theme.\n *\n * @since 3.0.0\n *\n * @param string $location Menu location identifier, like a slug.\n * @param string $description Menu location descriptive text.\n */\nfunction register_nav_menu( $location, $description ) {\n\tregister_nav_menus( array( $location => $description ) );\n}\n/**\n * Returns an array of all registered navigation menus in a theme\n *\n * @since 3.0.0\n * @return array\n */\nfunction get_registered_nav_menus() {\n\tglobal $_wp_registered_nav_menus;\n\tif ( isset( $_wp_registered_nav_menus ) )\n\t\treturn $_wp_registered_nav_menus;\n\treturn array();\n}\n\n/**\n * Returns an array with the registered navigation menu locations and the menu assigned to it\n *\n * @since 3.0.0\n * @return array\n */\n\nfunction get_nav_menu_locations() {\n\t$locations = get_theme_mod( 'nav_menu_locations' );\n\treturn ( is_array( $locations ) ) ? $locations : array();\n}\n\n/**\n * Whether a registered nav menu location has a menu assigned to it.\n *\n * @since 3.0.0\n * @param string $location Menu location identifier.\n * @return bool Whether location has a menu.\n */\nfunction has_nav_menu( $location ) {\n\t$locations = get_nav_menu_locations();\n\treturn ( ! empty( $locations[ $location ] ) );\n}\n\n/**\n * Determine whether the given ID is a nav menu item.\n *\n * @since 3.0.0\n *\n * @param int $menu_item_id The ID of the potential nav menu item.\n * @return bool Whether the given ID is that of a nav menu item.\n */\nfunction is_nav_menu_item( $menu_item_id = 0 ) {\n\treturn ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) );\n}\n\n/**\n * Create a Navigation Menu.\n *\n * @since 3.0.0\n *\n * @param string $menu_name Menu Name\n * @return mixed Menu object on success|WP_Error on failure\n */\nfunction wp_create_nav_menu( $menu_name ) {\n\treturn wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );\n}\n\n/**\n * Delete a Navigation Menu.\n *\n * @since 3.0.0\n *\n * @param string $menu name|id|slug\n * @return mixed Menu object on success|WP_Error on failure\n */\nfunction wp_delete_nav_menu( $menu ) {\n\t$menu = wp_get_nav_menu_object( $menu );\n\tif ( ! $menu )\n\t\treturn false;\n\n\t$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );\n\tif ( ! empty( $menu_objects ) ) {\n\t\tforeach ( $menu_objects as $item ) {\n\t\t\twp_delete_post( $item );\n\t\t}\n\t}\n\n\t$result = wp_delete_term( $menu->term_id, 'nav_menu' );\n\n\t// Remove this menu from any locations.\n\t$locations = get_nav_menu_locations();\n\tforeach ( $locations as $location => $menu_id ) {\n\t\tif ( $menu_id == $menu->term_id )\n\t\t\t$locations[ $location ] = 0;\n\t}\n\tset_theme_mod( 'nav_menu_locations', $locations );\n\n\tif ( $result && !is_wp_error($result) )\n\t\tdo_action( 'wp_delete_nav_menu', $menu->term_id );\n\n\treturn $result;\n}\n\n/**\n * Save the properties of a menu or create a new menu with those properties.\n *\n * @since 3.0.0\n *\n * @param int $menu_id The ID of the menu or \"0\" to create a new menu.\n * @param array $menu_data The array of menu data.\n * @return int|error object The menu's ID or WP_Error object.\n */\nfunction wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {\n\t$menu_id = (int) $menu_id;\n\n\t$_menu = wp_get_nav_menu_object( $menu_id );\n\n\t$args = array(\n\t\t'description' => ( isset( $menu_data['description'] ) ? $menu_data['description']  : '' ),\n\t\t'name'        => ( isset( $menu_data['menu-name']   ) ? $menu_data['menu-name']    : '' ),\n\t\t'parent'      => ( isset( $menu_data['parent']      ) ? (int) $menu_data['parent'] : 0  ),\n\t\t'slug'        => null,\n\t);\n\n\t// double-check that we're not going to have one menu take the name of another\n\t$_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );\n\tif (\n\t\t$_possible_existing &&\n\t\t! is_wp_error( $_possible_existing ) &&\n\t\tisset( $_possible_existing->term_id ) &&\n\t\t$_possible_existing->term_id != $menu_id\n\t)\n\t\treturn new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) );\n\n\t// menu doesn't already exist, so create a new menu\n\tif ( ! $_menu || is_wp_error( $_menu ) ) {\n\t\t$menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );\n\n\t\tif ( $menu_exists )\n\t\t\treturn new WP_Error( 'menu_exists', sprintf( __('The menu name <strong>%s</strong> conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) );\n\n\t\t$_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args );\n\n\t\tif ( is_wp_error( $_menu ) )\n\t\t\treturn $_menu;\n\n\t\tdo_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data );\n\n\t\treturn (int) $_menu['term_id'];\n\t}\n\n\tif ( ! $_menu || ! isset( $_menu->term_id ) )\n\t\treturn 0;\n\n\t$menu_id = (int) $_menu->term_id;\n\n\t$update_response = wp_update_term( $menu_id, 'nav_menu', $args );\n\n\tif ( is_wp_error( $update_response ) )\n\t\treturn $update_response;\n\n\tdo_action( 'wp_update_nav_menu', $menu_id, $menu_data );\n\treturn $menu_id;\n}\n\n/**\n * Save the properties of a menu item or create a new one.\n *\n * @since 3.0.0\n *\n * @param int $menu_id The ID of the menu. Required. If \"0\", makes the menu item a draft orphan.\n * @param int $menu_item_db_id The ID of the menu item. If \"0\", creates a new menu item.\n * @param array $menu_item_data The menu item's data.\n * @return int The menu item's database ID or WP_Error object on failure.\n */\nfunction wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {\n\t$menu_id = (int) $menu_id;\n\t$menu_item_db_id = (int) $menu_item_db_id;\n\n\t// make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects\n\tif ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) )\n\t\treturn new WP_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.'));\n\n\t$menu = wp_get_nav_menu_object( $menu_id );\n\n\tif ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) )\n\t\treturn $menu;\n\n\t$defaults = array(\n\t\t'menu-item-db-id' => $menu_item_db_id,\n\t\t'menu-item-object-id' => 0,\n\t\t'menu-item-object' => '',\n\t\t'menu-item-parent-id' => 0,\n\t\t'menu-item-position' => 0,\n\t\t'menu-item-type' => 'custom',\n\t\t'menu-item-title' => '',\n\t\t'menu-item-url' => '',\n\t\t'menu-item-description' => '',\n\t\t'menu-item-attr-title' => '',\n\t\t'menu-item-target' => '',\n\t\t'menu-item-classes' => '',\n\t\t'menu-item-xfn' => '',\n\t\t'menu-item-status' => '',\n\t);\n\n\t$args = wp_parse_args( $menu_item_data, $defaults );\n\n\tif ( 0 == $menu_id ) {\n\t\t$args['menu-item-position'] = 1;\n\t} elseif ( 0 == (int) $args['menu-item-position'] ) {\n\t\t$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );\n\t\t$last_item = array_pop( $menu_items );\n\t\t$args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );\n\t}\n\n\t$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;\n\n\tif ( 'custom' != $args['menu-item-type'] ) {\n\t\t/* if non-custom menu item, then:\n\t\t\t* use original object's URL\n\t\t\t* blank default title to sync with original object's\n\t\t*/\n\n\t\t$args['menu-item-url'] = '';\n\n\t\t$original_title = '';\n\t\tif ( 'taxonomy' == $args['menu-item-type'] ) {\n\t\t\t$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );\n\t\t\t$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );\n\t\t} elseif ( 'post_type' == $args['menu-item-type'] ) {\n\n\t\t\t$original_object = get_post( $args['menu-item-object-id'] );\n\t\t\t$original_parent = (int) $original_object->post_parent;\n\t\t\t$original_title = $original_object->post_title;\n\t\t}\n\n\t\tif ( $args['menu-item-title'] == $original_title )\n\t\t\t$args['menu-item-title'] = '';\n\n\t\t// hack to get wp to create a post object when too many properties are empty\n\t\tif ( '' ==  $args['menu-item-title'] && '' == $args['menu-item-description'] )\n\t\t\t$args['menu-item-description'] = ' ';\n\t}\n\n\t// Populate the menu item object\n\t$post = array(\n\t\t'menu_order' => $args['menu-item-position'],\n\t\t'ping_status' => 0,\n\t\t'post_content' => $args['menu-item-description'],\n\t\t'post_excerpt' => $args['menu-item-attr-title'],\n\t\t'post_parent' => $original_parent,\n\t\t'post_title' => $args['menu-item-title'],\n\t\t'post_type' => 'nav_menu_item',\n\t);\n\n\t$update = 0 != $menu_item_db_id;\n\n\t// Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()\n\tif ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) )\n\t\t$post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );\n\n\t// New menu item. Default is draft status\n\tif ( ! $update ) {\n\t\t$post['ID'] = 0;\n\t\t$post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';\n\t\t$menu_item_db_id = wp_insert_post( $post );\n\t\tif ( ! $menu_item_db_id\t|| is_wp_error( $menu_item_db_id ) )\n\t\t\treturn $menu_item_db_id;\n\t}\n\n\tif ( 'custom' == $args['menu-item-type'] ) {\n\t\t$args['menu-item-object-id'] = $menu_item_db_id;\n\t\t$args['menu-item-object'] = 'custom';\n\t}\n\n\t$menu_item_db_id = (int) $menu_item_db_id;\n\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );\n\n\t$args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );\n\t$args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );\n\tupdate_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) );\n\n\tif ( 0 == $menu_id )\n\t\tupdate_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );\n\telseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) )\n\t\tdelete_post_meta( $menu_item_db_id, '_menu_item_orphaned' );\n\n\t// Update existing menu item. Default is publish status\n\tif ( $update ) {\n\t\t$post['ID'] = $menu_item_db_id;\n\t\t$post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish';\n\t\twp_update_post( $post );\n\t}\n\n\tdo_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );\n\n\treturn $menu_item_db_id;\n}\n\n/**\n * Returns all navigation menu objects.\n *\n * @since 3.0.0\n *\n * @param array $args Array of arguments passed on to get_terms().\n * @return array menu objects\n */\nfunction wp_get_nav_menus( $args = array() ) {\n\t$defaults = array( 'hide_empty' => false, 'orderby' => 'none' );\n\t$args = wp_parse_args( $args, $defaults );\n\treturn apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu',  $args), $args );\n}\n\n/**\n * Sort menu items by the desired key.\n *\n * @since 3.0.0\n * @access private\n *\n * @param object $a The first object to compare\n * @param object $b The second object to compare\n * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.\n */\nfunction _sort_nav_menu_items( $a, $b ) {\n\tglobal $_menu_item_sort_prop;\n\n\tif ( empty( $_menu_item_sort_prop ) )\n\t\treturn 0;\n\n\tif ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )\n\t\treturn 0;\n\n\t$_a = (int) $a->$_menu_item_sort_prop;\n\t$_b = (int) $b->$_menu_item_sort_prop;\n\n\tif ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )\n\t\treturn 0;\n\telseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )\n\t\treturn $_a < $_b ? -1 : 1;\n\telse\n\t\treturn strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );\n}\n\n/**\n * Returns if a menu item is valid. Bug #13958\n *\n * @since 3.2.0\n * @access private\n *\n * @param object $menu_item The menu item to check\n * @return bool false if invalid, else true.\n */\nfunction _is_valid_nav_menu_item( $item ) {\n\tif ( ! empty( $item->_invalid ) )\n\t\treturn false;\n\n\treturn true;\n}\n\n/**\n * Returns all menu items of a navigation menu.\n *\n * @since 3.0.0\n *\n * @param string $menu menu name, id, or slug\n * @param string $args\n * @return mixed $items array of menu items, else false.\n */\nfunction wp_get_nav_menu_items( $menu, $args = array() ) {\n\t$menu = wp_get_nav_menu_object( $menu );\n\n\tif ( ! $menu )\n\t\treturn false;\n\n\tstatic $fetched = array();\n\n\t$items = get_objects_in_term( $menu->term_id, 'nav_menu' );\n\n\tif ( empty( $items ) )\n\t\treturn $items;\n\n\t$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',\n\t\t'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );\n\t$args = wp_parse_args( $args, $defaults );\n\tif ( count( $items ) > 1 )\n\t\t$args['include'] = implode( ',', $items );\n\telse\n\t\t$args['include'] = $items[0];\n\n\t$items = get_posts( $args );\n\n\tif ( is_wp_error( $items ) || ! is_array( $items ) )\n\t\treturn false;\n\n\t// Get all posts and terms at once to prime the caches\n\tif ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) {\n\t\t$fetched[$menu->term_id] = true;\n\t\t$posts = array();\n\t\t$terms = array();\n\t\tforeach ( $items as $item ) {\n\t\t\t$object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );\n\t\t\t$object    = get_post_meta( $item->ID, '_menu_item_object',    true );\n\t\t\t$type      = get_post_meta( $item->ID, '_menu_item_type',      true );\n\n\t\t\tif ( 'post_type' == $type )\n\t\t\t\t$posts[$object][] = $object_id;\n\t\t\telseif ( 'taxonomy' == $type)\n\t\t\t\t$terms[$object][] = $object_id;\n\t\t}\n\n\t\tif ( ! empty( $posts ) ) {\n\t\t\tforeach ( array_keys($posts) as $post_type ) {\n\t\t\t\tget_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) );\n\t\t\t}\n\t\t}\n\t\tunset($posts);\n\n\t\tif ( ! empty( $terms ) ) {\n\t\t\tforeach ( array_keys($terms) as $taxonomy ) {\n\t\t\t\tget_terms($taxonomy, array('include' => $terms[$taxonomy]) );\n\t\t\t}\n\t\t}\n\t\tunset($terms);\n\t}\n\n\t$items = array_map( 'wp_setup_nav_menu_item', $items );\n\n\tif ( ! is_admin() ) // Remove invalid items only in frontend\n\t\t$items = array_filter( $items, '_is_valid_nav_menu_item' );\n\n\tif ( ARRAY_A == $args['output'] ) {\n\t\t$GLOBALS['_menu_item_sort_prop'] = $args['output_key'];\n\t\tusort($items, '_sort_nav_menu_items');\n\t\t$i = 1;\n\t\tforeach( $items as $k => $item ) {\n\t\t\t$items[$k]->$args['output_key'] = $i++;\n\t\t}\n\t}\n\n\treturn apply_filters( 'wp_get_nav_menu_items',  $items, $menu, $args );\n}\n\n/**\n * Decorates a menu item object with the shared navigation menu item properties.\n *\n * Properties:\n * - db_id: \t\tThe DB ID of this item as a nav_menu_item object, if it exists (0 if it doesn't exist).\n * - object_id:\t\tThe DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.\n * - type:\t\tThe family of objects originally represented, such as \"post_type\" or \"taxonomy.\"\n * - object:\t\tThe type of object originally represented, such as \"category,\" \"post\", or \"attachment.\"\n * - type_label:\tThe singular label used to describe this type of menu item.\n * - post_parent:\tThe DB ID of the original object's parent object, if any (0 otherwise).\n * - menu_item_parent: \tThe DB ID of the nav_menu_item that is this item's menu parent, if any. 0 otherwise.\n * - url:\t\tThe URL to which this menu item points.\n * - title:\t\tThe title of this menu item.\n * - target: \t\tThe target attribute of the link element for this menu item.\n * - attr_title:\tThe title attribute of the link element for this menu item.\n * - classes:\t\tThe array of class attribute values for the link element of this menu item.\n * - xfn:\t\tThe XFN relationship expressed in the link of this menu item.\n * - description:\tThe description of this menu item.\n *\n * @since 3.0.0\n *\n * @param object $menu_item The menu item to modify.\n * @return object $menu_item The menu item with standard menu item properties.\n */\nfunction wp_setup_nav_menu_item( $menu_item ) {\n\tif ( isset( $menu_item->post_type ) ) {\n\t\tif ( 'nav_menu_item' == $menu_item->post_type ) {\n\t\t\t$menu_item->db_id = (int) $menu_item->ID;\n\t\t\t$menu_item->menu_item_parent = empty( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent;\n\t\t\t$menu_item->object_id = empty( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id;\n\t\t\t$menu_item->object = empty( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object;\n\t\t\t$menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;\n\n\t\t\tif ( 'post_type' == $menu_item->type ) {\n\t\t\t\t$object = get_post_type_object( $menu_item->object );\n\t\t\t\tif ( $object ) {\n\t\t\t\t\t$menu_item->type_label = $object->labels->singular_name;\n\t\t\t\t} else {\n\t\t\t\t\t$menu_item->type_label = $menu_item->object;\n\t\t\t\t\t$menu_item->_invalid = true;\n\t\t\t\t}\n\n\t\t\t\t$menu_item->url = get_permalink( $menu_item->object_id );\n\n\t\t\t\t$original_object = get_post( $menu_item->object_id );\n\t\t\t\t$original_title = $original_object->post_title;\n\t\t\t\t$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;\n\n\t\t\t} elseif ( 'taxonomy' == $menu_item->type ) {\n\t\t\t\t$object = get_taxonomy( $menu_item->object );\n\t\t\t\tif ( $object ) {\n\t\t\t\t\t$menu_item->type_label = $object->labels->singular_name;\n\t\t\t\t} else {\n\t\t\t\t\t$menu_item->type_label = $menu_item->object;\n\t\t\t\t\t$menu_item->_invalid = true;\n\t\t\t\t}\n\n\t\t\t\t$term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object );\n\t\t\t\t$menu_item->url = !is_wp_error( $term_url ) ? $term_url : '';\n\n\t\t\t\t$original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' );\n\t\t\t\tif ( is_wp_error( $original_title ) )\n\t\t\t\t\t$original_title = false;\n\t\t\t\t$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;\n\n\t\t\t} else {\n\t\t\t\t$menu_item->type_label = __('Custom');\n\t\t\t\t$menu_item->title = $menu_item->post_title;\n\t\t\t\t$menu_item->url = empty( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;\n\t\t\t}\n\n\t\t\t$menu_item->target = empty( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;\n\n\t\t\t$menu_item->attr_title = empty( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title;\n\n\t\t\tif ( empty( $menu_item->description ) )\n\t\t\t\t$menu_item->description = apply_filters( 'nav_menu_description',  wp_trim_words( $menu_item->post_content, 200 ) );\n\n\t\t\t$menu_item->classes = empty( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes;\n\t\t\t$menu_item->xfn = empty( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn;\n\t\t} else {\n\t\t\t$menu_item->db_id = 0;\n\t\t\t$menu_item->menu_item_parent = 0;\n\t\t\t$menu_item->object_id = (int) $menu_item->ID;\n\t\t\t$menu_item->type = 'post_type';\n\n\t\t\t$object = get_post_type_object( $menu_item->post_type );\n\t\t\t$menu_item->object = $object->name;\n\t\t\t$menu_item->type_label = $object->labels->singular_name;\n\n\t\t\tif ( '' === $menu_item->post_title )\n\t\t\t\t$menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID );\n\n\t\t\t$menu_item->title = $menu_item->post_title;\n\t\t\t$menu_item->url = get_permalink( $menu_item->ID );\n\t\t\t$menu_item->target = '';\n\n\t\t\t$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', '' );\n\t\t\t$menu_item->description = apply_filters( 'nav_menu_description', '' );\n\t\t\t$menu_item->classes = array();\n\t\t\t$menu_item->xfn = '';\n\t\t}\n\t} elseif ( isset( $menu_item->taxonomy ) ) {\n\t\t$menu_item->ID = $menu_item->term_id;\n\t\t$menu_item->db_id = 0;\n\t\t$menu_item->menu_item_parent = 0;\n\t\t$menu_item->object_id = (int) $menu_item->term_id;\n\t\t$menu_item->post_parent = (int) $menu_item->parent;\n\t\t$menu_item->type = 'taxonomy';\n\n\t\t$object = get_taxonomy( $menu_item->taxonomy );\n\t\t$menu_item->object = $object->name;\n\t\t$menu_item->type_label = $object->labels->singular_name;\n\n\t\t$menu_item->title = $menu_item->name;\n\t\t$menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy );\n\t\t$menu_item->target = '';\n\t\t$menu_item->attr_title = '';\n\t\t$menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy );\n\t\t$menu_item->classes = array();\n\t\t$menu_item->xfn = '';\n\n\t}\n\n\treturn apply_filters( 'wp_setup_nav_menu_item', $menu_item );\n}\n\n/**\n * Get the menu items associated with a particular object.\n *\n * @since 3.0.0\n *\n * @param int $object_id The ID of the original object.\n * @param string $object_type The type of object, such as \"taxonomy\" or \"post_type.\"\n * @param string $taxonomy If $object_type is \"taxonomy\", $taxonomy is the name of the tax that $object_id belongs to\n * @return array The array of menu item IDs; empty array if none;\n */\nfunction wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) {\n\t$object_id = (int) $object_id;\n\t$menu_item_ids = array();\n\n\t$query = new WP_Query;\n\t$menu_items = $query->query(\n\t\tarray(\n\t\t\t'meta_key' => '_menu_item_object_id',\n\t\t\t'meta_value' => $object_id,\n\t\t\t'post_status' => 'any',\n\t\t\t'post_type' => 'nav_menu_item',\n\t\t\t'posts_per_page' => -1,\n\t\t)\n\t);\n\tforeach( (array) $menu_items as $menu_item ) {\n\t\tif ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {\n\t\t\tif ( get_post_meta( $menu_item->ID, '_menu_item_type', true ) !== $object_type ||\n\t\t\t\tget_post_meta( $menu_item->ID, '_menu_item_object', true ) !== $taxonomy )\n\t\t\t\tcontinue;\n\n\t\t\t$menu_item_ids[] = (int) $menu_item->ID;\n\t\t}\n\t}\n\n\treturn array_unique( $menu_item_ids );\n}\n\n/**\n * Callback for handling a menu item when its original object is deleted.\n *\n * @since 3.0.0\n * @access private\n *\n * @param int $object_id The ID of the original object being trashed.\n *\n */\nfunction _wp_delete_post_menu_item( $object_id = 0 ) {\n\t$object_id = (int) $object_id;\n\n\t$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' );\n\n\tforeach( (array) $menu_item_ids as $menu_item_id ) {\n\t\twp_delete_post( $menu_item_id, true );\n\t}\n}\n\n/**\n * Callback for handling a menu item when its original object is deleted.\n *\n * @since 3.0.0\n * @access private\n *\n * @param int $object_id The ID of the original object being trashed.\n *\n */\nfunction _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {\n\t$object_id = (int) $object_id;\n\n\t$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );\n\n\tforeach( (array) $menu_item_ids as $menu_item_id ) {\n\t\twp_delete_post( $menu_item_id, true );\n\t}\n}\n\n/**\n * Automatically add newly published page objects to menus with that as an option.\n *\n * @since 3.0.0\n * @access private\n *\n * @param string $new_status The new status of the post object.\n * @param string $old_status The old status of the post object.\n * @param object $post The post object being transitioned from one status to another.\n * @return void\n */\nfunction _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {\n\tif ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )\n\t\treturn;\n\tif ( ! empty( $post->post_parent ) )\n\t\treturn;\n\t$auto_add = get_option( 'nav_menu_options' );\n\tif ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )\n\t\treturn;\n\t$auto_add = $auto_add['auto_add'];\n\tif ( empty( $auto_add ) || ! is_array( $auto_add ) )\n\t\treturn;\n\n\t$args = array(\n\t\t'menu-item-object-id' => $post->ID,\n\t\t'menu-item-object' => $post->post_type,\n\t\t'menu-item-type' => 'post_type',\n\t\t'menu-item-status' => 'publish',\n\t);\n\n\tforeach ( $auto_add as $menu_id ) {\n\t\t$items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );\n\t\tif ( ! is_array( $items ) )\n\t\t\tcontinue;\n\t\tforeach ( $items as $item ) {\n\t\t\tif ( $post->ID == $item->object_id )\n\t\t\t\tcontinue 2;\n\t\t}\n\t\twp_update_nav_menu_item( $menu_id, 0, $args );\n\t}\n}\n
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>windows-1250
     
    496496        else
    497497                $args['include'] = $items[0];
    498498
    499         $items = get_posts( $args );
     499        $items = get_posts( apply_filters( 'wp_get_nav_menu_items_args', $args, $menu, $items ) );
    500500
    501501        if ( is_wp_error( $items ) || ! is_array( $items ) )
    502502                return false;