Edit File by line
/home/barbar84/www/wp-inclu...
File: nav-menu.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Navigation Menu functions
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Nav_Menus
[5] Fix | Delete
* @since 3.0.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Returns a navigation menu object.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 3.0.0
[12] Fix | Delete
*
[13] Fix | Delete
* @param int|string|WP_Term $menu Menu ID, slug, name, or object.
[14] Fix | Delete
* @return WP_Term|false Menu object on success, false if $menu param isn't supplied or term does not exist.
[15] Fix | Delete
*/
[16] Fix | Delete
function wp_get_nav_menu_object( $menu ) {
[17] Fix | Delete
$menu_obj = false;
[18] Fix | Delete
[19] Fix | Delete
if ( is_object( $menu ) ) {
[20] Fix | Delete
$menu_obj = $menu;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
if ( $menu && ! $menu_obj ) {
[24] Fix | Delete
$menu_obj = get_term( $menu, 'nav_menu' );
[25] Fix | Delete
[26] Fix | Delete
if ( ! $menu_obj ) {
[27] Fix | Delete
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
if ( ! $menu_obj ) {
[31] Fix | Delete
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
if ( ! $menu_obj || is_wp_error( $menu_obj ) ) {
[36] Fix | Delete
$menu_obj = false;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Filters the nav_menu term retrieved for wp_get_nav_menu_object().
[41] Fix | Delete
*
[42] Fix | Delete
* @since 4.3.0
[43] Fix | Delete
*
[44] Fix | Delete
* @param WP_Term|false $menu_obj Term from nav_menu taxonomy, or false if nothing had been found.
[45] Fix | Delete
* @param int|string|WP_Term $menu The menu ID, slug, name, or object passed to wp_get_nav_menu_object().
[46] Fix | Delete
*/
[47] Fix | Delete
return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Check if the given ID is a navigation menu.
[52] Fix | Delete
*
[53] Fix | Delete
* Returns true if it is; false otherwise.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 3.0.0
[56] Fix | Delete
*
[57] Fix | Delete
* @param int|string|WP_Term $menu Menu ID, slug, name, or object of menu to check.
[58] Fix | Delete
* @return bool Whether the menu exists.
[59] Fix | Delete
*/
[60] Fix | Delete
function is_nav_menu( $menu ) {
[61] Fix | Delete
if ( ! $menu ) {
[62] Fix | Delete
return false;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$menu_obj = wp_get_nav_menu_object( $menu );
[66] Fix | Delete
[67] Fix | Delete
if (
[68] Fix | Delete
$menu_obj &&
[69] Fix | Delete
! is_wp_error( $menu_obj ) &&
[70] Fix | Delete
! empty( $menu_obj->taxonomy ) &&
[71] Fix | Delete
'nav_menu' === $menu_obj->taxonomy
[72] Fix | Delete
) {
[73] Fix | Delete
return true;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
return false;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Registers navigation menu locations for a theme.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 3.0.0
[83] Fix | Delete
*
[84] Fix | Delete
* @global array $_wp_registered_nav_menus
[85] Fix | Delete
*
[86] Fix | Delete
* @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text.
[87] Fix | Delete
*/
[88] Fix | Delete
function register_nav_menus( $locations = array() ) {
[89] Fix | Delete
global $_wp_registered_nav_menus;
[90] Fix | Delete
[91] Fix | Delete
add_theme_support( 'menus' );
[92] Fix | Delete
[93] Fix | Delete
foreach ( $locations as $key => $value ) {
[94] Fix | Delete
if ( is_int( $key ) ) {
[95] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'Nav menu locations must be strings.' ), '5.3.0' );
[96] Fix | Delete
break;
[97] Fix | Delete
}
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Unregisters a navigation menu location for a theme.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.1.0
[107] Fix | Delete
*
[108] Fix | Delete
* @global array $_wp_registered_nav_menus
[109] Fix | Delete
*
[110] Fix | Delete
* @param string $location The menu location identifier.
[111] Fix | Delete
* @return bool True on success, false on failure.
[112] Fix | Delete
*/
[113] Fix | Delete
function unregister_nav_menu( $location ) {
[114] Fix | Delete
global $_wp_registered_nav_menus;
[115] Fix | Delete
[116] Fix | Delete
if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[ $location ] ) ) {
[117] Fix | Delete
unset( $_wp_registered_nav_menus[ $location ] );
[118] Fix | Delete
if ( empty( $_wp_registered_nav_menus ) ) {
[119] Fix | Delete
_remove_theme_support( 'menus' );
[120] Fix | Delete
}
[121] Fix | Delete
return true;
[122] Fix | Delete
}
[123] Fix | Delete
return false;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Registers a navigation menu location for a theme.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 3.0.0
[130] Fix | Delete
*
[131] Fix | Delete
* @param string $location Menu location identifier, like a slug.
[132] Fix | Delete
* @param string $description Menu location descriptive text.
[133] Fix | Delete
*/
[134] Fix | Delete
function register_nav_menu( $location, $description ) {
[135] Fix | Delete
register_nav_menus( array( $location => $description ) );
[136] Fix | Delete
}
[137] Fix | Delete
/**
[138] Fix | Delete
* Retrieves all registered navigation menu locations in a theme.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 3.0.0
[141] Fix | Delete
*
[142] Fix | Delete
* @global array $_wp_registered_nav_menus
[143] Fix | Delete
*
[144] Fix | Delete
* @return array Registered navigation menu locations. If none are registered, an empty array.
[145] Fix | Delete
*/
[146] Fix | Delete
function get_registered_nav_menus() {
[147] Fix | Delete
global $_wp_registered_nav_menus;
[148] Fix | Delete
if ( isset( $_wp_registered_nav_menus ) ) {
[149] Fix | Delete
return $_wp_registered_nav_menus;
[150] Fix | Delete
}
[151] Fix | Delete
return array();
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Retrieves all registered navigation menu locations and the menus assigned to them.
[156] Fix | Delete
*
[157] Fix | Delete
* @since 3.0.0
[158] Fix | Delete
*
[159] Fix | Delete
* @return array Registered navigation menu locations and the menus assigned them.
[160] Fix | Delete
* If none are registered, an empty array.
[161] Fix | Delete
*/
[162] Fix | Delete
[163] Fix | Delete
function get_nav_menu_locations() {
[164] Fix | Delete
$locations = get_theme_mod( 'nav_menu_locations' );
[165] Fix | Delete
return ( is_array( $locations ) ) ? $locations : array();
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Determines whether a registered nav menu location has a menu assigned to it.
[170] Fix | Delete
*
[171] Fix | Delete
* @since 3.0.0
[172] Fix | Delete
*
[173] Fix | Delete
* @param string $location Menu location identifier.
[174] Fix | Delete
* @return bool Whether location has a menu.
[175] Fix | Delete
*/
[176] Fix | Delete
function has_nav_menu( $location ) {
[177] Fix | Delete
$has_nav_menu = false;
[178] Fix | Delete
[179] Fix | Delete
$registered_nav_menus = get_registered_nav_menus();
[180] Fix | Delete
if ( isset( $registered_nav_menus[ $location ] ) ) {
[181] Fix | Delete
$locations = get_nav_menu_locations();
[182] Fix | Delete
$has_nav_menu = ! empty( $locations[ $location ] );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Filters whether a nav menu is assigned to the specified location.
[187] Fix | Delete
*
[188] Fix | Delete
* @since 4.3.0
[189] Fix | Delete
*
[190] Fix | Delete
* @param bool $has_nav_menu Whether there is a menu assigned to a location.
[191] Fix | Delete
* @param string $location Menu location.
[192] Fix | Delete
*/
[193] Fix | Delete
return apply_filters( 'has_nav_menu', $has_nav_menu, $location );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Returns the name of a navigation menu.
[198] Fix | Delete
*
[199] Fix | Delete
* @since 4.9.0
[200] Fix | Delete
*
[201] Fix | Delete
* @param string $location Menu location identifier.
[202] Fix | Delete
* @return string Menu name.
[203] Fix | Delete
*/
[204] Fix | Delete
function wp_get_nav_menu_name( $location ) {
[205] Fix | Delete
$menu_name = '';
[206] Fix | Delete
[207] Fix | Delete
$locations = get_nav_menu_locations();
[208] Fix | Delete
[209] Fix | Delete
if ( isset( $locations[ $location ] ) ) {
[210] Fix | Delete
$menu = wp_get_nav_menu_object( $locations[ $location ] );
[211] Fix | Delete
[212] Fix | Delete
if ( $menu && $menu->name ) {
[213] Fix | Delete
$menu_name = $menu->name;
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Filters the navigation menu name being returned.
[219] Fix | Delete
*
[220] Fix | Delete
* @since 4.9.0
[221] Fix | Delete
*
[222] Fix | Delete
* @param string $menu_name Menu name.
[223] Fix | Delete
* @param string $location Menu location identifier.
[224] Fix | Delete
*/
[225] Fix | Delete
return apply_filters( 'wp_get_nav_menu_name', $menu_name, $location );
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Determines whether the given ID is a nav menu item.
[230] Fix | Delete
*
[231] Fix | Delete
* @since 3.0.0
[232] Fix | Delete
*
[233] Fix | Delete
* @param int $menu_item_id The ID of the potential nav menu item.
[234] Fix | Delete
* @return bool Whether the given ID is that of a nav menu item.
[235] Fix | Delete
*/
[236] Fix | Delete
function is_nav_menu_item( $menu_item_id = 0 ) {
[237] Fix | Delete
return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' === get_post_type( $menu_item_id ) ) );
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Creates a navigation menu.
[242] Fix | Delete
*
[243] Fix | Delete
* Note that `$menu_name` is expected to be pre-slashed.
[244] Fix | Delete
*
[245] Fix | Delete
* @since 3.0.0
[246] Fix | Delete
*
[247] Fix | Delete
* @param string $menu_name Menu name.
[248] Fix | Delete
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
[249] Fix | Delete
*/
[250] Fix | Delete
function wp_create_nav_menu( $menu_name ) {
[251] Fix | Delete
// expected_slashed ($menu_name)
[252] Fix | Delete
return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Delete a Navigation Menu.
[257] Fix | Delete
*
[258] Fix | Delete
* @since 3.0.0
[259] Fix | Delete
*
[260] Fix | Delete
* @param int|string|WP_Term $menu Menu ID, slug, name, or object.
[261] Fix | Delete
* @return bool|WP_Error True on success, false or WP_Error object on failure.
[262] Fix | Delete
*/
[263] Fix | Delete
function wp_delete_nav_menu( $menu ) {
[264] Fix | Delete
$menu = wp_get_nav_menu_object( $menu );
[265] Fix | Delete
if ( ! $menu ) {
[266] Fix | Delete
return false;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
[270] Fix | Delete
if ( ! empty( $menu_objects ) ) {
[271] Fix | Delete
foreach ( $menu_objects as $item ) {
[272] Fix | Delete
wp_delete_post( $item );
[273] Fix | Delete
}
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
$result = wp_delete_term( $menu->term_id, 'nav_menu' );
[277] Fix | Delete
[278] Fix | Delete
// Remove this menu from any locations.
[279] Fix | Delete
$locations = get_nav_menu_locations();
[280] Fix | Delete
foreach ( $locations as $location => $menu_id ) {
[281] Fix | Delete
if ( $menu_id == $menu->term_id ) {
[282] Fix | Delete
$locations[ $location ] = 0;
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
set_theme_mod( 'nav_menu_locations', $locations );
[286] Fix | Delete
[287] Fix | Delete
if ( $result && ! is_wp_error( $result ) ) {
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Fires after a navigation menu has been successfully deleted.
[291] Fix | Delete
*
[292] Fix | Delete
* @since 3.0.0
[293] Fix | Delete
*
[294] Fix | Delete
* @param int $term_id ID of the deleted menu.
[295] Fix | Delete
*/
[296] Fix | Delete
do_action( 'wp_delete_nav_menu', $menu->term_id );
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
return $result;
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Save the properties of a menu or create a new menu with those properties.
[304] Fix | Delete
*
[305] Fix | Delete
* Note that `$menu_data` is expected to be pre-slashed.
[306] Fix | Delete
*
[307] Fix | Delete
* @since 3.0.0
[308] Fix | Delete
*
[309] Fix | Delete
* @param int $menu_id The ID of the menu or "0" to create a new menu.
[310] Fix | Delete
* @param array $menu_data The array of menu data.
[311] Fix | Delete
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
[312] Fix | Delete
*/
[313] Fix | Delete
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
[314] Fix | Delete
// expected_slashed ($menu_data)
[315] Fix | Delete
$menu_id = (int) $menu_id;
[316] Fix | Delete
[317] Fix | Delete
$_menu = wp_get_nav_menu_object( $menu_id );
[318] Fix | Delete
[319] Fix | Delete
$args = array(
[320] Fix | Delete
'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ),
[321] Fix | Delete
'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ),
[322] Fix | Delete
'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ),
[323] Fix | Delete
'slug' => null,
[324] Fix | Delete
);
[325] Fix | Delete
[326] Fix | Delete
// Double-check that we're not going to have one menu take the name of another.
[327] Fix | Delete
$_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );
[328] Fix | Delete
if (
[329] Fix | Delete
$_possible_existing &&
[330] Fix | Delete
! is_wp_error( $_possible_existing ) &&
[331] Fix | Delete
isset( $_possible_existing->term_id ) &&
[332] Fix | Delete
$_possible_existing->term_id != $menu_id
[333] Fix | Delete
) {
[334] Fix | Delete
return new WP_Error(
[335] Fix | Delete
'menu_exists',
[336] Fix | Delete
sprintf(
[337] Fix | Delete
/* translators: %s: Menu name. */
[338] Fix | Delete
__( 'The menu name %s conflicts with another menu name. Please try another.' ),
[339] Fix | Delete
'<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>'
[340] Fix | Delete
)
[341] Fix | Delete
);
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
// Menu doesn't already exist, so create a new menu.
[345] Fix | Delete
if ( ! $_menu || is_wp_error( $_menu ) ) {
[346] Fix | Delete
$menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );
[347] Fix | Delete
[348] Fix | Delete
if ( $menu_exists ) {
[349] Fix | Delete
return new WP_Error(
[350] Fix | Delete
'menu_exists',
[351] Fix | Delete
sprintf(
[352] Fix | Delete
/* translators: %s: Menu name. */
[353] Fix | Delete
__( 'The menu name %s conflicts with another menu name. Please try another.' ),
[354] Fix | Delete
'<strong>' . esc_html( $menu_data['menu-name'] ) . '</strong>'
[355] Fix | Delete
)
[356] Fix | Delete
);
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
$_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args );
[360] Fix | Delete
[361] Fix | Delete
if ( is_wp_error( $_menu ) ) {
[362] Fix | Delete
return $_menu;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Fires after a navigation menu is successfully created.
[367] Fix | Delete
*
[368] Fix | Delete
* @since 3.0.0
[369] Fix | Delete
*
[370] Fix | Delete
* @param int $term_id ID of the new menu.
[371] Fix | Delete
* @param array $menu_data An array of menu data.
[372] Fix | Delete
*/
[373] Fix | Delete
do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data );
[374] Fix | Delete
[375] Fix | Delete
return (int) $_menu['term_id'];
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
if ( ! $_menu || ! isset( $_menu->term_id ) ) {
[379] Fix | Delete
return 0;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
$menu_id = (int) $_menu->term_id;
[383] Fix | Delete
[384] Fix | Delete
$update_response = wp_update_term( $menu_id, 'nav_menu', $args );
[385] Fix | Delete
[386] Fix | Delete
if ( is_wp_error( $update_response ) ) {
[387] Fix | Delete
return $update_response;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
$menu_id = (int) $update_response['term_id'];
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* Fires after a navigation menu has been successfully updated.
[394] Fix | Delete
*
[395] Fix | Delete
* @since 3.0.0
[396] Fix | Delete
*
[397] Fix | Delete
* @param int $menu_id ID of the updated menu.
[398] Fix | Delete
* @param array $menu_data An array of menu data.
[399] Fix | Delete
*/
[400] Fix | Delete
do_action( 'wp_update_nav_menu', $menu_id, $menu_data );
[401] Fix | Delete
return $menu_id;
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
/**
[405] Fix | Delete
* Save the properties of a menu item or create a new one.
[406] Fix | Delete
*
[407] Fix | Delete
* The menu-item-title, menu-item-description, and menu-item-attr-title are expected
[408] Fix | Delete
* to be pre-slashed since they are passed directly into `wp_insert_post()`.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 3.0.0
[411] Fix | Delete
*
[412] Fix | Delete
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
[413] Fix | Delete
* @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
[414] Fix | Delete
* @param array $menu_item_data The menu item's data.
[415] Fix | Delete
* @return int|WP_Error The menu item's database ID or WP_Error object on failure.
[416] Fix | Delete
*/
[417] Fix | Delete
function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
[418] Fix | Delete
$menu_id = (int) $menu_id;
[419] Fix | Delete
$menu_item_db_id = (int) $menu_item_db_id;
[420] Fix | Delete
[421] Fix | Delete
// Make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects.
[422] Fix | Delete
if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) ) {
[423] Fix | Delete
return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) );
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
$menu = wp_get_nav_menu_object( $menu_id );
[427] Fix | Delete
[428] Fix | Delete
if ( ! $menu && 0 !== $menu_id ) {
[429] Fix | Delete
return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) );
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
if ( is_wp_error( $menu ) ) {
[433] Fix | Delete
return $menu;
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
$defaults = array(
[437] Fix | Delete
'menu-item-db-id' => $menu_item_db_id,
[438] Fix | Delete
'menu-item-object-id' => 0,
[439] Fix | Delete
'menu-item-object' => '',
[440] Fix | Delete
'menu-item-parent-id' => 0,
[441] Fix | Delete
'menu-item-position' => 0,
[442] Fix | Delete
'menu-item-type' => 'custom',
[443] Fix | Delete
'menu-item-title' => '',
[444] Fix | Delete
'menu-item-url' => '',
[445] Fix | Delete
'menu-item-description' => '',
[446] Fix | Delete
'menu-item-attr-title' => '',
[447] Fix | Delete
'menu-item-target' => '',
[448] Fix | Delete
'menu-item-classes' => '',
[449] Fix | Delete
'menu-item-xfn' => '',
[450] Fix | Delete
'menu-item-status' => '',
[451] Fix | Delete
'menu-item-post-date' => '',
[452] Fix | Delete
'menu-item-post-date-gmt' => '',
[453] Fix | Delete
);
[454] Fix | Delete
[455] Fix | Delete
$args = wp_parse_args( $menu_item_data, $defaults );
[456] Fix | Delete
[457] Fix | Delete
if ( 0 == $menu_id ) {
[458] Fix | Delete
$args['menu-item-position'] = 1;
[459] Fix | Delete
} elseif ( 0 == (int) $args['menu-item-position'] ) {
[460] Fix | Delete
$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
[461] Fix | Delete
$last_item = array_pop( $menu_items );
[462] Fix | Delete
$args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;
[466] Fix | Delete
[467] Fix | Delete
if ( 'custom' === $args['menu-item-type'] ) {
[468] Fix | Delete
// If custom menu item, trim the URL.
[469] Fix | Delete
$args['menu-item-url'] = trim( $args['menu-item-url'] );
[470] Fix | Delete
} else {
[471] Fix | Delete
/*
[472] Fix | Delete
* If non-custom menu item, then:
[473] Fix | Delete
* - use the original object's URL.
[474] Fix | Delete
* - blank default title to sync with the original object's title.
[475] Fix | Delete
*/
[476] Fix | Delete
[477] Fix | Delete
$args['menu-item-url'] = '';
[478] Fix | Delete
[479] Fix | Delete
$original_title = '';
[480] Fix | Delete
if ( 'taxonomy' === $args['menu-item-type'] ) {
[481] Fix | Delete
$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
[482] Fix | Delete
$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
[483] Fix | Delete
} elseif ( 'post_type' === $args['menu-item-type'] ) {
[484] Fix | Delete
[485] Fix | Delete
$original_object = get_post( $args['menu-item-object-id'] );
[486] Fix | Delete
$original_parent = (int) $original_object->post_parent;
[487] Fix | Delete
$original_title = $original_object->post_title;
[488] Fix | Delete
} elseif ( 'post_type_archive' === $args['menu-item-type'] ) {
[489] Fix | Delete
$original_object = get_post_type_object( $args['menu-item-object'] );
[490] Fix | Delete
if ( $original_object ) {
[491] Fix | Delete
$original_title = $original_object->labels->archives;
[492] Fix | Delete
}
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
if ( wp_unslash( $args['menu-item-title'] ) === wp_specialchars_decode( $original_title ) ) {
[496] Fix | Delete
$args['menu-item-title'] = '';
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function