mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 11:44:33 +00:00
Customizer: Implement indicators for invalid nav menu items.
The same indicator on the nav menus admin page is now present for nav menu items in the Customizer. When a menu item is present for a post type that is no longer registered, the menu item will appear with the indicator. Props kucrut, westonruter. Fixes #33665. git-svn-id: https://develop.svn.wordpress.org/trunk@35302 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -885,7 +885,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
'status' => 'publish',
|
||||
'original_title' => '',
|
||||
'nav_menu_term_id' => 0, // This will be supplied as the $menu_id arg for wp_update_nav_menu_item().
|
||||
// @todo also expose invalid?
|
||||
'_invalid' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -1144,6 +1144,14 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset( $this->value['_invalid'] ) ) {
|
||||
$this->value['_invalid'] = (
|
||||
( 'post_type' === $this->value['type'] && ! post_type_exists( $this->value['object'] ) )
|
||||
||
|
||||
( 'taxonomy' === $this->value['type'] && ! taxonomy_exists( $this->value['object'] ) )
|
||||
);
|
||||
}
|
||||
|
||||
// Remove remaining properties available on a setup nav_menu_item post object which aren't relevant to the setting value.
|
||||
$irrelevant_properties = array(
|
||||
'ID',
|
||||
@@ -1246,6 +1254,8 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
$should_remove = (
|
||||
false === $this_item
|
||||
||
|
||||
true === $this_item['_invalid']
|
||||
||
|
||||
(
|
||||
$this->original_nav_menu_term_id === $menu->term_id
|
||||
&&
|
||||
@@ -1417,6 +1427,7 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
'status' => 'publish',
|
||||
'original_title' => '',
|
||||
'nav_menu_term_id' => 0,
|
||||
'_invalid' => false,
|
||||
);
|
||||
$menu_item_value = array_merge( $default, $menu_item_value );
|
||||
$menu_item_value = wp_array_slice_assoc( $menu_item_value, array_keys( $default ) );
|
||||
@@ -1449,6 +1460,8 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
|
||||
$menu_item_value['status'] = 'publish';
|
||||
}
|
||||
|
||||
$menu_item_value['_invalid'] = (bool) $menu_item_value['_invalid'];
|
||||
|
||||
/** This filter is documented in wp-includes/class-wp-customize-setting.php */
|
||||
return apply_filters( "customize_sanitize_{$this->id}", $menu_item_value, $this );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user