~canonical-sysadmins/wordpress/4.8

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-customize-control.php

  • Committer: Haw Loeung
  • Date: 2016-12-13 06:56:21 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: haw.loeung@canonical.com-20161213065621-8tcu7u7vlxgs2s81
Merge WP4.7 from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
        public $input_attrs = array();
116
116
 
117
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 bool
 
123
         */
 
124
        public $allow_addition = false;
 
125
 
 
126
        /**
118
127
         * @deprecated It is better to just call the json() method
119
128
         * @access public
120
129
         * @var array
296
305
                $this->json['label'] = $this->label;
297
306
                $this->json['description'] = $this->description;
298
307
                $this->json['instanceNumber'] = $this->instance_number;
 
308
 
 
309
                if ( 'dropdown-pages' === $this->type ) {
 
310
                        $this->json['allow_addition'] = $this->allow_addition;
 
311
                }
299
312
        }
300
313
 
301
314
        /**
383
396
                 *
384
397
                 * @param WP_Customize_Control $this WP_Customize_Control instance.
385
398
                 */
386
 
                do_action( 'customize_render_control_' . $this->id, $this );
 
399
                do_action( "customize_render_control_{$this->id}", $this );
387
400
 
388
401
                $this->render();
389
402
        }
444
457
        /**
445
458
         * Render the control's content.
446
459
         *
447
 
         * Allows the content to be overriden without having to rewrite the wrapper in `$this::render()`.
 
460
         * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
448
461
         *
449
462
         * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
450
463
         * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
519
532
                                        if ( ! empty( $this->description ) ) : ?>
520
533
                                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
521
534
                                        <?php endif; ?>
522
 
                                        <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
 
535
                                        <textarea rows="5" <?php $this->input_attrs(); ?> <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
523
536
                                </label>
524
537
                                <?php
525
538
                                break;
533
546
                                        <span class="description customize-control-description"><?php echo $this->description; ?></span>
534
547
                                <?php endif; ?>
535
548
 
536
 
                                <?php $dropdown = wp_dropdown_pages(
 
549
                                <?php
 
550
                                $dropdown_name = '_customize-dropdown-pages-' . $this->id;
 
551
                                $show_option_none = __( '&mdash; Select &mdash;' );
 
552
                                $option_none_value = '0';
 
553
                                $dropdown = wp_dropdown_pages(
537
554
                                        array(
538
 
                                                'name'              => '_customize-dropdown-pages-' . $this->id,
 
555
                                                'name'              => $dropdown_name,
539
556
                                                'echo'              => 0,
540
 
                                                'show_option_none'  => __( '&mdash; Select &mdash;' ),
541
 
                                                'option_none_value' => '0',
 
557
                                                'show_option_none'  => $show_option_none,
 
558
                                                'option_none_value' => $option_none_value,
542
559
                                                'selected'          => $this->value(),
543
560
                                        )
544
561
                                );
 
562
                                if ( empty( $dropdown ) ) {
 
563
                                        $dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) );
 
564
                                        $dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
 
565
                                        $dropdown .= '</select>';
 
566
                                }
545
567
 
546
568
                                // Hackily add in the data link parameter.
547
569
                                $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
 
548
587
                                echo $dropdown;
549
588
                                ?>
550
589
                                </label>
551
 
                                <?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-link add-new-toggle"><?php
 
592
                                                /* translators: %s: add new page label */
 
593
                                                printf( __( '+ %s' ), get_post_type_object( 'page' )->labels->add_new_item );
 
594
                                        ?></button>
 
595
                                        <div class="new-content-item">
 
596
                                                <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
 
597
                                                <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title&hellip;' ); ?>">
 
598
                                                <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
 
599
                                        </div>
 
600
                                <?php endif;
552
601
                                break;
553
602
                        default:
554
603
                                ?>
614
663
/** WP_Customize_Background_Image_Control class */
615
664
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
616
665
 
 
666
/** WP_Customize_Background_Position_Control class */
 
667
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
 
668
 
617
669
/** WP_Customize_Cropped_Image_Control class */
618
670
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );
619
671