~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-09-05 20:58:06 UTC
  • mfrom: (1.2.38)
  • Revision ID: package-import@ubuntu.com-20140905205806-e4h6dkg4190n0svf
Tags: 4.0+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        public $label = '';
55
55
 
56
56
        /**
 
57
         * @access public
 
58
         * @var string
 
59
         */
 
60
        public $description = '';
 
61
 
 
62
        /**
57
63
         * @todo: Remove choices
58
64
         *
59
65
         * @access public
65
71
         * @access public
66
72
         * @var array
67
73
         */
 
74
        public $input_attrs = array();
 
75
 
 
76
        /**
 
77
         * @access public
 
78
         * @var array
 
79
         */
68
80
        public $json = array();
69
81
 
70
82
        /**
73
85
         */
74
86
        public $type = 'text';
75
87
 
 
88
        /**
 
89
         * Callback.
 
90
         *
 
91
         * @since 4.0.0
 
92
         * @access public
 
93
         *
 
94
         * @see WP_Customize_Control::active()
 
95
         *
 
96
         * @var callable Callback is called with one argument, the instance of
 
97
         *               WP_Customize_Control, and returns bool to indicate whether
 
98
         *               the control is active (such as it relates to the URL
 
99
         *               currently being previewed).
 
100
         */
 
101
        public $active_callback = '';
76
102
 
77
103
        /**
78
104
         * Constructor.
87
113
         * @param string $id
88
114
         * @param array $args
89
115
         */
90
 
        function __construct( $manager, $id, $args = array() ) {
 
116
        public function __construct( $manager, $id, $args = array() ) {
91
117
                $keys = array_keys( get_object_vars( $this ) );
92
118
                foreach ( $keys as $key ) {
93
 
                        if ( isset( $args[ $key ] ) )
 
119
                        if ( isset( $args[ $key ] ) ) {
94
120
                                $this->$key = $args[ $key ];
 
121
                        }
95
122
                }
96
123
 
97
124
                $this->manager = $manager;
98
125
                $this->id = $id;
 
126
                if ( empty( $this->active_callback ) ) {
 
127
                        $this->active_callback = array( $this, 'active_callback' );
 
128
                }
99
129
 
100
130
                // Process settings.
101
 
                if ( empty( $this->settings ) )
 
131
                if ( empty( $this->settings ) ) {
102
132
                        $this->settings = $id;
 
133
                }
103
134
 
104
135
                $settings = array();
105
136
                if ( is_array( $this->settings ) ) {
120
151
         */
121
152
        public function enqueue() {}
122
153
 
 
154
        /**
 
155
         * Check whether control is active to current customizer preview.
 
156
         *
 
157
         * @since 4.0.0
 
158
         * @access public
 
159
         *
 
160
         * @return bool Whether the control is active to the current preview.
 
161
         */
 
162
        public final function active() {
 
163
                $control = $this;
 
164
                $active = call_user_func( $this->active_callback, $this );
 
165
 
 
166
                /**
 
167
                 * Filter response of WP_Customize_Control::active().
 
168
                 *
 
169
                 * @since 4.0.0
 
170
                 *
 
171
                 * @param bool                 $active  Whether the Customizer control is active.
 
172
                 * @param WP_Customize_Control $control WP_Customize_Control instance.
 
173
                 */
 
174
                $active = apply_filters( 'customize_control_active', $active, $control );
 
175
 
 
176
                return $active;
 
177
        }
 
178
 
 
179
        /**
 
180
         * Default callback used when invoking WP_Customize_Control::active().
 
181
         *
 
182
         * Subclasses can override this with their specific logic, or they may
 
183
         * provide an 'active_callback' argument to the constructor.
 
184
         *
 
185
         * @since 4.0.0
 
186
         * @access public
 
187
         *
 
188
         * @return bool Always true.
 
189
         */
 
190
        public function active_callback() {
 
191
                return true;
 
192
        }
123
193
 
124
194
        /**
125
195
         * Fetch a setting's value.
131
201
         * @return mixed The requested setting's value, if the setting exists.
132
202
         */
133
203
        public final function value( $setting_key = 'default' ) {
134
 
                if ( isset( $this->settings[ $setting_key ] ) )
 
204
                if ( isset( $this->settings[ $setting_key ] ) ) {
135
205
                        return $this->settings[ $setting_key ]->value();
 
206
                }
136
207
        }
137
208
 
138
209
        /**
147
218
                }
148
219
 
149
220
                $this->json['type'] = $this->type;
 
221
                $this->json['active'] = $this->active();
150
222
        }
151
223
 
152
224
        /**
245
317
        }
246
318
 
247
319
        /**
 
320
         * Render the custom attributes for the control's input element.
 
321
         *
 
322
         * @since 4.0.0
 
323
         * @access public
 
324
         */
 
325
        public function input_attrs() {
 
326
                foreach( $this->input_attrs as $attr => $value ) {
 
327
                        echo $attr . '="' . esc_attr( $value ) . '" ';
 
328
                }
 
329
        }
 
330
 
 
331
        /**
248
332
         * Render the control's content.
249
333
         *
250
334
         * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
251
335
         *
252
 
         * Supports basic input types `text`, `checkbox`, `radio`, `select` and `dropdown-pages`.
 
336
         * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
 
337
         * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
253
338
         *
254
339
         * @since 3.4.0
255
340
         */
256
341
        protected function render_content() {
257
342
                switch( $this->type ) {
258
 
                        case 'text':
259
 
                                ?>
260
 
                                <label>
261
 
                                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
262
 
                                        <input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
263
 
                                </label>
264
 
                                <?php
265
 
                                break;
266
343
                        case 'checkbox':
267
344
                                ?>
268
345
                                <label>
269
346
                                        <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
270
347
                                        <?php echo esc_html( $this->label ); ?>
 
348
                                        <?php if ( ! empty( $this->description ) ) : ?>
 
349
                                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
350
                                        <?php endif; ?>
271
351
                                </label>
272
352
                                <?php
273
353
                                break;
277
357
 
278
358
                                $name = '_customize-radio-' . $this->id;
279
359
 
280
 
                                ?>
281
 
                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
282
 
                                <?php
 
360
                                if ( ! empty( $this->label ) ) : ?>
 
361
                                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
362
                                <?php endif;
 
363
                                if ( ! empty( $this->description ) ) : ?>
 
364
                                        <span class="description customize-control-description"><?php echo $this->description ; ?></span>
 
365
                                <?php endif;
 
366
 
283
367
                                foreach ( $this->choices as $value => $label ) :
284
368
                                        ?>
285
369
                                        <label>
295
379
 
296
380
                                ?>
297
381
                                <label>
298
 
                                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
382
                                        <?php if ( ! empty( $this->label ) ) : ?>
 
383
                                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
384
                                        <?php endif;
 
385
                                        if ( ! empty( $this->description ) ) : ?>
 
386
                                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
387
                                        <?php endif; ?>
 
388
 
299
389
                                        <select <?php $this->link(); ?>>
300
390
                                                <?php
301
391
                                                foreach ( $this->choices as $value => $label )
305
395
                                </label>
306
396
                                <?php
307
397
                                break;
 
398
                        case 'textarea':
 
399
                                ?>
 
400
                                <label>
 
401
                                        <?php if ( ! empty( $this->label ) ) : ?>
 
402
                                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
403
                                        <?php endif;
 
404
                                        if ( ! empty( $this->description ) ) : ?>
 
405
                                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
406
                                        <?php endif; ?>
 
407
                                        <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
 
408
                                </label>
 
409
                                <?php
 
410
                                break;
308
411
                        case 'dropdown-pages':
309
412
                                $dropdown = wp_dropdown_pages(
310
413
                                        array(
325
428
                                        $dropdown
326
429
                                );
327
430
                                break;
 
431
                        default:
 
432
                                ?>
 
433
                                <label>
 
434
                                        <?php if ( ! empty( $this->label ) ) : ?>
 
435
                                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
436
                                        <?php endif;
 
437
                                        if ( ! empty( $this->description ) ) : ?>
 
438
                                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
439
                                        <?php endif; ?>
 
440
                                        <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
 
441
                                </label>
 
442
                                <?php
 
443
                                break;
328
444
                }
329
445
        }
330
446
}
401
517
                // The input's value gets set by JS. Don't fill it.
402
518
                ?>
403
519
                <label>
404
 
                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
520
                        <?php if ( ! empty( $this->label ) ) : ?>
 
521
                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
522
                        <?php endif;
 
523
                        if ( ! empty( $this->description ) ) : ?>
 
524
                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
525
                        <?php endif; ?>
 
526
 
405
527
                        <div class="customize-control-content">
406
528
                                <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>"<?php echo $default_attr; ?> />
407
529
                        </div>
458
580
        public function render_content() {
459
581
                ?>
460
582
                <label>
461
 
                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
583
                        <?php if ( ! empty( $this->label ) ) : ?>
 
584
                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
585
                        <?php endif;
 
586
                        if ( ! empty( $this->description ) ) : ?>
 
587
                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
588
                        <?php endif; ?>
462
589
                        <div>
463
590
                                <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
464
591
                                <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
540
667
 
541
668
                ?>
542
669
                <div class="customize-image-picker">
543
 
                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
670
                        <?php if ( ! empty( $this->label ) ) : ?>
 
671
                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
 
672
                        <?php endif;
 
673
                        if ( ! empty( $this->description ) ) : ?>
 
674
                                <span class="description customize-control-description"><?php echo $this->description; ?></span>
 
675
                        <?php endif; ?>
544
676
 
545
677
                        <div class="customize-control-content">
546
678
                                <div class="dropdown preview-thumbnail" tabindex="0">
610
742
         */
611
743
        public function tab_upload_new() {
612
744
                if ( ! _device_can_upload() ) {
613
 
                        echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://wordpress.org/mobile/' ) . '</p>';
 
745
                        echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'http://apps.wordpress.org/' ) . '</p>';
614
746
                } else {
615
747
                        ?>
616
748
                        <div class="upload-dropzone">
853
985
                        <p class="customizer-section-intro">
854
986
                                <?php
855
987
                                if ( $width && $height ) {
856
 
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new</strong>, your theme recommends a header size of <strong>%s &times; %s</strong> pixels.' ), $width, $height );
 
988
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of <strong>%s &times; %s</strong> pixels.' ), $width, $height );
857
989
                                } elseif ( $width ) {
858
 
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
 
990
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
859
991
                                } else {
860
 
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
 
992
                                        printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
861
993
                                }
862
994
                                ?>
863
995
                        </p>
924
1056
                </span>
925
1057
                <?php
926
1058
        }
 
1059
 
 
1060
        /**
 
1061
         * Whether the current sidebar is rendered on the page.
 
1062
         *
 
1063
         * @since 4.0.0
 
1064
         * @access public
 
1065
         *
 
1066
         * @return bool Whether sidebar is rendered.
 
1067
         */
 
1068
        public function active_callback() {
 
1069
                return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
 
1070
        }
927
1071
}
928
1072
 
929
1073
/**
964
1108
                $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
965
1109
                echo $this->manager->widgets->get_widget_control( $args );
966
1110
        }
 
1111
 
 
1112
        /**
 
1113
         * Whether the current widget is rendered on the page.
 
1114
         *
 
1115
         * @since 4.0.0
 
1116
         * @access public
 
1117
         *
 
1118
         * @return bool Whether the widget is rendered.
 
1119
         */
 
1120
        function active_callback() {
 
1121
                return $this->manager->widgets->is_widget_rendered( $this->widget_id );
 
1122
        }
967
1123
}
968
1124