WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/25/2016 06:30:27 AM (5 years ago)
Author:
westonruter
Message:

Customize: Allow page stubs to be created via dropdown-pages controls in the Static Front Page section.

This ability was previously added to nav menus via the available page items panel. The "Add New Page" button only appears when the allow_addition control param is supplied as true. Code is adapted from the Customize Posts feature plugin.

Props celloexpressions, westonruter.
See #38013, #34923.
Fixes #38164.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-control.php

    r38624 r38906  
    114114     */
    115115    public $input_attrs = array();
     116
     117    /**
     118     * Show UI for adding new content, currently only used for the dropdown-pages control.
     119     *
     120     * @since 4.7.0
     121     * @access public
     122     * @var array
     123     */
     124    public $allow_addition = false;
    116125
    117126    /**
     
    297306        $this->json['description'] = $this->description;
    298307        $this->json['instanceNumber'] = $this->instance_number;
     308
     309        if ( 'dropdown-pages' === $this->type ) {
     310            $this->json['allow_addition'] = $this->allow_addition;
     311        }
    299312    }
    300313
     
    555568                // Hackily add in the data link parameter.
    556569                $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
     570
     571                // Even more hacikly add auto-draft page stubs.
     572                // @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. See <https://github.com/xwp/wp-customize-posts/pull/250>.
     573                $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
     574                if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
     575                    $auto_draft_page_options = '';
     576                    foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
     577                        $post = get_post( $auto_draft_page_id );
     578                        if ( $post && 'page' === $post->post_type ) {
     579                            $auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) );
     580                        }
     581                    }
     582                    if ( $auto_draft_page_options ) {
     583                        $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
     584                    }
     585                }
     586
    557587                echo $dropdown;
    558588                ?>
    559589                </label>
    560                 <?php
     590                <?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
     591                    <button type="button" class="button add-new-toggle"><?php echo get_post_type_object( 'page' )->labels->add_new_item; ?></button>
     592                    <div class="new-content-item">
     593                        <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
     594                        <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title&hellip;' ); ?>">
     595                        <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
     596                    </div>
     597                <?php endif;
    561598                break;
    562599            default:
Note: See TracChangeset for help on using the changeset viewer.