WordPress 4.4
[autoinstalls/wordpress.git] / wp-includes / class-wp-customize-nav-menus.php
index fb1633bf93b5d98b6ae9e2c396cd4684447434f0..f6be2094061935a4fcf4869bb08c93082a7dff54 100644 (file)
@@ -107,7 +107,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 +122,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(
@@ -325,8 +336,8 @@ final class WP_Customize_Nav_Menus {
                                '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 slug */
+                               'menuLocation'      => _x( '(Currently set to: %s)', 'menu' ),
                                'menuNameLabel'     => __( 'Menu Name' ),
                                'itemAdded'         => __( 'Menu item added' ),
                                'itemDeleted'       => __( 'Menu item deleted' ),
@@ -342,8 +353,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.' ),
@@ -464,10 +473,14 @@ 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   = '<p>' . 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 ) );
+               if ( 1 == $num_locations ) {
+                       $description = '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' );
+               } else {
+                       $description = '<p>' . 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 ) );
+               }
                $description  .= '</p><p>' . __( 'You can also place menus in widget areas with the Custom Menu widget.' ) . '</p>';
 
                $this->manager->add_section( 'menu_locations', array(
@@ -611,7 +624,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 +638,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,
                                );
@@ -662,7 +675,7 @@ final class WP_Customize_Nav_Menus {
                                                <span class="item-title" aria-hidden="true">
                                                        <span class="menu-item-title<# if ( ! data.title ) { #> no-title<# } #>">{{ data.title || wp.customize.Menus.data.l10n.untitled }}</span>
                                                </span>
-                                               <button type="button" class="not-a-button item-add">
+                                               <button type="button" class="button-link item-add">
                                                        <span class="screen-reader-text"><?php
                                                                /* translators: 1: Title of a menu item, 2: Type of a menu item */
                                                                printf( __( 'Add to menu: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.type_label }}' );
@@ -725,7 +738,7 @@ final class WP_Customize_Nav_Menus {
                        <div id="new-custom-menu-item" class="accordion-section">
                                <h4 class="accordion-section-title" role="presentation">
                                        <?php _e( 'Custom Links' ); ?>
-                                       <button type="button" class="not-a-button" aria-expanded="false">
+                                       <button type="button" class="button-link" aria-expanded="false">
                                                <span class="screen-reader-text"><?php _e( 'Toggle section: Custom Links' ); ?></span>
                                                <span class="toggle-indicator" aria-hidden="true"></span>
                                        </button>
@@ -762,7 +775,7 @@ final class WP_Customize_Nav_Menus {
                                                <?php echo esc_html( $available_item_type['title'] ); ?>
                                                <span class="spinner"></span>
                                                <span class="no-items"><?php _e( 'No items' ); ?></span>
-                                               <button type="button" class="not-a-button" aria-expanded="false">
+                                               <button type="button" class="button-link" aria-expanded="false">
                                                        <span class="screen-reader-text"><?php
                                                        /* translators: %s: Title of a section with menu items */
                                                        printf( __( 'Toggle section: %s' ), esc_html( $available_item_type['title'] ) ); ?></span>
@@ -930,7 +943,7 @@ final class WP_Customize_Nav_Menus {
                        'renderQueryVar'        => self::RENDER_QUERY_VAR,
                        'renderNonceValue'      => wp_create_nonce( self::RENDER_AJAX_ACTION ),
                        'renderNoncePostKey'    => self::RENDER_NONCE_POST_KEY,
-                       'requestUri'            => '/',
+                       'requestUri'            => empty( $_SERVER['REQUEST_URI'] ) ? home_url( '/' ) : esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
                        'theme'                 => array(
                                'stylesheet' => $this->manager->get_stylesheet(),
                                'active'     => $this->manager->is_theme_active(),
@@ -939,10 +952,6 @@ final class WP_Customize_Nav_Menus {
                        'navMenuInstanceArgs'   => $this->preview_nav_menu_instance_args,
                );
 
-               if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
-                       $exports['requestUri'] = esc_url_raw( home_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
-               }
-
                printf( '<script>var _wpCustomizePreviewNavMenusExports = %s;</script>', wp_json_encode( $exports ) );
        }