X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/53f4633144ed68c8b8fb5861f992b5489894a940..607b7e02d77e7326161e8ec15639052d2040f745:/wp-includes/class-wp-customize-nav-menus.php diff --git a/wp-includes/class-wp-customize-nav-menus.php b/wp-includes/class-wp-customize-nav-menus.php index fb1633bf..f9832a69 100644 --- a/wp-includes/class-wp-customize-nav-menus.php +++ b/wp-includes/class-wp-customize-nav-menus.php @@ -48,6 +48,12 @@ final class WP_Customize_Nav_Menus { $this->previewed_menus = array(); $this->manager = $manager; + // Skip useless hooks when the user can't manage nav menus anyway. + if ( ! current_user_can( 'edit_theme_options' ) ) { + return; + } + + add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) ); add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) ); add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); @@ -60,6 +66,23 @@ final class WP_Customize_Nav_Menus { add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) ); add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); + + // Selective Refresh partials. + add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 ); + } + + /** + * Adds a nonce for customizing menus. + * + * @since 4.5.0 + * @access public + * + * @param array $nonces Array of nonces. + * @return array $nonces Modified array of nonces. + */ + public function filter_nonces( $nonces ) { + $nonces['customize-menus'] = wp_create_nonce( 'customize-menus' ); + return $nonces; } /** @@ -107,7 +130,8 @@ final class WP_Customize_Nav_Menus { $items = array(); if ( 'post_type' === $type ) { - if ( ! get_post_type_object( $object ) ) { + $post_type = get_post_type_object( $object ); + if ( ! $post_type ) { return new WP_Error( 'nav_menus_invalid_post_type' ); } @@ -121,6 +145,16 @@ final class WP_Customize_Nav_Menus { 'object' => '', 'url' => home_url(), ); + } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) { + // Add a post type archive link. + $items[] = array( + 'id' => $object . '-archive', + 'title' => $post_type->labels->archives, + 'type' => 'post_type_archive', + 'type_label' => __( 'Post Type Archive' ), + 'object' => $object, + 'url' => get_post_type_archive_link( $object ), + ); } $posts = get_posts( array( @@ -177,7 +211,7 @@ final class WP_Customize_Nav_Menus { } /** - * Filter the available menu items. + * Filters the available menu items. * * @since 4.3.0 * @@ -300,6 +334,16 @@ final class WP_Customize_Nav_Menus { } } + /** + * Filters the available menu items during a search request. + * + * @since 4.5.0 + * + * @param array $items The array of menu items. + * @param array $args Includes 'pagenum' and 's' (search) arguments. + */ + $items = apply_filters( 'customize_nav_menu_searched_items', $items, $args ); + return $items; } @@ -318,15 +362,14 @@ final class WP_Customize_Nav_Menus { // Pass data to JS. $settings = array( - 'nonce' => wp_create_nonce( 'customize-menus' ), 'allMenus' => wp_get_nav_menus(), 'itemTypes' => $this->available_item_types(), 'l10n' => array( 'untitled' => _x( '(no label)', 'missing menu item navigation label' ), 'unnamed' => _x( '(unnamed)', 'Missing menu name.' ), 'custom_label' => __( 'Custom Link' ), - /* translators: %s: Current menu location */ - 'menuLocation' => __( '(Currently set to: %s)' ), + /* translators: %s: menu location */ + 'menuLocation' => _x( '(Currently set to: %s)', 'menu' ), 'menuNameLabel' => __( 'Menu Name' ), 'itemAdded' => __( 'Menu item added' ), 'itemDeleted' => __( 'Menu item deleted' ), @@ -342,8 +385,6 @@ final class WP_Customize_Nav_Menus { 'invalidTitleTpl' => __( '%s (Invalid)' ), /* translators: %s: title of menu item in draft status */ 'pendingTitleTpl' => __( '%s (Pending)' ), - 'taxonomyTermLabel' => __( 'Taxonomy' ), - 'postTypeLabel' => __( 'Post Type' ), 'itemsFound' => __( 'Number of items found: %d' ), 'itemsFoundMore' => __( 'Additional items found: %d' ), 'itemsLoadingMore' => __( 'Loading more results... please wait.' ), @@ -352,12 +393,13 @@ final class WP_Customize_Nav_Menus { 'reorderLabelOn' => esc_attr__( 'Reorder menu items' ), 'reorderLabelOff' => esc_attr__( 'Close reorder mode' ), ), - 'menuItemTransport' => 'postMessage', + 'settingTransport' => 'postMessage', 'phpIntMax' => PHP_INT_MAX, 'defaultSettingValues' => array( 'nav_menu' => $temp_nav_menu_setting->default, 'nav_menu_item' => $temp_nav_menu_item_setting->default, ), + 'locationSlugMappedToName' => get_registered_nav_menus(), ); $data = sprintf( 'var _wpCustomizeNavMenusSettings = %s;', wp_json_encode( $settings ) ); @@ -386,7 +428,7 @@ final class WP_Customize_Nav_Menus { } /** - * Filter a dynamic setting's constructor args. + * Filters a dynamic setting's constructor args. * * For a dynamic setting to be registered, this filter must be employed * to override the default false value with an array of args to pass to @@ -402,11 +444,13 @@ final class WP_Customize_Nav_Menus { public function filter_dynamic_setting_args( $setting_args, $setting_id ) { if ( preg_match( WP_Customize_Nav_Menu_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( - 'type' => WP_Customize_Nav_Menu_Setting::TYPE, + 'type' => WP_Customize_Nav_Menu_Setting::TYPE, + 'transport' => 'postMessage', ); } elseif ( preg_match( WP_Customize_Nav_Menu_Item_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( - 'type' => WP_Customize_Nav_Menu_Item_Setting::TYPE, + 'type' => WP_Customize_Nav_Menu_Item_Setting::TYPE, + 'transport' => 'postMessage', ); } return $setting_args; @@ -452,6 +496,7 @@ final class WP_Customize_Nav_Menus { // Create a panel for Menus. $description = '

' . __( 'This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.' ) . '

'; if ( current_theme_supports( 'widgets' ) ) { + /* translators: URL to the widgets panel of the customizer */ $description .= '

' . sprintf( __( 'Menus can be displayed in locations defined by your theme or in widget areas by adding a “Custom Menu” widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '

'; } else { $description .= '

' . __( 'Menus can be displayed in locations defined by your theme.' ) . '

'; @@ -464,11 +509,19 @@ final class WP_Customize_Nav_Menus { ) ) ); $menus = wp_get_nav_menus(); - // Menu loactions. + // Menu locations. $locations = get_registered_nav_menus(); $num_locations = count( array_keys( $locations ) ); - $description = '

' . sprintf( _n( 'Your theme contains %s menu location. Select which menu you would like to use.', 'Your theme contains %s menu locations. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ); - $description .= '

' . __( 'You can also place menus in widget areas with the Custom Menu widget.' ) . '

'; + if ( 1 == $num_locations ) { + $description = '

' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '

'; + } else { + /* translators: %s: number of menu locations */ + $description = '

' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '

'; + } + if ( current_theme_supports( 'widgets' ) ) { + /* translators: URL to the widgets panel of the customizer */ + $description .= '

' . sprintf( __( 'You can also place menus in widget areas with the “Custom Menu” widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '

'; + } $this->manager->add_section( 'menu_locations', array( 'title' => __( 'Menu Locations' ), @@ -521,7 +574,9 @@ final class WP_Customize_Nav_Menus { ) ) ); $nav_menu_setting_id = 'nav_menu[' . $menu_id . ']'; - $this->manager->add_setting( new WP_Customize_Nav_Menu_Setting( $this->manager, $nav_menu_setting_id ) ); + $this->manager->add_setting( new WP_Customize_Nav_Menu_Setting( $this->manager, $nav_menu_setting_id, array( + 'transport' => 'postMessage', + ) ) ); // Add the menu contents. $menu_items = (array) wp_get_nav_menu_items( $menu_id ); @@ -534,7 +589,8 @@ final class WP_Customize_Nav_Menus { $value = (array) $item; $value['nav_menu_term_id'] = $menu_id; $this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array( - 'value' => $value, + 'value' => $value, + 'transport' => 'postMessage', ) ) ); // Create a control for each menu item. @@ -555,28 +611,20 @@ final class WP_Customize_Nav_Menus { 'priority' => 999, ) ) ); - $this->manager->add_setting( 'new_menu_name', array( - 'type' => 'new_menu', - 'default' => '', - 'transport' => 'postMessage', - ) ); - $this->manager->add_control( 'new_menu_name', array( 'label' => '', 'section' => 'add_menu', 'type' => 'text', + 'settings' => array(), 'input_attrs' => array( 'class' => 'menu-name-field', 'placeholder' => __( 'New menu name' ), ), ) ); - $this->manager->add_setting( 'create_new_menu', array( - 'type' => 'new_menu', - ) ); - $this->manager->add_control( new WP_Customize_New_Menu_Control( $this->manager, 'create_new_menu', array( - 'section' => 'add_menu', + 'section' => 'add_menu', + 'settings' => array(), ) ) ); } @@ -611,7 +659,7 @@ final class WP_Customize_Nav_Menus { if ( $post_types ) { foreach ( $post_types as $slug => $post_type ) { $item_types[] = array( - 'title' => $post_type->labels->singular_name, + 'title' => $post_type->labels->name, 'type' => 'post_type', 'object' => $post_type->name, ); @@ -625,7 +673,7 @@ final class WP_Customize_Nav_Menus { continue; } $item_types[] = array( - 'title' => $taxonomy->labels->singular_name, + 'title' => $taxonomy->labels->name, 'type' => 'taxonomy', 'object' => $taxonomy->name, ); @@ -633,7 +681,7 @@ final class WP_Customize_Nav_Menus { } /** - * Filter the available menu item types. + * Filters the available menu item types. * * @since 4.3.0 * @@ -662,7 +710,7 @@ final class WP_Customize_Nav_Menus { -
-
+
- -

@@ -762,7 +806,7 @@ final class WP_Customize_Nav_Menus { -