89 * Adds contextual help. |
89 * Adds contextual help. |
90 * |
90 * |
91 * @since 3.0.0 |
91 * @since 3.0.0 |
92 */ |
92 */ |
93 public function help() { |
93 public function help() { |
94 get_current_screen()->add_help_tab( array( |
94 get_current_screen()->add_help_tab( |
95 'id' => 'overview', |
95 array( |
96 'title' => __('Overview'), |
96 'id' => 'overview', |
97 'content' => |
97 'title' => __( 'Overview' ), |
98 '<p>' . __( 'This screen is used to customize the header section of your theme.') . '</p>' . |
98 'content' => |
99 '<p>' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.') . '<p>' |
99 '<p>' . __( 'This screen is used to customize the header section of your theme.' ) . '</p>' . |
100 ) ); |
100 '<p>' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.' ) . '<p>', |
101 |
101 ) |
102 get_current_screen()->add_help_tab( array( |
102 ); |
103 'id' => 'set-header-image', |
103 |
104 'title' => __('Header Image'), |
104 get_current_screen()->add_help_tab( |
105 'content' => |
105 array( |
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. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the “Choose Image” button.' ) . '</p>' . |
106 'id' => 'set-header-image', |
107 '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the “Save Changes” button.' ) . '</p>' . |
107 'title' => __( 'Header Image' ), |
108 '<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 “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.') . '</p>' . |
108 'content' => |
109 '<p>' . __( 'If you don’t want a header image to be displayed on your site at all, click the “Remove Header Image” 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 “Save Changes”.') . '</p>' |
109 '<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 “Choose Image” button.' ) . '</p>' . |
110 ) ); |
110 '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the “Save Changes” button.' ) . '</p>' . |
111 |
111 '<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 “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '</p>' . |
112 get_current_screen()->add_help_tab( array( |
112 '<p>' . __( 'If you don’t want a header image to be displayed on your site at all, click the “Remove Header Image” 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 “Save Changes”.' ) . '</p>', |
113 'id' => 'set-header-text', |
113 ) |
114 'title' => __('Header Text'), |
114 ); |
115 'content' => |
115 |
116 '<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>' . |
116 get_current_screen()->add_help_tab( |
117 '<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 clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
117 array( |
118 '<p>' . __( 'Don’t forget to click “Save Changes” when you’re done!') . '</p>' |
118 'id' => 'set-header-text', |
119 ) ); |
119 'title' => __( 'Header Text' ), |
|
120 'content' => |
|
121 '<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>' . |
|
122 '<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 clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
123 '<p>' . __( 'Don’t forget to click “Save Changes” when you’re done!' ) . '</p>', |
|
124 ) |
|
125 ); |
120 |
126 |
121 get_current_screen()->set_help_sidebar( |
127 get_current_screen()->set_help_sidebar( |
122 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
128 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
123 '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Header_Screen">Documentation on Custom Header</a>' ) . '</p>' . |
129 '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Header_Screen">Documentation on Custom Header</a>' ) . '</p>' . |
124 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' |
130 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
125 ); |
131 ); |
126 } |
132 } |
127 |
133 |
128 /** |
134 /** |
129 * Get the current step. |
135 * Get the current step. |
434 jQuery('#height').val(c.height); |
452 jQuery('#height').val(c.height); |
435 } |
453 } |
436 }); |
454 }); |
437 }); |
455 }); |
438 </script> |
456 </script> |
439 <?php |
457 <?php |
440 } |
458 } |
441 |
459 |
442 /** |
460 /** |
443 * Display first step of custom header image page. |
461 * Display first step of custom header image page. |
444 * |
462 * |
445 * @since 2.1.0 |
463 * @since 2.1.0 |
446 */ |
464 */ |
447 public function step_1() { |
465 public function step_1() { |
448 $this->process_default_headers(); |
466 $this->process_default_headers(); |
449 ?> |
467 ?> |
450 |
468 |
451 <div class="wrap"> |
469 <div class="wrap"> |
452 <h1><?php _e( 'Custom Header' ); ?></h1> |
470 <h1><?php _e( 'Custom Header' ); ?></h1> |
453 |
471 |
454 <?php if ( current_user_can( 'customize' ) ) { ?> |
472 <?php if ( current_user_can( 'customize' ) ) { ?> |
455 <div class="notice notice-info hide-if-no-customize"> |
473 <div class="notice notice-info hide-if-no-customize"> |
456 <p> |
474 <p> |
457 <?php |
475 <?php |
458 printf( |
476 printf( |
459 __( 'You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.' ), |
477 __( 'You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.' ), |
460 admin_url( 'customize.php?autofocus[control]=header_image' ) |
478 admin_url( 'customize.php?autofocus[control]=header_image' ) |
461 ); |
479 ); |
462 ?> |
480 ?> |
463 </p> |
481 </p> |
464 </div> |
482 </div> |
465 <?php } ?> |
483 <?php } ?> |
466 |
484 |
467 <?php if ( ! empty( $this->updated ) ) { ?> |
485 <?php if ( ! empty( $this->updated ) ) { ?> |
468 <div id="message" class="updated"> |
486 <div id="message" class="updated"> |
469 <p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> |
487 <p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> |
470 </div> |
488 </div> |
471 <?php } ?> |
489 <?php } ?> |
472 |
490 |
473 <h3><?php _e( 'Header Image' ); ?></h3> |
491 <h2><?php _e( 'Header Image' ); ?></h2> |
474 |
492 |
475 <table class="form-table"> |
493 <table class="form-table" role="presentation"> |
476 <tbody> |
494 <tbody> |
477 |
495 |
478 <?php if ( get_custom_header() || display_header_text() ) : ?> |
496 <?php if ( get_custom_header() || display_header_text() ) : ?> |
479 <tr> |
497 <tr> |
480 <th scope="row"><?php _e( 'Preview' ); ?></th> |
498 <th scope="row"><?php _e( 'Preview' ); ?></th> |
481 <td> |
499 <td> |
482 <?php |
500 <?php |
483 if ( $this->admin_image_div_callback ) { |
501 if ( $this->admin_image_div_callback ) { |
484 call_user_func( $this->admin_image_div_callback ); |
502 call_user_func( $this->admin_image_div_callback ); |
485 } else { |
503 } else { |
486 $custom_header = get_custom_header(); |
504 $custom_header = get_custom_header(); |
487 $header_image = get_header_image(); |
505 $header_image = get_header_image(); |
488 |
506 |
489 if ( $header_image ) { |
507 if ( $header_image ) { |
490 $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');'; |
508 $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');'; |
491 } else { |
509 } else { |
492 $header_image_style = ''; |
510 $header_image_style = ''; |
493 } |
511 } |
494 |
512 |
495 if ( $custom_header->width ) |
513 if ( $custom_header->width ) { |
496 $header_image_style .= 'max-width:' . $custom_header->width . 'px;'; |
514 $header_image_style .= 'max-width:' . $custom_header->width . 'px;'; |
497 if ( $custom_header->height ) |
515 } |
498 $header_image_style .= 'height:' . $custom_header->height . 'px;'; |
516 if ( $custom_header->height ) { |
499 ?> |
517 $header_image_style .= 'height:' . $custom_header->height . 'px;'; |
|
518 } |
|
519 ?> |
500 <div id="headimg" style="<?php echo $header_image_style; ?>"> |
520 <div id="headimg" style="<?php echo $header_image_style; ?>"> |
501 <?php |
521 <?php |
502 if ( display_header_text() ) |
522 if ( display_header_text() ) { |
503 $style = ' style="color:#' . get_header_textcolor() . ';"'; |
523 $style = ' style="color:#' . get_header_textcolor() . ';"'; |
504 else |
524 } else { |
505 $style = ' style="display:none;"'; |
525 $style = ' style="display:none;"'; |
506 ?> |
526 } |
507 <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1> |
527 ?> |
|
528 <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo( 'url' ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1> |
508 <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> |
529 <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> |
509 </div> |
530 </div> |
510 <?php } ?> |
531 <?php } ?> |
511 </td> |
532 </td> |
512 </tr> |
533 </tr> |
513 <?php endif; ?> |
534 <?php endif; ?> |
514 |
535 |
515 <?php if ( current_user_can( 'upload_files' ) && current_theme_supports( 'custom-header', 'uploads' ) ) : ?> |
536 <?php if ( current_user_can( 'upload_files' ) && current_theme_supports( 'custom-header', 'uploads' ) ) : ?> |
516 <tr> |
537 <tr> |
517 <th scope="row"><?php _e( 'Select Image' ); ?></th> |
538 <th scope="row"><?php _e( 'Select Image' ); ?></th> |
518 <td> |
539 <td> |
519 <p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br /> |
540 <p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br /> |
520 <?php |
541 <?php |
521 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
542 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
522 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) ); |
543 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) ); |
523 } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { |
544 } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { |
524 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) |
545 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
525 printf( |
546 printf( |
526 /* translators: %s: size in pixels */ |
547 /* translators: %s: size in pixels */ |
527 __( 'Images should be at least %s wide.' ) . ' ', |
548 __( 'Images should be at least %s wide.' ) . ' ', |
528 sprintf( |
549 sprintf( |
529 /* translators: %d: custom header width */ |
550 /* translators: %d: custom header width */ |
530 '<strong>' . __( '%d pixels' ) . '</strong>', |
551 '<strong>' . __( '%d pixels' ) . '</strong>', |
531 get_theme_support( 'custom-header', 'width' ) |
552 get_theme_support( 'custom-header', 'width' ) |
532 ) |
553 ) |
533 ); |
554 ); |
534 } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
555 } |
535 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) |
556 } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
536 printf( |
557 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { |
537 /* translators: %s: size in pixels */ |
558 printf( |
538 __( 'Images should be at least %s tall.' ) . ' ', |
559 /* translators: %s: size in pixels */ |
539 sprintf( |
560 __( 'Images should be at least %s tall.' ) . ' ', |
540 /* translators: %d: custom header height */ |
561 sprintf( |
541 '<strong>' . __( '%d pixels' ) . '</strong>', |
562 /* translators: %d: custom header height */ |
542 get_theme_support( 'custom-header', 'height' ) |
563 '<strong>' . __( '%d pixels' ) . '</strong>', |
543 ) |
564 get_theme_support( 'custom-header', 'height' ) |
544 ); |
565 ) |
545 } |
566 ); |
546 if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) { |
567 } |
547 if ( current_theme_supports( 'custom-header', 'width' ) ) |
568 } |
548 printf( |
569 if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) { |
549 /* translators: %s: size in pixels */ |
570 if ( current_theme_supports( 'custom-header', 'width' ) ) { |
550 __( 'Suggested width is %s.' ) . ' ', |
571 printf( |
551 sprintf( |
572 /* translators: %s: size in pixels */ |
552 /* translators: %d: custom header width */ |
573 __( 'Suggested width is %s.' ) . ' ', |
553 '<strong>' . __( '%d pixels' ) . '</strong>', |
574 sprintf( |
554 get_theme_support( 'custom-header', 'width' ) |
575 /* translators: %d: custom header width */ |
555 ) |
576 '<strong>' . __( '%d pixels' ) . '</strong>', |
556 ); |
577 get_theme_support( 'custom-header', 'width' ) |
557 if ( current_theme_supports( 'custom-header', 'height' ) ) |
578 ) |
558 printf( |
579 ); |
559 /* translators: %s: size in pixels */ |
580 } |
560 __( 'Suggested height is %s.' ) . ' ', |
581 if ( current_theme_supports( 'custom-header', 'height' ) ) { |
561 sprintf( |
582 printf( |
562 /* translators: %d: custom header height */ |
583 /* translators: %s: size in pixels */ |
563 '<strong>' . __( '%d pixels' ) . '</strong>', |
584 __( 'Suggested height is %s.' ) . ' ', |
564 get_theme_support( 'custom-header', 'height' ) |
585 sprintf( |
565 ) |
586 /* translators: %d: custom header height */ |
566 ); |
587 '<strong>' . __( '%d pixels' ) . '</strong>', |
567 } |
588 get_theme_support( 'custom-header', 'height' ) |
568 ?></p> |
589 ) |
569 <form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ) ?>"> |
590 ); |
|
591 } |
|
592 } |
|
593 ?> |
|
594 </p> |
|
595 <form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>"> |
570 <p> |
596 <p> |
571 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
597 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
572 <input type="file" id="upload" name="import" /> |
598 <input type="file" id="upload" name="import" /> |
573 <input type="hidden" name="action" value="save" /> |
599 <input type="hidden" name="action" value="save" /> |
574 <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?> |
600 <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?> |
575 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> |
601 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> |
576 </p> |
602 </p> |
577 <?php |
603 <?php |
578 $modal_update_href = esc_url( add_query_arg( array( |
604 $modal_update_href = esc_url( |
579 'page' => 'custom-header', |
605 add_query_arg( |
580 'step' => 2, |
606 array( |
581 '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'), |
607 'page' => 'custom-header', |
582 ), admin_url('themes.php') ) ); |
608 'step' => 2, |
583 ?> |
609 '_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ), |
|
610 ), |
|
611 admin_url( 'themes.php' ) |
|
612 ) |
|
613 ); |
|
614 ?> |
584 <p> |
615 <p> |
585 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
616 <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
586 <button id="choose-from-library-link" class="button" |
617 <button id="choose-from-library-link" class="button" |
587 data-update-link="<?php echo esc_attr( $modal_update_href ); ?>" |
618 data-update-link="<?php echo esc_attr( $modal_update_href ); ?>" |
588 data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>" |
619 data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>" |
589 data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button> |
620 data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button> |
590 </p> |
621 </p> |
591 </form> |
622 </form> |
592 </td> |
623 </td> |
593 </tr> |
624 </tr> |
594 <?php endif; ?> |
625 <?php endif; ?> |
595 </tbody> |
626 </tbody> |
596 </table> |
627 </table> |
597 |
628 |
598 <form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ) ?>"> |
629 <form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ); ?>"> |
599 <?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?> |
630 <?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?> |
600 <table class="form-table"> |
631 <table class="form-table" role="presentation"> |
601 <tbody> |
632 <tbody> |
602 <?php if ( get_uploaded_header_images() ) : ?> |
633 <?php if ( get_uploaded_header_images() ) : ?> |
603 <tr> |
634 <tr> |
604 <th scope="row"><?php _e( 'Uploaded Images' ); ?></th> |
635 <th scope="row"><?php _e( 'Uploaded Images' ); ?></th> |
605 <td> |
636 <td> |
606 <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ) ?></p> |
637 <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ); ?></p> |
607 <?php |
638 <?php |
608 $this->show_header_selector( 'uploaded' ); |
639 $this->show_header_selector( 'uploaded' ); |
609 ?> |
640 ?> |
610 </td> |
641 </td> |
611 </tr> |
642 </tr> |
612 <?php endif; |
643 <?php |
613 if ( ! empty( $this->default_headers ) ) : ?> |
644 endif; |
|
645 if ( ! empty( $this->default_headers ) ) : |
|
646 ?> |
614 <tr> |
647 <tr> |
615 <th scope="row"><?php _e( 'Default Images' ); ?></th> |
648 <th scope="row"><?php _e( 'Default Images' ); ?></th> |
616 <td> |
649 <td> |
617 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?> |
650 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?> |
618 <p><?php _e( 'If you don‘t want to upload your own image, you can use one of these cool headers, or show a random one.' ) ?></p> |
651 <p><?php _e( 'If you don‘t want to upload your own image, you can use one of these cool headers, or show a random one.' ); ?></p> |
619 <?php else: ?> |
652 <?php else : ?> |
620 <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ) ?></p> |
653 <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ); ?></p> |
621 <?php endif; ?> |
654 <?php endif; ?> |
622 <?php |
655 <?php |
623 $this->show_header_selector( 'default' ); |
656 $this->show_header_selector( 'default' ); |
624 ?> |
657 ?> |
625 </td> |
658 </td> |
626 </tr> |
659 </tr> |
627 <?php endif; |
660 <?php |
628 if ( get_header_image() ) : ?> |
661 endif; |
|
662 if ( get_header_image() ) : |
|
663 ?> |
629 <tr> |
664 <tr> |
630 <th scope="row"><?php _e( 'Remove Image' ); ?></th> |
665 <th scope="row"><?php _e( 'Remove Image' ); ?></th> |
631 <td> |
666 <td> |
632 <p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?></p> |
667 <p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ); ?></p> |
633 <?php submit_button( __( 'Remove Header Image' ), '', 'removeheader', false ); ?> |
668 <?php submit_button( __( 'Remove Header Image' ), '', 'removeheader', false ); ?> |
634 </td> |
669 </td> |
635 </tr> |
670 </tr> |
636 <?php endif; |
671 <?php |
637 |
672 endif; |
638 $default_image = sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ); |
673 |
639 if ( $default_image && get_header_image() != $default_image ) : ?> |
674 $default_image = sprintf( get_theme_support( 'custom-header', 'default-image' ), get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
675 if ( $default_image && get_header_image() != $default_image ) : |
|
676 ?> |
640 <tr> |
677 <tr> |
641 <th scope="row"><?php _e( 'Reset Image' ); ?></th> |
678 <th scope="row"><?php _e( 'Reset Image' ); ?></th> |
642 <td> |
679 <td> |
643 <p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></p> |
680 <p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ); ?></p> |
644 <?php submit_button( __( 'Restore Original Header Image' ), '', 'resetheader', false ); ?> |
681 <?php submit_button( __( 'Restore Original Header Image' ), '', 'resetheader', false ); ?> |
645 </td> |
682 </td> |
646 </tr> |
683 </tr> |
647 <?php endif; ?> |
684 <?php endif; ?> |
648 </tbody> |
685 </tbody> |
649 </table> |
686 </table> |
650 |
687 |
651 <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?> |
688 <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?> |
652 |
689 |
653 <h3><?php _e( 'Header Text' ); ?></h3> |
690 <h2><?php _e( 'Header Text' ); ?></h2> |
654 |
691 |
655 <table class="form-table"> |
692 <table class="form-table" role="presentation"> |
656 <tbody> |
693 <tbody> |
657 <tr> |
694 <tr> |
658 <th scope="row"><?php _e( 'Header Text' ); ?></th> |
695 <th scope="row"><?php _e( 'Header Text' ); ?></th> |
659 <td> |
696 <td> |
660 <p> |
697 <p> |
665 |
702 |
666 <tr class="displaying-header-text"> |
703 <tr class="displaying-header-text"> |
667 <th scope="row"><?php _e( 'Text Color' ); ?></th> |
704 <th scope="row"><?php _e( 'Text Color' ); ?></th> |
668 <td> |
705 <td> |
669 <p> |
706 <p> |
670 <?php |
707 <?php |
671 $default_color = ''; |
708 $default_color = ''; |
672 if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
709 if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
673 $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
710 $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
674 if ( $default_color && false === strpos( $default_color, '#' ) ) { |
711 if ( $default_color && false === strpos( $default_color, '#' ) ) { |
675 $default_color = '#' . $default_color; |
712 $default_color = '#' . $default_color; |
676 } |
713 } |
677 } |
714 } |
678 |
715 |
679 $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : ''; |
716 $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : ''; |
680 |
717 |
681 $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' ); |
718 $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' ); |
682 if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) { |
719 if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) { |
683 $header_textcolor = '#' . $header_textcolor; |
720 $header_textcolor = '#' . $header_textcolor; |
684 } |
721 } |
685 |
722 |
686 echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />'; |
723 echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />'; |
687 if ( $default_color ) { |
724 if ( $default_color ) { |
688 echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>'; |
725 echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>'; |
689 } |
726 } |
690 ?> |
727 ?> |
691 </p> |
728 </p> |
692 </td> |
729 </td> |
693 </tr> |
730 </tr> |
694 </tbody> |
731 </tbody> |
695 </table> |
732 </table> |
696 <?php endif; |
733 <?php |
697 |
734 endif; |
698 /** |
735 |
699 * Fires just before the submit button in the custom header options form. |
736 /** |
700 * |
737 * Fires just before the submit button in the custom header options form. |
701 * @since 3.1.0 |
738 * |
702 */ |
739 * @since 3.1.0 |
703 do_action( 'custom_header_options' ); |
740 */ |
704 |
741 do_action( 'custom_header_options' ); |
705 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> |
742 |
706 |
743 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); |
707 <?php submit_button( null, 'primary', 'save-header-options' ); ?> |
744 ?> |
|
745 |
|
746 <?php submit_button( null, 'primary', 'save-header-options' ); ?> |
708 </form> |
747 </form> |
709 </div> |
748 </div> |
710 |
749 |
711 <?php } |
750 <?php |
|
751 } |
712 |
752 |
713 /** |
753 /** |
714 * Display second step of custom header image page. |
754 * Display second step of custom header image page. |
715 * |
755 * |
716 * @since 2.1.0 |
756 * @since 2.1.0 |
717 */ |
757 */ |
718 public function step_2() { |
758 public function step_2() { |
719 check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload'); |
759 check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' ); |
720 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
760 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
721 wp_die( |
761 wp_die( |
722 '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
762 '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
723 '<p>' . __( 'The current theme does not support uploading a custom header image.' ) . '</p>', |
763 '<p>' . __( 'The current theme does not support uploading a custom header image.' ) . '</p>', |
724 403 |
764 403 |
725 ); |
765 ); |
726 } |
766 } |
727 |
767 |
728 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { |
768 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { |
729 $attachment_id = absint( $_GET['file'] ); |
769 $attachment_id = absint( $_GET['file'] ); |
730 $file = get_attached_file( $attachment_id, true ); |
770 $file = get_attached_file( $attachment_id, true ); |
731 $url = wp_get_attachment_image_src( $attachment_id, 'full' ); |
771 $url = wp_get_attachment_image_src( $attachment_id, 'full' ); |
732 $url = $url[0]; |
772 $url = $url[0]; |
733 } elseif ( isset( $_POST ) ) { |
773 } elseif ( isset( $_POST ) ) { |
734 $data = $this->step_2_manage_upload(); |
774 $data = $this->step_2_manage_upload(); |
735 $attachment_id = $data['attachment_id']; |
775 $attachment_id = $data['attachment_id']; |
736 $file = $data['file']; |
776 $file = $data['file']; |
737 $url = $data['url']; |
777 $url = $data['url']; |
738 } |
778 } |
739 |
779 |
740 if ( file_exists( $file ) ) { |
780 if ( file_exists( $file ) ) { |
741 list( $width, $height, $type, $attr ) = getimagesize( $file ); |
781 list( $width, $height, $type, $attr ) = getimagesize( $file ); |
742 } else { |
782 } else { |
743 $data = wp_get_attachment_metadata( $attachment_id ); |
783 $data = wp_get_attachment_metadata( $attachment_id ); |
744 $height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0; |
784 $height = isset( $data['height'] ) ? $data['height'] : 0; |
745 $width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0; |
785 $width = isset( $data['width'] ) ? $data['width'] : 0; |
746 unset( $data ); |
786 unset( $data ); |
747 } |
787 } |
748 |
788 |
749 $max_width = 0; |
789 $max_width = 0; |
750 // For flex, limit size of image displayed to 1500px unless theme says otherwise |
790 // For flex, limit size of image displayed to 1500px unless theme says otherwise |
751 if ( current_theme_supports( 'custom-header', 'flex-width' ) ) |
791 if ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
752 $max_width = 1500; |
792 $max_width = 1500; |
753 |
793 } |
754 if ( current_theme_supports( 'custom-header', 'max-width' ) ) |
794 |
|
795 if ( current_theme_supports( 'custom-header', 'max-width' ) ) { |
755 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
796 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
|
797 } |
756 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); |
798 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); |
757 |
799 |
758 // If flexible height isn't supported and the image is the exact right size |
800 // If flexible height isn't supported and the image is the exact right size |
759 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) |
801 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) |
760 && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) |
802 && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) { |
761 { |
|
762 // Add the meta-data |
803 // Add the meta-data |
763 if ( file_exists( $file ) ) |
804 if ( file_exists( $file ) ) { |
764 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
805 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
806 } |
765 |
807 |
766 $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
808 $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
767 |
809 |
768 /** |
810 /** |
769 * Fires after the header image is set or an error is returned. |
811 * Fires after the header image is set or an error is returned. |
776 do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication |
818 do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication |
777 |
819 |
778 return $this->finished(); |
820 return $this->finished(); |
779 } elseif ( $width > $max_width ) { |
821 } elseif ( $width > $max_width ) { |
780 $oitar = $width / $max_width; |
822 $oitar = $width / $max_width; |
781 $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); |
823 $image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) ); |
782 if ( ! $image || is_wp_error( $image ) ) |
824 if ( ! $image || is_wp_error( $image ) ) { |
783 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
825 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
826 } |
784 |
827 |
785 /** This filter is documented in wp-admin/custom-header.php */ |
828 /** This filter is documented in wp-admin/custom-header.php */ |
786 $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication |
829 $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication |
787 |
830 |
788 $url = str_replace(basename($url), basename($image), $url); |
831 $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url ); |
789 $width = $width / $oitar; |
832 $width = $width / $oitar; |
790 $height = $height / $oitar; |
833 $height = $height / $oitar; |
791 } else { |
834 } else { |
792 $oitar = 1; |
835 $oitar = 1; |
793 } |
836 } |
794 ?> |
837 ?> |
795 |
838 |
796 <div class="wrap"> |
839 <div class="wrap"> |
797 <h1><?php _e( 'Crop Header Image' ); ?></h1> |
840 <h1><?php _e( 'Crop Header Image' ); ?></h1> |
798 |
841 |
799 <form method="post" action="<?php echo esc_url(add_query_arg('step', 3)); ?>"> |
842 <form method="post" action="<?php echo esc_url( add_query_arg( 'step', 3 ) ); ?>"> |
800 <p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p> |
843 <p class="hide-if-no-js"><?php _e( 'Choose the part of the image you want to use as your header.' ); ?></p> |
801 <p class="hide-if-js"><strong><?php _e( 'You need JavaScript to choose a part of the image.'); ?></strong></p> |
844 <p class="hide-if-js"><strong><?php _e( 'You need JavaScript to choose a part of the image.' ); ?></strong></p> |
802 |
845 |
803 <div id="crop_image" style="position: relative"> |
846 <div id="crop_image" style="position: relative"> |
804 <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="" /> |
847 <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="" /> |
805 </div> |
848 </div> |
806 |
849 |
890 403 |
936 403 |
891 ); |
937 ); |
892 } |
938 } |
893 |
939 |
894 if ( $_POST['oitar'] > 1 ) { |
940 if ( $_POST['oitar'] > 1 ) { |
895 $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; |
941 $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; |
896 $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; |
942 $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; |
897 $_POST['width'] = $_POST['width'] * $_POST['oitar']; |
943 $_POST['width'] = $_POST['width'] * $_POST['oitar']; |
898 $_POST['height'] = $_POST['height'] * $_POST['oitar']; |
944 $_POST['height'] = $_POST['height'] * $_POST['oitar']; |
899 } |
945 } |
900 |
946 |
901 $attachment_id = absint( $_POST['attachment_id'] ); |
947 $attachment_id = absint( $_POST['attachment_id'] ); |
902 $original = get_attached_file($attachment_id); |
948 $original = get_attached_file( $attachment_id ); |
903 |
949 |
904 $dimensions = $this->get_header_dimensions( array( |
950 $dimensions = $this->get_header_dimensions( |
905 'height' => $_POST['height'], |
951 array( |
906 'width' => $_POST['width'], |
952 'height' => $_POST['height'], |
907 ) ); |
953 'width' => $_POST['width'], |
908 $height = $dimensions['dst_height']; |
954 ) |
909 $width = $dimensions['dst_width']; |
955 ); |
910 |
956 $height = $dimensions['dst_height']; |
911 if ( empty( $_POST['skip-cropping'] ) ) |
957 $width = $dimensions['dst_width']; |
|
958 |
|
959 if ( empty( $_POST['skip-cropping'] ) ) { |
912 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $width, $height ); |
960 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $width, $height ); |
913 elseif ( ! empty( $_POST['create-new-attachment'] ) ) |
961 } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { |
914 $cropped = _copy_image_file( $attachment_id ); |
962 $cropped = _copy_image_file( $attachment_id ); |
915 else |
963 } else { |
916 $cropped = get_attached_file( $attachment_id ); |
964 $cropped = get_attached_file( $attachment_id ); |
917 |
965 } |
918 if ( ! $cropped || is_wp_error( $cropped ) ) |
966 |
|
967 if ( ! $cropped || is_wp_error( $cropped ) ) { |
919 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
968 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
969 } |
920 |
970 |
921 /** This filter is documented in wp-admin/custom-header.php */ |
971 /** This filter is documented in wp-admin/custom-header.php */ |
922 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication |
972 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication |
923 |
973 |
924 $object = $this->create_attachment_object( $cropped, $attachment_id ); |
974 $object = $this->create_attachment_object( $cropped, $attachment_id ); |
925 |
975 |
926 if ( ! empty( $_POST['create-new-attachment'] ) ) |
976 if ( ! empty( $_POST['create-new-attachment'] ) ) { |
927 unset( $object['ID'] ); |
977 unset( $object['ID'] ); |
|
978 } |
928 |
979 |
929 // Update the attachment |
980 // Update the attachment |
930 $attachment_id = $this->insert_attachment( $object, $cropped ); |
981 $attachment_id = $this->insert_attachment( $object, $cropped ); |
931 |
982 |
932 $url = wp_get_attachment_url( $attachment_id ); |
983 $url = wp_get_attachment_url( $attachment_id ); |
933 $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
984 $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
934 |
985 |
935 // Cleanup. |
986 // Cleanup. |
936 $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original ); |
987 $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original ); |
937 if ( file_exists( $medium ) ) { |
988 if ( file_exists( $medium ) ) { |
938 wp_delete_file( $medium ); |
989 wp_delete_file( $medium ); |
939 } |
990 } |
940 |
991 |
941 if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) { |
992 if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) { |