~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-admin/custom-header.php

  • Committer: Stephane Miller
  • Date: 2012-09-06 02:15:02 UTC
  • Revision ID: steph@canonical.com-20120906021502-nwkniyljjx0f9gvc
add wordpress 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
         */
43
43
        var $default_headers = array();
44
44
 
45
 
 
46
45
        /**
47
46
         * Holds custom headers uploaded by the user
48
47
         *
72
71
        function __construct($admin_header_callback, $admin_image_div_callback = '') {
73
72
                $this->admin_header_callback = $admin_header_callback;
74
73
                $this->admin_image_div_callback = $admin_image_div_callback;
 
74
 
 
75
                add_action( 'admin_menu', array( $this, 'init' ) );
75
76
        }
76
77
 
77
78
        /**
90
91
                add_action("admin_head-$page", array(&$this, 'help') );
91
92
                add_action("admin_head-$page", array(&$this, 'take_action'), 50);
92
93
                add_action("admin_head-$page", array(&$this, 'js'), 50);
93
 
                add_action("admin_head-$page", $this->admin_header_callback, 51);
 
94
                if ( $this->admin_header_callback )
 
95
                        add_action("admin_head-$page", $this->admin_header_callback, 51);
 
96
 
 
97
                if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) {
 
98
                        add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
 
99
                        add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
 
100
                        add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
 
101
                }
94
102
        }
95
103
 
96
104
        /**
103
111
                        'id'      => 'overview',
104
112
                        'title'   => __('Overview'),
105
113
                        'content' =>
106
 
                                '<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately.' ) . '</p>' .
107
 
                                '<p>' . __( 'If you want to discard your custom header and go back to the default included in your theme, click on the buttons to remove the custom image and restore the original header image.' ) . '</p>' .
108
 
                                '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&#8217;d like and click the Save Changes button.' ) . '</p>'
 
114
                                '<p>' . __( 'This screen is used to customize the header section of your theme.') . '</p>' .
 
115
                                '<p>' . __( 'You can choose from the theme&#8217;s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.') . '<p>'
 
116
                ) );
 
117
 
 
118
                get_current_screen()->add_help_tab( array(
 
119
                        'id'      => 'set-header-image',
 
120
                        'title'   => __('Header Image'),
 
121
                        'content' =>
 
122
                                '<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the &#8220;Choose Image&#8221; button.' ) . '</p>' .
 
123
                                '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&#8217;d like and click the &#8220;Save Changes&#8221; button.' ) . '</p>' .
 
124
                                '<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the &#8220;Random&#8221; radio button next to the Uploaded Images or Default Images section to enable this feature.') . '</p>' .
 
125
                                '<p>' . __( 'If you don&#8217;t want a header image to be displayed on your site at all, click the &#8220;Remove Header Image&#8221; button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click &#8220;Save Changes&#8221;.') . '</p>'
 
126
                ) );
 
127
 
 
128
                get_current_screen()->add_help_tab( array(
 
129
                        'id'      => 'set-header-text',
 
130
                        'title'   => __('Header Text'),
 
131
                        'content' =>
 
132
                                '<p>' . sprintf( __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%1$s">General Settings</a> section.' ), admin_url( 'options-general.php' ) ) . '<p>' .
 
133
                                '<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by typing in a legitimate HTML hex value (eg: &#8220;#ff0000&#8221; for red) or by clicking &#8220;Select a Color&#8221; and dialing in a color using the color picker.') . '</p>' .
 
134
                                '<p>' . __( 'Don&#8217;t forget to Save Changes when you&#8217;re done!') . '</p>'
109
135
                ) );
110
136
 
111
137
                get_current_screen()->set_help_sidebar(
127
153
                        return 1;
128
154
 
129
155
                $step = (int) $_GET['step'];
130
 
                if ( $step < 1 || 3 < $step )
131
 
                        $step = 1;
 
156
                if ( $step < 1 || 3 < $step ||
 
157
                        ( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) ||
 
158
                        ( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) )
 
159
                )
 
160
                        return 1;
132
161
 
133
162
                return $step;
134
163
        }
141
170
        function js_includes() {
142
171
                $step = $this->step();
143
172
 
144
 
                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
145
 
                        wp_enqueue_script('farbtastic');
146
 
                elseif ( 2 == $step )
 
173
                if ( ( 1 == $step || 3 == $step ) ) {
 
174
                        add_thickbox();
 
175
                        wp_enqueue_script( 'media-upload' );
 
176
                        wp_enqueue_script( 'custom-header' );
 
177
                        if ( current_theme_supports( 'custom-header', 'header-text' ) )
 
178
                                wp_enqueue_script('farbtastic');
 
179
                } elseif ( 2 == $step ) {
147
180
                        wp_enqueue_script('imgareaselect');
 
181
                }
148
182
        }
149
183
 
150
184
        /**
155
189
        function css_includes() {
156
190
                $step = $this->step();
157
191
 
158
 
                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
 
192
                if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
159
193
                        wp_enqueue_style('farbtastic');
160
194
                elseif ( 2 == $step )
161
195
                        wp_enqueue_style('imgareaselect');
162
196
        }
163
197
 
164
198
        /**
165
 
         * Check if header text is allowed
166
 
         *
167
 
         * @since 3.0.0
168
 
         */
169
 
        function header_text() {
170
 
                if ( defined( 'NO_HEADER_TEXT' ) && NO_HEADER_TEXT )
171
 
                        return false;
172
 
 
173
 
                return true;
174
 
        }
175
 
 
176
 
        /**
177
199
         * Execute custom header modification.
178
200
         *
179
201
         * @since 2.6.0
189
211
 
190
212
                if ( isset( $_POST['resetheader'] ) ) {
191
213
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
192
 
                        remove_theme_mod( 'header_image' );
 
214
                        $this->reset_header_image();
193
215
                        return;
194
216
                }
195
217
 
201
223
 
202
224
                if ( isset( $_POST['removeheader'] ) ) {
203
225
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
204
 
                        set_theme_mod( 'header_image', 'remove-header' );
 
226
                        $this->remove_header_image();
205
227
                        return;
206
228
                }
207
229
 
208
 
                if ( isset( $_POST['text-color'] ) ) {
 
230
                if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) {
 
231
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
 
232
                        set_theme_mod( 'header_textcolor', 'blank' );
 
233
                } elseif ( isset( $_POST['text-color'] ) ) {
209
234
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
210
235
                        $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
211
 
                        if ( 'blank' == $_POST['text-color'] ) {
 
236
                        $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
 
237
                        if ( strlen($color) == 6 || strlen($color) == 3 )
 
238
                                set_theme_mod('header_textcolor', $color);
 
239
                        elseif ( ! $color )
212
240
                                set_theme_mod( 'header_textcolor', 'blank' );
213
 
                        } else {
214
 
                                $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
215
 
                                if ( strlen($color) == 6 || strlen($color) == 3 )
216
 
                                        set_theme_mod('header_textcolor', $color);
217
 
                        }
218
241
                }
219
242
 
220
243
                if ( isset( $_POST['default-header'] ) ) {
221
244
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
222
 
                        if ( 'random-default-image' == $_POST['default-header'] ) {
223
 
                                set_theme_mod( 'header_image', 'random-default-image' );
224
 
                        } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) {
225
 
                                set_theme_mod( 'header_image', 'random-uploaded-image' );
226
 
                        } else {
227
 
                                $this->process_default_headers();
228
 
                                $uploaded = get_uploaded_header_images();
229
 
                                if ( isset( $uploaded[$_POST['default-header']] ) )
230
 
                                        set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) );
231
 
                                elseif ( isset( $this->default_headers[$_POST['default-header']] ) )
232
 
                                        set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
233
 
                        }
 
245
                        $this->set_header_image( $_POST['default-header'] );
 
246
                        return;
234
247
                }
235
248
        }
236
249
 
290
303
                        echo '<div class="default-header">';
291
304
                        echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />';
292
305
                        $width = '';
293
 
                        if ( !empty( $header['uploaded'] ) )
 
306
                        if ( !empty( $header['attachment_id'] ) )
294
307
                                $width = ' width="230"';
295
 
                        echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>';
 
308
                        echo '<img src="' . set_url_scheme( $header_thumbnail ) . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>';
296
309
                        echo '</div>';
297
310
                }
298
311
                echo '<div class="clear"></div></div>';
305
318
         */
306
319
        function js() {
307
320
                $step = $this->step();
308
 
                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
 
321
                if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
309
322
                        $this->js_1();
310
323
                elseif ( 2 == $step )
311
324
                        $this->js_2();
319
332
        function js_1() { ?>
320
333
<script type="text/javascript">
321
334
/* <![CDATA[ */
322
 
        var text_objects = ['#name', '#desc', '#text-color-row'];
323
 
        var farbtastic;
324
 
        var default_color = '#<?php echo HEADER_TEXTCOLOR; ?>';
325
 
        var old_color = null;
 
335
var farbtastic;
 
336
(function($){
 
337
        var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
 
338
                header_text_fields;
326
339
 
327
340
        function pickColor(color) {
328
 
                jQuery('#name').css('color', color);
329
 
                jQuery('#desc').css('color', color);
330
 
                jQuery('#text-color').val(color);
 
341
                $('#name').css('color', color);
 
342
                $('#desc').css('color', color);
 
343
                $('#text-color').val(color);
331
344
                farbtastic.setColor(color);
332
345
        }
333
346
 
334
 
        function toggle_text(s) {
335
 
                if (jQuery(s).attr('id') == 'showtext' && jQuery('#text-color').val() != 'blank')
336
 
                        return;
337
 
 
338
 
                if (jQuery(s).attr('id') == 'hidetext' && jQuery('#text-color').val() == 'blank')
339
 
                        return;
340
 
 
341
 
                if (jQuery('#text-color').val() == 'blank') {
342
 
                        //Show text
343
 
                        if (old_color == '#blank')
344
 
                                old_color = default_color;
345
 
 
346
 
                        jQuery( text_objects.toString() ).show();
347
 
                        jQuery('#text-color').val(old_color);
348
 
                        jQuery('#name').css('color', old_color);
349
 
                        jQuery('#desc').css('color', old_color);
350
 
                        pickColor(old_color);
 
347
        function toggle_text() {
 
348
                var checked = $('#display-header-text').prop('checked'),
 
349
                        text_color;
 
350
                header_text_fields.toggle( checked );
 
351
                if ( ! checked )
 
352
                        return;
 
353
                text_color = $('#text-color');
 
354
                if ( '' == text_color.val().replace('#', '') ) {
 
355
                        text_color.val( default_color );
 
356
                        pickColor( default_color );
351
357
                } else {
352
 
                        //Hide text
353
 
                        jQuery( text_objects.toString() ).hide();
354
 
                        old_color = jQuery('#text-color').val();
355
 
                        jQuery('#text-color').val('blank');
 
358
                        pickColor( text_color.val() );
356
359
                }
357
360
        }
358
361
 
359
 
        jQuery(document).ready(function() {
360
 
                jQuery('#pickcolor').click(function() {
361
 
                        jQuery('#color-picker').show();
362
 
                });
363
 
 
364
 
                jQuery('input[name="hidetext"]').click(function() {
365
 
                        toggle_text(this);
366
 
                });
367
 
 
368
 
                jQuery('#defaultcolor').click(function() {
 
362
        $(document).ready(function() {
 
363
                header_text_fields = $('.displaying-header-text');
 
364
                $('#pickcolor').click(function(e) {
 
365
                        e.preventDefault();
 
366
                        $('#color-picker').show();
 
367
                });
 
368
 
 
369
                $('#display-header-text').click( toggle_text );
 
370
 
 
371
                $('#defaultcolor').click(function() {
369
372
                        pickColor(default_color);
370
 
                        jQuery('#text-color').val(default_color)
 
373
                        $('#text-color').val(default_color);
371
374
                });
372
375
 
373
 
                jQuery('#text-color').keyup(function() {
374
 
                        var _hex = jQuery('#text-color').val();
 
376
                $('#text-color').keyup(function() {
 
377
                        var _hex = $('#text-color').val();
375
378
                        var hex = _hex;
376
379
                        if ( hex[0] != '#' )
377
380
                                hex = '#' + hex;
378
381
                        hex = hex.replace(/[^#a-fA-F0-9]+/, '');
379
382
                        if ( hex != _hex )
380
 
                                jQuery('#text-color').val(hex);
 
383
                                $('#text-color').val(hex);
381
384
                        if ( hex.length == 4 || hex.length == 7 )
382
385
                                pickColor( hex );
383
386
                });
384
387
 
385
 
                jQuery(document).mousedown(function(){
386
 
                        jQuery('#color-picker').each( function() {
387
 
                                var display = jQuery(this).css('display');
 
388
                $(document).mousedown(function(){
 
389
                        $('#color-picker').each( function() {
 
390
                                var display = $(this).css('display');
388
391
                                if (display == 'block')
389
 
                                        jQuery(this).fadeOut(2);
 
392
                                        $(this).fadeOut(2);
390
393
                        });
391
394
                });
392
395
 
393
 
                farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); });
394
 
                <?php if ( $color = get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?>
395
 
                pickColor('#<?php echo $color; ?>');
396
 
                <?php } ?>
397
 
 
398
 
                <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) { ?>
 
396
                farbtastic = $.farbtastic('#color-picker', function(color) { pickColor(color); });
 
397
                <?php if ( display_header_text() ) { ?>
 
398
                pickColor('#<?php echo get_header_textcolor(); ?>');
 
399
                <?php } else { ?>
399
400
                toggle_text();
400
401
                <?php } ?>
401
402
        });
 
403
})(jQuery);
402
404
/* ]]> */
403
405
</script>
404
406
<?php
420
422
        }
421
423
 
422
424
        jQuery(document).ready(function() {
423
 
                var xinit = <?php echo HEADER_IMAGE_WIDTH; ?>;
424
 
                var yinit = <?php echo HEADER_IMAGE_HEIGHT; ?>;
 
425
                var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>;
 
426
                var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>;
425
427
                var ratio = xinit / yinit;
426
428
                var ximg = jQuery('img#upload').width();
427
429
                var yimg = jQuery('img#upload').height();
439
441
                jQuery('img#upload').imgAreaSelect({
440
442
                        handles: true,
441
443
                        keys: true,
442
 
                        aspectRatio: xinit + ':' + yinit,
443
444
                        show: true,
444
445
                        x1: 0,
445
446
                        y1: 0,
446
447
                        x2: xinit,
447
448
                        y2: yinit,
448
 
                        maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
449
 
                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
 
449
                        <?php
 
450
                        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
 
451
                        ?>
 
452
                        aspectRatio: xinit + ':' + yinit,
 
453
                        <?php
 
454
                        }
 
455
                        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
 
456
                        ?>
 
457
                        maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>,
 
458
                        <?php
 
459
                        }
 
460
                        if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
 
461
                        ?>
 
462
                        maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>,
 
463
                        <?php
 
464
                        }
 
465
                        ?>
450
466
                        onInit: function () {
451
467
                                jQuery('#width').val(xinit);
452
468
                                jQuery('#height').val(yinit);
483
499
</div>
484
500
<?php } ?>
485
501
 
 
502
<h3><?php _e( 'Header Image' ); ?></h3>
 
503
 
486
504
<table class="form-table">
487
505
<tbody>
488
506
 
489
 
 
490
507
<tr valign="top">
491
508
<th scope="row"><?php _e( 'Preview' ); ?></th>
492
 
<td >
 
509
<td>
493
510
        <?php if ( $this->admin_image_div_callback ) {
494
511
          call_user_func( $this->admin_image_div_callback );
495
512
        } else {
496
513
        ?>
497
 
        <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);">
 
514
        <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;">
498
515
                <?php
499
 
                if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
 
516
                if ( display_header_text() )
 
517
                        $style = ' style="color:#' . get_header_textcolor() . ';"';
 
518
                else
500
519
                        $style = ' style="display:none;"';
501
 
                else
502
 
                        $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
503
520
                ?>
504
 
                <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1>
505
 
                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
 
521
                <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1>
 
522
                <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
506
523
        </div>
507
524
        <?php } ?>
508
525
</td>
509
526
</tr>
510
 
<?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>
 
527
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
511
528
<tr valign="top">
512
 
<th scope="row"><?php _e( 'Upload Image' ); ?></th>
 
529
<th scope="row"><?php _e( 'Select Image' ); ?></th>
513
530
<td>
514
531
        <p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
515
 
        <?php printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p>
 
532
        <?php
 
533
        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
 
534
                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
 
535
        } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
 
536
                if ( ! current_theme_supports( 'custom-header', 'flex-width' ) )
 
537
                        printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
 
538
        } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
 
539
                if ( ! current_theme_supports( 'custom-header', 'flex-height' ) )
 
540
                        printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
 
541
        }
 
542
        if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) {
 
543
                if ( current_theme_supports( 'custom-header', 'width' ) )
 
544
                        printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
 
545
                if ( current_theme_supports( 'custom-header', 'height' ) )
 
546
                        printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
 
547
        }
 
548
        ?></p>
516
549
        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
517
550
        <p>
518
551
                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
519
552
                <input type="file" id="upload" name="import" />
520
553
                <input type="hidden" name="action" value="save" />
521
 
                <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?>
 
554
                <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
522
555
                <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
523
556
        </p>
 
557
        <?php
 
558
                $image_library_url = get_upload_iframe_src( 'image', null, 'library' );
 
559
                $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url );
 
560
                $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url );
 
561
        ?>
 
562
        <p>
 
563
                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
 
564
                <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
 
565
        </p>
524
566
        </form>
525
567
</td>
526
568
</tr>
546
588
<tr valign="top">
547
589
<th scope="row"><?php _e( 'Default Images' ); ?></th>
548
590
<td>
549
 
<?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>
 
591
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
550
592
        <p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers, or show a random one.' ) ?></p>
551
593
<?php else: ?>
552
594
        <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ) ?></p>
567
609
</tr>
568
610
        <?php endif;
569
611
 
570
 
        if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE ) : ?>
 
612
        $default_image = get_theme_support( 'custom-header', 'default-image' );
 
613
        if ( $default_image && get_header_image() != $default_image ) : ?>
571
614
<tr valign="top">
572
615
<th scope="row"><?php _e( 'Reset Image' ); ?></th>
573
616
<td>
579
622
</tbody>
580
623
</table>
581
624
 
582
 
        <?php if ( $this->header_text() ) : ?>
 
625
<?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
 
626
 
 
627
<h3><?php _e( 'Header Text' ); ?></h3>
 
628
 
583
629
<table class="form-table">
584
630
<tbody>
585
 
<tr valign="top" class="hide-if-no-js">
586
 
<th scope="row"><?php _e( 'Display Text' ); ?></th>
 
631
<tr valign="top">
 
632
<th scope="row"><?php _e( 'Header Text' ); ?></th>
587
633
<td>
588
634
        <p>
589
 
        <?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?>
590
 
        <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) )  ? true : false ); ?> /> <?php _e( 'No' ); ?></label>
591
 
        <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label>
 
635
        <label><input type="checkbox" name="display-header-text" id="display-header-text"<?php checked( display_header_text() ); ?> /> <?php _e( 'Show header text with your image.' ); ?></label>
592
636
        </p>
593
637
</td>
594
638
</tr>
595
639
 
596
 
<tr valign="top" id="text-color-row">
 
640
<tr valign="top" class="displaying-header-text">
597
641
<th scope="row"><?php _e( 'Text Color' ); ?></th>
598
642
<td>
599
643
        <p>
600
 
                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ); ?>" />
601
 
                <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span>
602
 
                <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" />
 
644
<?php if ( display_header_text() ) : ?>
 
645
                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" />
 
646
<?php else : ?>
 
647
                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_support( 'custom-header', 'default-text-color' ) ); ?>" />
 
648
<?php endif; ?>
 
649
                <a href="#" class="hide-if-no-js" id="pickcolor"><?php _e( 'Select a Color' ); ?></a>
603
650
        </p>
604
651
        <div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
605
652
</td>
606
653
</tr>
607
654
 
608
 
        <?php if ( defined('HEADER_TEXTCOLOR') && get_theme_mod('header_textcolor') ) { ?>
 
655
        <?php if ( current_theme_supports( 'custom-header', 'default-text-color' ) && get_theme_mod( 'header_textcolor' ) ) { ?>
609
656
<tr valign="top">
610
657
<th scope="row"><?php _e('Reset Text Color'); ?></th>
611
658
<td>
617
664
 
618
665
</tbody>
619
666
</table>
620
 
        <?php endif;
 
667
<?php endif;
621
668
 
622
669
do_action( 'custom_header_options' );
623
670
 
636
683
         */
637
684
        function step_2() {
638
685
                check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload');
639
 
                if ( ! current_theme_supports( 'custom-header-uploads' ) )
 
686
                if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
640
687
                        wp_die( __( 'Cheatin&#8217; uh?' ) );
641
688
 
642
 
                $overrides = array('test_form' => false);
643
 
                $file = wp_handle_upload($_FILES['import'], $overrides);
644
 
 
645
 
                if ( isset($file['error']) )
646
 
                        wp_die( $file['error'],  __( 'Image Upload Error' ) );
647
 
 
648
 
                $url = $file['url'];
649
 
                $type = $file['type'];
650
 
                $file = $file['file'];
651
 
                $filename = basename($file);
652
 
 
653
 
                // Construct the object array
654
 
                $object = array(
655
 
                'post_title' => $filename,
656
 
                'post_content' => $url,
657
 
                'post_mime_type' => $type,
658
 
                'guid' => $url,
659
 
                'context' => 'custom-header'
660
 
                );
661
 
 
662
 
                // Save the data
663
 
                $id = wp_insert_attachment($object, $file);
664
 
 
665
 
                list($width, $height, $type, $attr) = getimagesize( $file );
666
 
 
667
 
                if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
 
689
                if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
 
690
                        $attachment_id = absint( $_GET['file'] );
 
691
                        $file = get_attached_file( $attachment_id, true );
 
692
                        $url = wp_get_attachment_image_src( $attachment_id, 'full');
 
693
                        $url = $url[0];
 
694
                } elseif ( isset( $_POST ) ) {
 
695
                        extract($this->step_2_manage_upload());
 
696
                }
 
697
 
 
698
                if ( file_exists( $file ) ) {
 
699
                        list( $width, $height, $type, $attr ) = getimagesize( $file );
 
700
                } else {
 
701
                        $data = wp_get_attachment_metadata( $attachment_id );
 
702
                        $height = $data[ 'height' ];
 
703
                        $width = $data[ 'width' ];
 
704
                        unset( $data );
 
705
                }
 
706
 
 
707
                $max_width = 0;
 
708
                // For flex, limit size of image displayed to 1500px unless theme says otherwise
 
709
                if ( current_theme_supports( 'custom-header', 'flex-width' ) )
 
710
                        $max_width = 1500;
 
711
 
 
712
                if ( current_theme_supports( 'custom-header', 'max-width' ) )
 
713
                        $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
 
714
                $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
 
715
 
 
716
                // If flexible height isn't supported and the image is the exact right size
 
717
                if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' )
 
718
                        && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) )
 
719
                {
668
720
                        // Add the meta-data
669
 
                        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
670
 
                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
671
 
 
672
 
                        set_theme_mod('header_image', esc_url($url));
673
 
                        do_action('wp_create_file_in_uploads', $file, $id); // For replication
 
721
                        if ( file_exists( $file ) )
 
722
                                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
 
723
 
 
724
                        $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
 
725
 
 
726
                        do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication
674
727
                        return $this->finished();
675
 
                } elseif ( $width > HEADER_IMAGE_WIDTH ) {
676
 
                        $oitar = $width / HEADER_IMAGE_WIDTH;
677
 
                        $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
678
 
                        if ( is_wp_error( $image ) )
679
 
                                wp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) );
 
728
                } elseif ( $width > $max_width ) {
 
729
                        $oitar = $width / $max_width;
 
730
                        $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
 
731
                        if ( ! $image || is_wp_error( $image ) )
 
732
                                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
680
733
 
681
 
                        $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
 
734
                        $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication
682
735
 
683
736
                        $url = str_replace(basename($url), basename($image), $url);
684
737
                        $width = $width / $oitar;
704
757
        <input type="hidden" name="y1" id="y1" value="0"/>
705
758
        <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
706
759
        <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/>
707
 
        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" />
 
760
        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
708
761
        <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
 
762
        <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
 
763
        <input type="hidden" name="create-new-attachment" value="true" />
 
764
        <?php } ?>
709
765
        <?php wp_nonce_field( 'custom-header-crop-image' ) ?>
710
766
 
711
 
        <?php submit_button( __( 'Crop and Publish' ) ); ?>
 
767
        <p class="submit">
 
768
        <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
 
769
        <?php
 
770
        if ( isset( $oitar ) && 1 == $oitar )
 
771
                submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
 
772
        ?>
712
773
        </p>
713
774
</form>
714
775
</div>
715
776
                <?php
716
777
        }
717
778
 
 
779
 
 
780
        /**
 
781
         * Upload the file to be cropped in the second step.
 
782
         *
 
783
         * @since 3.4.0
 
784
         */
 
785
        function step_2_manage_upload() {
 
786
                $overrides = array('test_form' => false);
 
787
                $file = wp_handle_upload($_FILES['import'], $overrides);
 
788
 
 
789
                if ( isset($file['error']) )
 
790
                        wp_die( $file['error'],  __( 'Image Upload Error' ) );
 
791
 
 
792
                $url = $file['url'];
 
793
                $type = $file['type'];
 
794
                $file = $file['file'];
 
795
                $filename = basename($file);
 
796
 
 
797
                // Construct the object array
 
798
                $object = array(
 
799
                        'post_title'     => $filename,
 
800
                        'post_content'   => $url,
 
801
                        'post_mime_type' => $type,
 
802
                        'guid'           => $url,
 
803
                        'context'        => 'custom-header'
 
804
                );
 
805
 
 
806
                // Save the data
 
807
                $attachment_id = wp_insert_attachment( $object, $file );
 
808
                return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
 
809
        }
 
810
 
718
811
        /**
719
812
         * Display third step of custom header image page.
720
813
         *
721
814
         * @since 2.1.0
722
815
         */
723
816
        function step_3() {
724
 
                check_admin_referer('custom-header-crop-image');
725
 
                if ( ! current_theme_supports( 'custom-header-uploads' ) )
 
817
                check_admin_referer( 'custom-header-crop-image' );
 
818
 
 
819
                if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
726
820
                        wp_die( __( 'Cheatin&#8217; uh?' ) );
727
821
 
728
822
                if ( $_POST['oitar'] > 1 ) {
735
829
                $attachment_id = absint( $_POST['attachment_id'] );
736
830
                $original = get_attached_file($attachment_id);
737
831
 
738
 
                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
739
 
                if ( is_wp_error( $cropped ) )
740
 
                        wp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) );
 
832
 
 
833
                $max_width = 0;
 
834
                // For flex, limit size of image displayed to 1500px unless theme says otherwise
 
835
                if ( current_theme_supports( 'custom-header', 'flex-width' ) )
 
836
                        $max_width = 1500;
 
837
 
 
838
                if ( current_theme_supports( 'custom-header', 'max-width' ) )
 
839
                        $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
 
840
                $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
 
841
 
 
842
                if ( ( current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) || $_POST['width'] > $max_width )
 
843
                        $dst_height = absint( $_POST['height'] * ( $max_width / $_POST['width'] ) );
 
844
                elseif ( current_theme_supports( 'custom-header', 'flex-height' ) && current_theme_supports( 'custom-header', 'flex-width' ) )
 
845
                        $dst_height = absint( $_POST['height'] );
 
846
                else
 
847
                        $dst_height = get_theme_support( 'custom-header', 'height' );
 
848
 
 
849
                if ( ( current_theme_supports( 'custom-header', 'flex-width' ) && ! current_theme_supports( 'custom-header', 'flex-height' ) ) || $_POST['width'] > $max_width )
 
850
                        $dst_width = absint( $_POST['width'] * ( $max_width / $_POST['width'] ) );
 
851
                elseif ( current_theme_supports( 'custom-header', 'flex-width' ) && current_theme_supports( 'custom-header', 'flex-height' ) )
 
852
                        $dst_width = absint( $_POST['width'] );
 
853
                else
 
854
                        $dst_width = get_theme_support( 'custom-header', 'width' );
 
855
 
 
856
                if ( empty( $_POST['skip-cropping'] ) )
 
857
                        $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
 
858
                elseif ( ! empty( $_POST['create-new-attachment'] ) )
 
859
                        $cropped = _copy_image_file( $attachment_id );
 
860
                else
 
861
                        $cropped = get_attached_file( $attachment_id );
 
862
 
 
863
                if ( ! $cropped || is_wp_error( $cropped ) )
 
864
                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
741
865
 
742
866
                $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
743
867
 
744
868
                $parent = get_post($attachment_id);
745
869
                $parent_url = $parent->guid;
746
 
                $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
 
870
                $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
 
871
 
 
872
                $size = @getimagesize( $cropped );
 
873
                $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
747
874
 
748
875
                // Construct the object array
749
876
                $object = array(
750
877
                        'ID' => $attachment_id,
751
878
                        'post_title' => basename($cropped),
752
879
                        'post_content' => $url,
753
 
                        'post_mime_type' => 'image/jpeg',
 
880
                        'post_mime_type' => $image_type,
754
881
                        'guid' => $url,
755
882
                        'context' => 'custom-header'
756
883
                );
 
884
                if ( ! empty( $_POST['create-new-attachment'] ) )
 
885
                        unset( $object['ID'] );
757
886
 
758
887
                // Update the attachment
759
 
                wp_insert_attachment($object, $cropped);
 
888
                $attachment_id = wp_insert_attachment( $object, $cropped );
760
889
                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
761
 
                update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
762
890
 
763
 
                set_theme_mod('header_image', $url);
 
891
                $width = $dst_width;
 
892
                $height = $dst_height;
 
893
                $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
764
894
 
765
895
                // cleanup
766
 
                $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
767
 
                @unlink( apply_filters( 'wp_delete_file', $medium ) );
768
 
                @unlink( apply_filters( 'wp_delete_file', $original ) );
 
896
                $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
 
897
                if ( file_exists( $medium ) )
 
898
                        @unlink( apply_filters( 'wp_delete_file', $medium ) );
 
899
                if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) )
 
900
                        @unlink( apply_filters( 'wp_delete_file', $original ) );
769
901
 
770
902
                return $this->finished();
771
903
        }
789
921
                if ( ! current_user_can('edit_theme_options') )
790
922
                        wp_die(__('You do not have permission to customize headers.'));
791
923
                $step = $this->step();
792
 
                if ( 1 == $step )
793
 
                        $this->step_1();
794
 
                elseif ( 2 == $step )
 
924
                if ( 2 == $step )
795
925
                        $this->step_2();
796
926
                elseif ( 3 == $step )
797
927
                        $this->step_3();
798
 
        }
799
 
 
 
928
                else
 
929
                        $this->step_1();
 
930
        }
 
931
 
 
932
        /**
 
933
         * Replace default attachment actions with "Set as header" link.
 
934
         *
 
935
         * @since 3.4.0
 
936
         */
 
937
        function attachment_fields_to_edit( $form_fields, $post ) {
 
938
                $form_fields = array();
 
939
                $href = esc_url(add_query_arg(array(
 
940
                        'page' => 'custom-header',
 
941
                        'step' => 2,
 
942
                        '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
 
943
                        'file' => $post->ID
 
944
                ), admin_url('themes.php')));
 
945
 
 
946
                $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' );
 
947
                $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' );
 
948
 
 
949
                return $form_fields;
 
950
        }
 
951
 
 
952
        /**
 
953
         * Leave only "Media Library" tab in the uploader window.
 
954
         *
 
955
         * @since 3.4.0
 
956
         */
 
957
        function filter_upload_tabs() {
 
958
                return array( 'library' => __('Media Library') );
 
959
        }
 
960
 
 
961
        /**
 
962
         * Choose a header image, selected from existing uploaded and default headers,
 
963
         * or provide an array of uploaded header data (either new, or from media library).
 
964
         *
 
965
         * @param mixed $choice Which header image to select. Allows for values of 'random-default-image',
 
966
         *      for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling
 
967
         *      among the uploaded images; the key of a default image registered for that theme; and
 
968
         *      the key of an image uploaded for that theme (the basename of the URL).
 
969
         *  Or an array of arguments: attachment_id, url, width, height. All are required.
 
970
         *
 
971
         * @since 3.4.0
 
972
         */
 
973
        final public function set_header_image( $choice ) {
 
974
                if ( is_array( $choice ) || is_object( $choice ) ) {
 
975
                        $choice = (array) $choice;
 
976
                        if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) )
 
977
                                return;
 
978
 
 
979
                        $choice['url'] = esc_url_raw( $choice['url'] );
 
980
 
 
981
                        $header_image_data = (object) array(
 
982
                                'attachment_id' => $choice['attachment_id'],
 
983
                                'url'           => $choice['url'],
 
984
                                'thumbnail_url' => $choice['url'],
 
985
                                'height'        => $choice['height'],
 
986
                                'width'         => $choice['width'],
 
987
                        );
 
988
 
 
989
                        update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
 
990
                        set_theme_mod( 'header_image', $choice['url'] );
 
991
                        set_theme_mod( 'header_image_data', $header_image_data );
 
992
                        return;
 
993
                }
 
994
 
 
995
                if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
 
996
                        set_theme_mod( 'header_image', $choice );
 
997
                        remove_theme_mod( 'header_image_data' );
 
998
                        return;
 
999
                }
 
1000
 
 
1001
                $uploaded = get_uploaded_header_images();
 
1002
                if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
 
1003
                        $header_image_data = $uploaded[ $choice ];
 
1004
 
 
1005
                } else {
 
1006
                        $this->process_default_headers();
 
1007
                        if ( isset( $this->default_headers[ $choice ] ) )
 
1008
                                $header_image_data = $this->default_headers[ $choice ];
 
1009
                        else
 
1010
                                return;
 
1011
                }
 
1012
 
 
1013
                set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) );
 
1014
                set_theme_mod( 'header_image_data', $header_image_data );
 
1015
        }
 
1016
 
 
1017
        /**
 
1018
         * Remove a header image.
 
1019
         *
 
1020
         * @since 3.4.0
 
1021
         */
 
1022
        final public function remove_header_image() {
 
1023
                return $this->set_header_image( 'remove-header' );
 
1024
        }
 
1025
 
 
1026
        /**
 
1027
         * Reset a header image to the default image for the theme.
 
1028
         *
 
1029
         * This method does not do anything if the theme does not have a default header image.
 
1030
         *
 
1031
         * @since 3.4.0
 
1032
         */
 
1033
        final public function reset_header_image() {
 
1034
                $this->process_default_headers();
 
1035
                $default = get_theme_support( 'custom-header', 'default-image' );
 
1036
 
 
1037
                if ( ! $default )
 
1038
                        return $this->remove_header_image();
 
1039
 
 
1040
                $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
 
1041
 
 
1042
                foreach ( $this->default_headers as $header => $details ) {
 
1043
                        if ( $details['url'] == $default ) {
 
1044
                                $default_data = $details;
 
1045
                                break;
 
1046
                        }
 
1047
                }
 
1048
 
 
1049
                set_theme_mod( 'header_image', $default );
 
1050
                set_theme_mod( 'header_image_data', (object) $default_data );
 
1051
        }
800
1052
}
801
 
?>