wp/wp-includes/nav-menu.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Navigation Menu functions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Nav_Menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Returns a navigation menu object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
 * @param int|string|WP_Term $menu Menu ID, slug, name, or object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
 * @return WP_Term|false False if $menu param isn't supplied or term does not exist, menu object if successful.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
function wp_get_nav_menu_object( $menu ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	$menu_obj = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
	if ( is_object( $menu ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
		$menu_obj = $menu;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
	if ( $menu && ! $menu_obj ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
		$menu_obj = get_term( $menu, 'nav_menu' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
		if ( ! $menu_obj ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
			$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    32
		if ( ! $menu_obj ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    33
			$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    34
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    35
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    36
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
	if ( ! $menu_obj || is_wp_error( $menu_obj ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    38
		$menu_obj = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    39
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    41
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    42
	 * Filters the nav_menu term retrieved for wp_get_nav_menu_object().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    43
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    44
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    45
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
	 * @param WP_Term|false      $menu_obj Term from nav_menu taxonomy, or false if nothing had been found.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    47
	 * @param int|string|WP_Term $menu     The menu ID, slug, name, or object passed to wp_get_nav_menu_object().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    48
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    49
	return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 * Check if the given ID is a navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * Returns true if it is; false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
 * @param int|string|WP_Term $menu Menu ID, slug, name, or object of menu to check.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * @return bool Whether the menu exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
function is_nav_menu( $menu ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	if ( ! $menu )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	$menu_obj = wp_get_nav_menu_object( $menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		$menu_obj &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		! is_wp_error( $menu_obj ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		! empty( $menu_obj->taxonomy ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		'nav_menu' == $menu_obj->taxonomy
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
	)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
 * Registers navigation menu locations for a theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
 * @global array $_wp_registered_nav_menus
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
 * @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
function register_nav_menus( $locations = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	global $_wp_registered_nav_menus;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	add_theme_support( 'menus' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
 * Unregisters a navigation menu location for a theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
 * @since 3.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
 * @global array $_wp_registered_nav_menus
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
 * @param string $location The menu location identifier.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * @return bool True on success, false on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
function unregister_nav_menu( $location ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	global $_wp_registered_nav_menus;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		unset( $_wp_registered_nav_menus[$location] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		if ( empty( $_wp_registered_nav_menus ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
			_remove_theme_support( 'menus' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
 * Registers a navigation menu location for a theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
 * @param string $location    Menu location identifier, like a slug.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
 * @param string $description Menu location descriptive text.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
function register_nav_menu( $location, $description ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	register_nav_menus( array( $location => $description ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   130
 * Retrieves all registered navigation menu locations in a theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   133
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
 * @global array $_wp_registered_nav_menus
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
 * @return array Registered navigation menu locations. If none are registered, an empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
function get_registered_nav_menus() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	global $_wp_registered_nav_menus;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	if ( isset( $_wp_registered_nav_menus ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		return $_wp_registered_nav_menus;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	return array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
 * Retrieves all registered navigation menu locations and the menus assigned to them.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
 * @return array Registered navigation menu locations and the menus assigned them.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
 *               If none are registered, an empty array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
function get_nav_menu_locations() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
	$locations = get_theme_mod( 'nav_menu_locations' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	return ( is_array( $locations ) ) ? $locations : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
 * Determines whether a registered nav menu location has a menu assigned to it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   163
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * @param string $location Menu location identifier.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 * @return bool Whether location has a menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
function has_nav_menu( $location ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
	$has_nav_menu = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
	$registered_nav_menus = get_registered_nav_menus();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
	if ( isset( $registered_nav_menus[ $location ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
		$locations = get_nav_menu_locations();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
		$has_nav_menu = ! empty( $locations[ $location ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   176
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   177
	 * Filters whether a nav menu is assigned to the specified location.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   178
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   179
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
	 * @param bool   $has_nav_menu Whether there is a menu assigned to a location.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
	 * @param string $location     Menu location.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
	return apply_filters( 'has_nav_menu', $has_nav_menu, $location );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
 * Returns the name of a navigation menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
 * @param string $location Menu location identifier.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
 * @return string Menu name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
function wp_get_nav_menu_name( $location ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
	$menu_name = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   197
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
	$locations = get_nav_menu_locations();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
	if ( isset( $locations[ $location ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
		$menu = wp_get_nav_menu_object( $locations[ $location ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
		if ( $menu && $menu->name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
			$menu_name = $menu->name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   207
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
	 * Filters the navigation menu name being returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
	 * @param string $menu_name Menu name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
	 * @param string $location  Menu location identifier.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
	return apply_filters( 'wp_get_nav_menu_name', $menu_name, $location );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   219
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   220
 * Determines whether the given ID is a nav menu item.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
 * @param int $menu_item_id The ID of the potential nav menu item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
 * @return bool Whether the given ID is that of a nav menu item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
function is_nav_menu_item( $menu_item_id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
 * Creates a navigation menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
 * Note that `$menu_name` is expected to be pre-slashed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
 * @param string $menu_name Menu name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
 * @return int|WP_Error Menu ID on success, WP_Error object on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
function wp_create_nav_menu( $menu_name ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
	// expected_slashed ($menu_name)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
 * Delete a Navigation Menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
 * @param int|string|WP_Term $menu Menu ID, slug, name, or object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
 * @return bool|WP_Error True on success, false or WP_Error object on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
function wp_delete_nav_menu( $menu ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	$menu = wp_get_nav_menu_object( $menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	if ( ! $menu )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
	if ( ! empty( $menu_objects ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		foreach ( $menu_objects as $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
			wp_delete_post( $item );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	$result = wp_delete_term( $menu->term_id, 'nav_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	// Remove this menu from any locations.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	$locations = get_nav_menu_locations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
	foreach ( $locations as $location => $menu_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		if ( $menu_id == $menu->term_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			$locations[ $location ] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	set_theme_mod( 'nav_menu_locations', $locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	if ( $result && !is_wp_error($result) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
		 * Fires after a navigation menu has been successfully deleted.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
		 * @param int $term_id ID of the deleted menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		do_action( 'wp_delete_nav_menu', $menu->term_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	return $result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 * Save the properties of a menu or create a new menu with those properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
 * Note that `$menu_data` is expected to be pre-slashed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   294
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   297
 * @param int   $menu_id   The ID of the menu or "0" to create a new menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * @param array $menu_data The array of menu data.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
 * @return int|WP_Error Menu ID on success, WP_Error object on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
	// expected_slashed ($menu_data)
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	$menu_id = (int) $menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	$_menu = wp_get_nav_menu_object( $menu_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		'description' => ( isset( $menu_data['description'] ) ? $menu_data['description']  : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		'name'        => ( isset( $menu_data['menu-name']   ) ? $menu_data['menu-name']    : '' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		'parent'      => ( isset( $menu_data['parent']      ) ? (int) $menu_data['parent'] : 0  ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
		'slug'        => null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	// double-check that we're not going to have one menu take the name of another
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	$_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		$_possible_existing &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		! is_wp_error( $_possible_existing ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		isset( $_possible_existing->term_id ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
		$_possible_existing->term_id != $menu_id
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   321
	) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   322
		return new WP_Error( 'menu_exists',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   323
			/* translators: %s: menu name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
			sprintf( __( 'The menu name %s conflicts with another menu name. Please try another.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
				'<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	// menu doesn't already exist, so create a new menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	if ( ! $_menu || is_wp_error( $_menu ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
		$menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
		if ( $menu_exists ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   335
			return new WP_Error( 'menu_exists',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
				/* translators: %s: menu name */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
				sprintf( __( 'The menu name %s conflicts with another menu name. Please try another.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   338
					'<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
				)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
		$_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		if ( is_wp_error( $_menu ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			return $_menu;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
		 * Fires after a navigation menu is successfully created.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
		 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
		 * @param int   $term_id   ID of the new menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
		 * @param array $menu_data An array of menu data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		return (int) $_menu['term_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
	if ( ! $_menu || ! isset( $_menu->term_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
		return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
	$menu_id = (int) $_menu->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
	$update_response = wp_update_term( $menu_id, 'nav_menu', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
	if ( is_wp_error( $update_response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
		return $update_response;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
	$menu_id = (int) $update_response['term_id'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
	 * Fires after a navigation menu has been successfully updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
	 * @param int   $menu_id   ID of the updated menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
	 * @param array $menu_data An array of menu data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	do_action( 'wp_update_nav_menu', $menu_id, $menu_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	return $menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * Save the properties of a menu item or create a new one.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   388
 * The menu-item-title, menu-item-description, and menu-item-attr-title are expected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   389
 * to be pre-slashed since they are passed directly into `wp_insert_post()`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
 * @param int   $menu_id         The ID of the menu. Required. If "0", makes the menu item a draft orphan.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
 * @param int   $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
 * @param array $menu_item_data  The menu item's data.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
 * @return int|WP_Error The menu item's database ID or WP_Error object on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	$menu_id = (int) $menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	$menu_item_db_id = (int) $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	// make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
		return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	$menu = wp_get_nav_menu_object( $menu_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
	if ( ! $menu && 0 !== $menu_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
		return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
	if ( is_wp_error( $menu ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		return $menu;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		'menu-item-db-id' => $menu_item_db_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		'menu-item-object-id' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		'menu-item-object' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		'menu-item-parent-id' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		'menu-item-position' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		'menu-item-type' => 'custom',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		'menu-item-title' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
		'menu-item-url' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		'menu-item-description' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		'menu-item-attr-title' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
		'menu-item-target' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		'menu-item-classes' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		'menu-item-xfn' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		'menu-item-status' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	$args = wp_parse_args( $menu_item_data, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
	if ( 0 == $menu_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		$args['menu-item-position'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	} elseif ( 0 == (int) $args['menu-item-position'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		$last_item = array_pop( $menu_items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
		$args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	if ( 'custom' != $args['menu-item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		/* if non-custom menu item, then:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
			* use original object's URL
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
			* blank default title to sync with original object's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		*/
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
		$args['menu-item-url'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		$original_title = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
		if ( 'taxonomy' == $args['menu-item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
			$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		} elseif ( 'post_type' == $args['menu-item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
			$original_object = get_post( $args['menu-item-object-id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			$original_parent = (int) $original_object->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			$original_title = $original_object->post_title;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   462
		} elseif ( 'post_type_archive' == $args['menu-item-type'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   463
			$original_object = get_post_type_object( $args['menu-item-object'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   464
			if ( $original_object ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   465
				$original_title = $original_object->labels->archives;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		if ( $args['menu-item-title'] == $original_title )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
			$args['menu-item-title'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
		// hack to get wp to create a post object when too many properties are empty
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
		if ( '' ==  $args['menu-item-title'] && '' == $args['menu-item-description'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			$args['menu-item-description'] = ' ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	// Populate the menu item object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$post = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		'menu_order' => $args['menu-item-position'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		'ping_status' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
		'post_content' => $args['menu-item-description'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
		'post_excerpt' => $args['menu-item-attr-title'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		'post_parent' => $original_parent,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
		'post_title' => $args['menu-item-title'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		'post_type' => 'nav_menu_item',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	$update = 0 != $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	// New menu item. Default is draft status
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	if ( ! $update ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		$post['ID'] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		$post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
		$menu_item_db_id = wp_insert_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		if ( ! $menu_item_db_id	|| is_wp_error( $menu_item_db_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
			return $menu_item_db_id;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   497
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   498
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   499
		 * Fires immediately after a new navigation menu item has been added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   500
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   501
		 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   502
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   503
		 * @see wp_update_nav_menu_item()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   504
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   505
		 * @param int   $menu_id         ID of the updated menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   506
		 * @param int   $menu_item_db_id ID of the new menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   507
		 * @param array $args            An array of arguments used to update/add the menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   508
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   509
		do_action( 'wp_add_nav_menu_item', $menu_id, $menu_item_db_id, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
	// Associate the menu item with the menu term
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
	// Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
	 if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
		wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	if ( 'custom' == $args['menu-item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		$args['menu-item-object-id'] = $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		$args['menu-item-object'] = 'custom';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	$menu_item_db_id = (int) $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
	$args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	$args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
	update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	if ( 0 == $menu_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	// Update existing menu item. Default is publish status
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	if ( $update ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		$post['ID'] = $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		$post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		wp_update_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
	 * Fires after a navigation menu item has been updated.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	 * @see wp_update_nav_menu_item()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
	 * @param int   $menu_id         ID of the updated menu.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
	 * @param int   $menu_item_db_id ID of the updated menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
	 * @param array $args            An array of arguments used to update a menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	do_action( 'wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	return $menu_item_db_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
 * Returns all navigation menu objects.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
 * @since 4.1.0 Default value of the 'orderby' argument was changed from 'none'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
 *              to 'name'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   572
 * @param array $args Optional. Array of arguments passed on to get_terms().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
 *                    Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
 * @return array Menu objects.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
function wp_get_nav_menus( $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
	$defaults = array( 'hide_empty' => false, 'orderby' => 'name' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	$args = wp_parse_args( $args, $defaults );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
	 * Filters the navigation menu objects being returned.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
	 * @see get_terms()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
	 * @param array $menus An array of menu objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	 * @param array $args  An array of arguments used to retrieve menu objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu',  $args), $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
 * Return if a menu item is valid.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
 * @link https://core.trac.wordpress.org/ticket/13958
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
 * @param object $item The menu item to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
 * @return bool False if invalid, otherwise true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
function _is_valid_nav_menu_item( $item ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   605
	return empty( $item->_invalid );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   609
 * Retrieves all menu items of a navigation menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   611
 * Note: Most arguments passed to the `$args` parameter – save for 'output_key' – are
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   612
 * specifically for retrieving nav_menu_item posts from get_posts() and may only
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
 * indirectly affect the ultimate ordering and content of the resulting nav menu
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   614
 * items that get returned from this function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   618
 * @global string $_menu_item_sort_prop
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   619
 * @staticvar array $fetched
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   620
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   621
 * @param int|string|WP_Term $menu Menu ID, slug, name, or object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   622
 * @param array              $args {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   623
 *     Optional. Arguments to pass to get_posts().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   624
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   625
 *     @type string $order       How to order nav menu items as queried with get_posts(). Will be ignored
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   626
 *                               if 'output' is ARRAY_A. Default 'ASC'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   627
 *     @type string $orderby     Field to order menu items by as retrieved from get_posts(). Supply an orderby
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   628
 *                               field via 'output_key' to affect the output order of nav menu items.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   629
 *                               Default 'menu_order'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   630
 *     @type string $post_type   Menu items post type. Default 'nav_menu_item'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   631
 *     @type string $post_status Menu items post status. Default 'publish'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   632
 *     @type string $output      How to order outputted menu items. Default ARRAY_A.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   633
 *     @type string $output_key  Key to use for ordering the actual menu items that get returned. Note that
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   634
 *                               that is not a get_posts() argument and will only affect output of menu items
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   635
 *                               processed in this function. Default 'menu_order'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   636
 *     @type bool   $nopaging    Whether to retrieve all menu items (true) or paginate (false). Default true.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   637
 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   638
 * @return false|array $items Array of menu items, otherwise false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
function wp_get_nav_menu_items( $menu, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	$menu = wp_get_nav_menu_object( $menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   643
	if ( ! $menu ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   645
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	static $fetched = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   650
	if ( is_wp_error( $items ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   651
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   652
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
		'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	$args = wp_parse_args( $args, $defaults );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   657
	$args['include'] = $items;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   659
	if ( ! empty( $items ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   660
		$items = get_posts( $args );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   661
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   662
		$items = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
	// Get all posts and terms at once to prime the caches
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   666
	if ( empty( $fetched[ $menu->term_id ] ) && ! wp_using_ext_object_cache() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		$fetched[$menu->term_id] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		$posts = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		$terms = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		foreach ( $items as $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
			$object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
			$object    = get_post_meta( $item->ID, '_menu_item_object',    true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
			$type      = get_post_meta( $item->ID, '_menu_item_type',      true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
			if ( 'post_type' == $type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
				$posts[$object][] = $object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
			elseif ( 'taxonomy' == $type)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
				$terms[$object][] = $object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
		if ( ! empty( $posts ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
			foreach ( array_keys($posts) as $post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
				get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		unset($posts);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		if ( ! empty( $terms ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
			foreach ( array_keys($terms) as $taxonomy ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
				get_terms( $taxonomy, array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
					'include' => $terms[ $taxonomy ],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   692
					'hierarchical' => false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   693
				) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
		unset($terms);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	$items = array_map( 'wp_setup_nav_menu_item', $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   701
	if ( ! is_admin() ) { // Remove invalid items only in front end
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		$items = array_filter( $items, '_is_valid_nav_menu_item' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   703
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	if ( ARRAY_A == $args['output'] ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   706
		$items = wp_list_sort( $items, array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   707
			$args['output_key'] => 'ASC',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   708
		) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		$i = 1;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
		foreach ( $items as $k => $item ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   711
			$items[$k]->{$args['output_key']} = $i++;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   715
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   716
	 * Filters the navigation menu items being returned.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   718
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
	 * @param array  $items An array of menu item post objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
	 * @param object $menu  The menu object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
	 * @param array  $args  An array of arguments used to retrieve menu item objects.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   724
	return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 * Decorates a menu item object with the shared navigation menu item properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 * Properties:
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   731
 * - ID:               The term_id if the menu item represents a taxonomy term.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   732
 * - attr_title:       The title attribute of the link element for this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   733
 * - classes:          The array of class attribute values for the link element of this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   734
 * - db_id:            The DB ID of this item as a nav_menu_item object, if it exists (0 if it doesn't exist).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   735
 * - description:      The description of this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   736
 * - menu_item_parent: The DB ID of the nav_menu_item that is this item's menu parent, if any. 0 otherwise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   737
 * - object:           The type of object originally represented, such as "category," "post", or "attachment."
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   738
 * - object_id:        The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   739
 * - post_parent:      The DB ID of the original object's parent object, if any (0 otherwise).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   740
 * - post_title:       A "no title" label if menu item represents a post that lacks a title.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   741
 * - target:           The target attribute of the link element for this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   742
 * - title:            The title of this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
 * - type:             The family of objects originally represented, such as "post_type" or "taxonomy."
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
 * - type_label:       The singular label used to describe this type of menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
 * - url:              The URL to which this menu item points.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
 * - xfn:              The XFN relationship expressed in the link of this menu item.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   747
 * - _invalid:         Whether the menu item represents an object that no longer exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
 * @param object $menu_item The menu item to modify.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
 * @return object $menu_item The menu item with standard menu item properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
function wp_setup_nav_menu_item( $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	if ( isset( $menu_item->post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		if ( 'nav_menu_item' == $menu_item->post_type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
			$menu_item->db_id = (int) $menu_item->ID;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   758
			$menu_item->menu_item_parent = ! isset( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   759
			$menu_item->object_id = ! isset( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   760
			$menu_item->object = ! isset( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   761
			$menu_item->type = ! isset( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
			if ( 'post_type' == $menu_item->type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
				$object = get_post_type_object( $menu_item->object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
				if ( $object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
					$menu_item->type_label = $object->labels->singular_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
					$menu_item->type_label = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
					$menu_item->_invalid = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   772
				if ( 'trash' === get_post_status( $menu_item->object_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   773
					$menu_item->_invalid = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   774
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   775
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
				$menu_item->url = get_permalink( $menu_item->object_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
				$original_object = get_post( $menu_item->object_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
				/** This filter is documented in wp-includes/post-template.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   780
				$original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
				if ( '' === $original_title ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   783
					/* translators: %d: ID of a post */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
					$original_title = sprintf( __( '#%d (no title)' ), $original_object->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
				$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
			} elseif ( 'post_type_archive' == $menu_item->type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
				$object =  get_post_type_object( $menu_item->object );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
				if ( $object ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
					$menu_item->title = '' == $menu_item->post_title ? $object->labels->archives : $menu_item->post_title;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
					$post_type_description = $object->description;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   794
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   795
					$menu_item->_invalid = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   796
					$post_type_description = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   797
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   798
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   799
				$menu_item->type_label = __( 'Post Type Archive' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   800
				$post_content = wp_trim_words( $menu_item->post_content, 200 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   801
				$post_type_description = '' == $post_content ? $post_type_description : $post_content;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   802
				$menu_item->url = get_post_type_archive_link( $menu_item->object );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
			} elseif ( 'taxonomy' == $menu_item->type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				$object = get_taxonomy( $menu_item->object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
				if ( $object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
					$menu_item->type_label = $object->labels->singular_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
					$menu_item->type_label = $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
					$menu_item->_invalid = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
				$term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
				$menu_item->url = !is_wp_error( $term_url ) ? $term_url : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
				$original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
				if ( is_wp_error( $original_title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
					$original_title = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
				$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
			} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
				$menu_item->type_label = __('Custom Link');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
				$menu_item->title = $menu_item->post_title;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   823
				$menu_item->url = ! isset( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   826
			$menu_item->target = ! isset( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
			/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   829
			 * Filters a navigation menu item's title attribute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
			 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
			 * @param string $item_title The menu item title attribute.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
			 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   835
			$menu_item->attr_title = ! isset( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   837
			if ( ! isset( $menu_item->description ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
				/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   839
				 * Filters a navigation menu item's description.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
				 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
				 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
				 * @param string $description The menu item description.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
				$menu_item->description = apply_filters( 'nav_menu_description', wp_trim_words( $menu_item->post_content, 200 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   848
			$menu_item->classes = ! isset( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   849
			$menu_item->xfn = ! isset( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
			$menu_item->db_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
			$menu_item->menu_item_parent = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
			$menu_item->object_id = (int) $menu_item->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
			$menu_item->type = 'post_type';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
			$object = get_post_type_object( $menu_item->post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
			$menu_item->object = $object->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			$menu_item->type_label = $object->labels->singular_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   860
			if ( '' === $menu_item->post_title ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   861
				/* translators: %d: ID of a post */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
				$menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   863
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
			$menu_item->title = $menu_item->post_title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
			$menu_item->url = get_permalink( $menu_item->ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
			$menu_item->target = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
			/** This filter is documented in wp-includes/nav-menu.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
			$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', '' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
			/** This filter is documented in wp-includes/nav-menu.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
			$menu_item->description = apply_filters( 'nav_menu_description', '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			$menu_item->classes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
			$menu_item->xfn = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	} elseif ( isset( $menu_item->taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		$menu_item->ID = $menu_item->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		$menu_item->db_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		$menu_item->menu_item_parent = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
		$menu_item->object_id = (int) $menu_item->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		$menu_item->post_parent = (int) $menu_item->parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		$menu_item->type = 'taxonomy';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
		$object = get_taxonomy( $menu_item->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
		$menu_item->object = $object->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
		$menu_item->type_label = $object->labels->singular_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
		$menu_item->title = $menu_item->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		$menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
		$menu_item->target = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		$menu_item->attr_title = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
		$menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		$menu_item->classes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
		$menu_item->xfn = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   900
	 * Filters a navigation menu item object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
	 * @since 3.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
	 * @param object $menu_item The menu item object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	return apply_filters( 'wp_setup_nav_menu_item', $menu_item );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
 * Get the menu items associated with a particular object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   914
 * @param int    $object_id   The ID of the original object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
 * @param string $object_type The type of object, such as "taxonomy" or "post_type."
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   916
 * @param string $taxonomy    If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
 * @return array The array of menu item IDs; empty array if none;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
	$object_id = (int) $object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
	$menu_item_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	$query = new WP_Query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	$menu_items = $query->query(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
		array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
			'meta_key' => '_menu_item_object_id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
			'meta_value' => $object_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
			'post_status' => 'any',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
			'post_type' => 'nav_menu_item',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
			'posts_per_page' => -1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   933
	foreach ( (array) $menu_items as $menu_item ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   935
			$menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
			if (
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
				'post_type' == $object_type &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
				'post_type' == $menu_item_type
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
			) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
				$menu_item_ids[] = (int) $menu_item->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   941
			} elseif (
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
				'taxonomy' == $object_type &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   943
				'taxonomy' == $menu_item_type &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
				get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
			) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
				$menu_item_ids[] = (int) $menu_item->ID;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	return array_unique( $menu_item_ids );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
 * Callback for handling a menu item when its original object is deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
 * @param int $object_id The ID of the original object being trashed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
function _wp_delete_post_menu_item( $object_id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	$object_id = (int) $object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   968
	foreach ( (array) $menu_item_ids as $menu_item_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		wp_delete_post( $menu_item_id, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   974
 * Serves as a callback for handling a menu item when its original object is deleted.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   979
 * @param int    $object_id Optional. The ID of the original object being trashed. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   980
 * @param int    $tt_id     Term taxonomy ID. Unused.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   981
 * @param string $taxonomy  Taxonomy slug.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	$object_id = (int) $object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   988
	foreach ( (array) $menu_item_ids as $menu_item_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		wp_delete_post( $menu_item_id, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
 * Automatically add newly published page objects to menus with that as an option.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
 * @param string $new_status The new status of the post object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
 * @param string $old_status The old status of the post object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1001
 * @param object $post       The post object being transitioned from one status to another.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
	if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	if ( ! empty( $post->post_parent ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	$auto_add = get_option( 'nav_menu_options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	$auto_add = $auto_add['auto_add'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	if ( empty( $auto_add ) || ! is_array( $auto_add ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		'menu-item-object-id' => $post->ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
		'menu-item-object' => $post->post_type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
		'menu-item-type' => 'post_type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
		'menu-item-status' => 'publish',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	foreach ( $auto_add as $menu_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		$items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
		if ( ! is_array( $items ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
		foreach ( $items as $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
			if ( $post->ID == $item->object_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
				continue 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		wp_update_nav_menu_item( $menu_id, 0, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1033
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1034
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1035
 * Delete auto-draft posts associated with the supplied changeset.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1036
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1037
 * @since 4.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1038
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1039
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1040
 * @param int $post_id Post ID for the customize_changeset.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1041
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
function _wp_delete_customize_changeset_dependent_auto_drafts( $post_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1043
	$post = get_post( $post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1044
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1045
	if ( ! $post || 'customize_changeset' !== $post->post_type ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1046
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1047
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1048
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1049
	$data = json_decode( $post->post_content, true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1050
	if ( empty( $data['nav_menus_created_posts']['value'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1051
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1052
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1053
	remove_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1054
	foreach ( $data['nav_menus_created_posts']['value'] as $stub_post_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1055
		if ( empty( $stub_post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1056
			continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1057
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1058
		if ( 'auto-draft' === get_post_status( $stub_post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1059
			wp_delete_post( $stub_post_id, true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1060
		} elseif ( 'draft' === get_post_status( $stub_post_id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1061
			wp_trash_post( $stub_post_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1062
			delete_post_meta( $stub_post_id, '_customize_changeset_uuid' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1063
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
	add_action( 'delete_post', '_wp_delete_customize_changeset_dependent_auto_drafts' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1066
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1067
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1069
 * Handle menu config after theme change.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1070
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1074
function _wp_menus_changed() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
	$old_nav_menu_locations    = get_option( 'theme_switch_menu_locations', array() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1076
	$new_nav_menu_locations    = get_nav_menu_locations();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1077
	$mapped_nav_menu_locations = wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locations );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1078
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1079
	set_theme_mod( 'nav_menu_locations', $mapped_nav_menu_locations );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1080
	delete_option( 'theme_switch_menu_locations' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1081
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1082
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1083
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1084
 * Maps nav menu locations according to assignments in previously active theme.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1085
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1086
 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1087
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1088
 * @param array $new_nav_menu_locations New nav menu locations assignments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1089
 * @param array $old_nav_menu_locations Old nav menu locations assignments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1090
 * @return array Nav menus mapped to new nav menu locations.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locations ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
	$registered_nav_menus   = get_registered_nav_menus();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
	$new_nav_menu_locations = array_intersect_key( $new_nav_menu_locations, $registered_nav_menus );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
	// Short-circuit if there are no old nav menu location assignments to map.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
	if ( empty( $old_nav_menu_locations ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
		return $new_nav_menu_locations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
	// If old and new theme have just one location, map it and we're done.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
	if ( 1 === count( $old_nav_menu_locations ) && 1 === count( $registered_nav_menus ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
		$new_nav_menu_locations[ key( $registered_nav_menus ) ] = array_pop( $old_nav_menu_locations );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1104
		return $new_nav_menu_locations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
	$old_locations = array_keys( $old_nav_menu_locations );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
	// Map locations with the same slug.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
	foreach ( $registered_nav_menus as $location => $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
		if ( in_array( $location, $old_locations, true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
			$new_nav_menu_locations[ $location ] = $old_nav_menu_locations[ $location ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
			unset( $old_nav_menu_locations[ $location ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
	// If there are no old nav menu locations left, then we're done.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
	if ( empty( $old_nav_menu_locations ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
		return $new_nav_menu_locations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
	 * If old and new theme both have locations that contain phrases
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
	 * from within the same group, make an educated guess and map it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1125
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
	$common_slug_groups = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1127
		array( 'primary', 'menu-1', 'main', 'header', 'navigation', 'top' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1128
		array( 'secondary', 'menu-2', 'footer', 'subsidiary', 'bottom' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1129
		array( 'social' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1131
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1132
	// Go through each group...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1133
	foreach ( $common_slug_groups as $slug_group ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1135
		// ...and see if any of these slugs...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1136
		foreach ( $slug_group as $slug ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1137
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1138
			// ...and any of the new menu locations...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
			foreach ( $registered_nav_menus as $new_location => $name ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1141
				// ...actually match!
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
				if ( false === stripos( $new_location, $slug ) && false === stripos( $slug, $new_location ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
					continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1145
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
				// Then see if any of the old locations...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
				foreach ( $old_nav_menu_locations as $location => $menu_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1148
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
					// ...and any slug in the same group...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1150
					foreach ( $slug_group as $slug ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1151
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1152
						// ... have a match as well.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1153
						if ( false === stripos( $location, $slug ) && false === stripos( $slug, $location ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1154
							continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1156
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1157
						// Make sure this location wasn't mapped and removed previously.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1158
						if ( ! empty( $old_nav_menu_locations[ $location ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1159
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1160
							// We have a match that can be mapped!
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1161
							$new_nav_menu_locations[ $new_location ] = $old_nav_menu_locations[ $location ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1162
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1163
							// Remove the mapped location so it can't be mapped again.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1164
							unset( $old_nav_menu_locations[ $location ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1165
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1166
							// Go back and check the next new menu location.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1167
							continue 3;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1168
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1169
					} // endforeach ( $slug_group as $slug )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1170
				} // endforeach ( $old_nav_menu_locations as $location => $menu_id )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1171
			} // endforeach foreach ( $registered_nav_menus as $new_location => $name )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1172
		} // endforeach ( $slug_group as $slug )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1173
	} // endforeach ( $common_slug_groups as $slug_group )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1174
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1175
	return $new_nav_menu_locations;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1176
}