*/
public $input_attrs = array();
+ /**
+ * Show UI for adding new content, currently only used for the dropdown-pages control.
+ *
+ * @since 4.7.0
+ * @access public
+ * @var bool
+ */
+ public $allow_addition = false;
+
/**
* @deprecated It is better to just call the json() method
* @access public
$this->json['label'] = $this->label;
$this->json['description'] = $this->description;
$this->json['instanceNumber'] = $this->instance_number;
+
+ if ( 'dropdown-pages' === $this->type ) {
+ $this->json['allow_addition'] = $this->allow_addition;
+ }
}
/**
*
* @param WP_Customize_Control $this WP_Customize_Control instance.
*/
- do_action( 'customize_render_control_' . $this->id, $this );
+ do_action( "customize_render_control_{$this->id}", $this );
$this->render();
}
/**
* Render the control's content.
*
- * Allows the content to be overriden without having to rewrite the wrapper in `$this::render()`.
+ * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
*
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
if ( ! empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
- <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
+ <textarea rows="5" <?php $this->input_attrs(); ?> <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
break;
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
- <?php $dropdown = wp_dropdown_pages(
+ <?php
+ $dropdown_name = '_customize-dropdown-pages-' . $this->id;
+ $show_option_none = __( '— Select —' );
+ $option_none_value = '0';
+ $dropdown = wp_dropdown_pages(
array(
- 'name' => '_customize-dropdown-pages-' . $this->id,
+ 'name' => $dropdown_name,
'echo' => 0,
- 'show_option_none' => __( '— Select —' ),
- 'option_none_value' => '0',
+ 'show_option_none' => $show_option_none,
+ 'option_none_value' => $option_none_value,
'selected' => $this->value(),
)
);
+ if ( empty( $dropdown ) ) {
+ $dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) );
+ $dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
+ $dropdown .= '</select>';
+ }
// Hackily add in the data link parameter.
$dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
+
+ // Even more hacikly add auto-draft page stubs.
+ // @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>.
+ $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
+ if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
+ $auto_draft_page_options = '';
+ foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
+ $post = get_post( $auto_draft_page_id );
+ if ( $post && 'page' === $post->post_type ) {
+ $auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) );
+ }
+ }
+ if ( $auto_draft_page_options ) {
+ $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
+ }
+ }
+
echo $dropdown;
?>
</label>
- <?php
+ <?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
+ <button type="button" class="button-link add-new-toggle"><?php
+ /* translators: %s: add new page label */
+ printf( __( '+ %s' ), get_post_type_object( 'page' )->labels->add_new_item );
+ ?></button>
+ <div class="new-content-item">
+ <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
+ <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title…' ); ?>">
+ <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
+ </div>
+ <?php endif;
break;
default:
?>
/** WP_Customize_Background_Image_Control class */
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
+/** WP_Customize_Background_Position_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
+
/** WP_Customize_Cropped_Image_Control class */
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );