Make WordPress Core

Ticket #38013: 38013.1.diff

File 38013.1.diff, 6.6 KB (added by westonruter, 9 years ago)
  • src/wp-admin/js/customize-nav-menus.js

    diff --git src/wp-admin/js/customize-nav-menus.js src/wp-admin/js/customize-nav-menus.js
    index 6dcdadc..1ca65ae 100644
     
    104104                                deferred.resolve( response );
    105105                                api.Menus.insertedAutoDrafts.push( response.post_id );
    106106                                api( 'nav_menus_created_posts' ).set( _.clone( api.Menus.insertedAutoDrafts ) );
     107
     108                                if ( 'page' === params.post_type ) {
     109
     110                                        // Activate static front page controls as this could be the first page created.
     111                                        _.each( [ 'show_on_front', 'page_on_front', 'page_for_posts' ], function ( controlId ) {
     112                                                var control = api.control( controlId );
     113                                                if ( control ) {
     114                                                        control.activate();
     115                                                }
     116                                        } );
     117
     118                                        // Add new page to dropdown-pages controls.
     119                                        api.control.each( function( control ) {
     120                                                if ( 'dropdown-pages' === control.params.type ) {
     121                                                        control.container.find( 'select:first' ).append( new Option( params.post_title, response.post_id ) );
     122                                                }
     123                                        } );
     124                                }
    107125                        }
    108126                } );
    109127
  • src/wp-includes/class-wp-customize-control.php

    diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php
    index 3f4877f..f6c0076 100644
    class WP_Customize_Control { 
    533533                                        <span class="description customize-control-description"><?php echo $this->description; ?></span>
    534534                                <?php endif; ?>
    535535
    536                                 <?php $dropdown = wp_dropdown_pages(
     536                                <?php
     537                                $dropdown_name = '_customize-dropdown-pages-' . $this->id;
     538                                $show_option_none = __( '&mdash; Select &mdash;' );
     539                                $option_none_value = '0';
     540                                $dropdown = wp_dropdown_pages(
    537541                                        array(
    538                                                 'name'              => '_customize-dropdown-pages-' . $this->id,
     542                                                'name'              => $dropdown_name,
    539543                                                'echo'              => 0,
    540                                                 'show_option_none'  => __( '&mdash; Select &mdash;' ),
    541                                                 'option_none_value' => '0',
     544                                                'show_option_none'  => $show_option_none,
     545                                                'option_none_value' => $option_none_value,
    542546                                                'selected'          => $this->value(),
    543547                                        )
    544548                                );
     549                                if ( empty( $dropdown ) ) {
     550                                        $dropdown = sprintf( '<select name="%s">', esc_attr( $dropdown_name ) );
     551                                        $dropdown .= sprintf( '<option value="%s">%s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
     552                                        $dropdown .= '</select>';
     553                                }
    545554
    546555                                // Hackily add in the data link parameter.
    547556                                $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index 668989b..fb54baf 100644
    final class WP_Customize_Manager { 
    22552255                }
    22562256
    22572257                /* Static Front Page */
    2258                 // #WP19627
    2259 
    2260                 // Replicate behavior from options-reading.php and hide front page options if there are no pages
    2261                 if ( get_pages() ) {
    2262                         $this->add_section( 'static_front_page', array(
    2263                                 'title'          => __( 'Static Front Page' ),
    2264                         //      'theme_supports' => 'static-front-page',
    2265                                 'priority'       => 120,
    2266                                 'description'    => __( 'Your theme supports a static front page.' ),
    2267                         ) );
     2258                // See also https://core.trac.wordpress.org/ticket/19627 which introduces the the static-front-page theme_support.
    22682259
    2269                         $this->add_setting( 'show_on_front', array(
    2270                                 'default'        => get_option( 'show_on_front' ),
    2271                                 'capability'     => 'manage_options',
    2272                                 'type'           => 'option',
    2273                         //      'theme_supports' => 'static-front-page',
    2274                         ) );
     2260                // Replicate behavior from options-reading.php.
     2261                $this->add_section( 'static_front_page', array(
     2262                        'title' => __( 'Static Front Page' ),
     2263                        'priority' => 120,
     2264                        'description' => __( 'Your theme supports a static front page.' ),
     2265                ) );
    22752266
    2276                         $this->add_control( 'show_on_front', array(
    2277                                 'label'   => __( 'Front page displays' ),
    2278                                 'section' => 'static_front_page',
    2279                                 'type'    => 'radio',
    2280                                 'choices' => array(
    2281                                         'posts' => __( 'Your latest posts' ),
    2282                                         'page'  => __( 'A static page' ),
    2283                                 ),
    2284                         ) );
     2267                $this->add_setting( 'show_on_front', array(
     2268                        'default' => get_option( 'show_on_front' ),
     2269                        'capability' => 'manage_options',
     2270                        'type' => 'option',
     2271                ) );
    22852272
    2286                         $this->add_setting( 'page_on_front', array(
    2287                                 'type'       => 'option',
    2288                                 'capability' => 'manage_options',
    2289                         //      'theme_supports' => 'static-front-page',
    2290                         ) );
     2273                $this->add_control( 'show_on_front', array(
     2274                        'label' => __( 'Front page displays' ),
     2275                        'section' => 'static_front_page',
     2276                        'type'=> 'radio',
     2277                        'choices' => array(
     2278                                'posts' => __( 'Your latest posts' ),
     2279                                'page'  => __( 'A static page' ),
     2280                        ),
     2281                        'active_callback' => array( $this, 'has_published_pages' ),
     2282                ) );
    22912283
    2292                         $this->add_control( 'page_on_front', array(
    2293                                 'label'      => __( 'Front page' ),
    2294                                 'section'    => 'static_front_page',
    2295                                 'type'       => 'dropdown-pages',
    2296                         ) );
     2284                $this->add_setting( 'page_on_front', array(
     2285                        'type'       => 'option',
     2286                        'capability' => 'manage_options',
     2287                ) );
    22972288
    2298                         $this->add_setting( 'page_for_posts', array(
    2299                                 'type'           => 'option',
    2300                                 'capability'     => 'manage_options',
    2301                         //      'theme_supports' => 'static-front-page',
    2302                         ) );
     2289                $this->add_control( 'page_on_front', array(
     2290                        'label' => __( 'Front page' ),
     2291                        'section' => 'static_front_page',
     2292                        'type' => 'dropdown-pages',
     2293                        'active_callback' => array( $this, 'has_published_pages' ),
     2294                ) );
    23032295
    2304                         $this->add_control( 'page_for_posts', array(
    2305                                 'label'      => __( 'Posts page' ),
    2306                                 'section'    => 'static_front_page',
    2307                                 'type'       => 'dropdown-pages',
    2308                         ) );
     2296                $this->add_setting( 'page_for_posts', array(
     2297                        'type'           => 'option',
     2298                        'capability'     => 'manage_options',
     2299                //      'theme_supports' => 'static-front-page',
     2300                ) );
     2301
     2302                $this->add_control( 'page_for_posts', array(
     2303                        'label' => __( 'Posts page' ),
     2304                        'section' => 'static_front_page',
     2305                        'type' => 'dropdown-pages',
     2306                        'active_callback' => array( $this, 'has_published_pages' ),
     2307                ) );
     2308        }
     2309
     2310        /**
     2311         * Return whether there are published pages.
     2312         *
     2313         * Used as active callback for static front page section and controls.
     2314         *
     2315         * @access private
     2316         * @since 4.7.0
     2317         *
     2318         * @returns bool Whether there are published (or to be published) pages.
     2319         */
     2320        public function has_published_pages() {
     2321
     2322                $setting = $this->get_setting( 'nav_menus_created_posts' );
     2323                if ( $setting ) {
     2324                        foreach ( $setting->value() as $post_id ) {
     2325                                if ( get_post_type( $post_id ) ) {
     2326                                        return true;
     2327                                }
     2328                        }
    23092329                }
     2330
     2331                return 0 !== count( get_pages() );
    23102332        }
    23112333
    23122334        /**