]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentytwelve/inc/custom-header.php
Wordpress 3.6
[autoinstalls/wordpress.git] / wp-content / themes / twentytwelve / inc / custom-header.php
1 <?php
2 /**
3  * Implements an optional custom header for Twenty Twelve.
4  * See http://codex.wordpress.org/Custom_Headers
5  *
6  * @package WordPress
7  * @subpackage Twenty_Twelve
8  * @since Twenty Twelve 1.0
9  */
10
11 /**
12  * Sets up the WordPress core custom header arguments and settings.
13  *
14  * @uses add_theme_support() to register support for 3.4 and up.
15  * @uses twentytwelve_header_style() to style front-end.
16  * @uses twentytwelve_admin_header_style() to style wp-admin form.
17  * @uses twentytwelve_admin_header_image() to add custom markup to wp-admin form.
18  *
19  * @since Twenty Twelve 1.0
20  */
21 function twentytwelve_custom_header_setup() {
22         $args = array(
23                 // Text color and image (empty to use none).
24                 'default-text-color'     => '515151',
25                 'default-image'          => '',
26
27                 // Set height and width, with a maximum value for the width.
28                 'height'                 => 250,
29                 'width'                  => 960,
30                 'max-width'              => 2000,
31
32                 // Support flexible height and width.
33                 'flex-height'            => true,
34                 'flex-width'             => true,
35
36                 // Random image rotation off by default.
37                 'random-default'         => false,
38
39                 // Callbacks for styling the header and the admin preview.
40                 'wp-head-callback'       => 'twentytwelve_header_style',
41                 'admin-head-callback'    => 'twentytwelve_admin_header_style',
42                 'admin-preview-callback' => 'twentytwelve_admin_header_image',
43         );
44
45         add_theme_support( 'custom-header', $args );
46 }
47 add_action( 'after_setup_theme', 'twentytwelve_custom_header_setup' );
48
49 /**
50  * Loads our special font CSS file.
51  *
52  * @since Twenty Twelve 1.2
53  *
54  * @return void
55  */
56 function twentytwelve_custom_header_fonts() {
57         $font_url = twentytwelve_get_font_url();
58         if ( ! empty( $font_url ) )
59                 wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
60 }
61 add_action( 'admin_print_styles-appearance_page_custom-header', 'twentytwelve_custom_header_fonts' );
62
63 /**
64  * Styles the header text displayed on the blog.
65  *
66  * get_header_textcolor() options: 515151 is default, hide text (returns 'blank'), or any hex value.
67  *
68  * @since Twenty Twelve 1.0
69  */
70 function twentytwelve_header_style() {
71         $text_color = get_header_textcolor();
72
73         // If no custom options for text are set, let's bail
74         if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
75                 return;
76
77         // If we get this far, we have custom styles.
78         ?>
79         <style type="text/css" id="twentytwelve-header-css">
80         <?php
81                 // Has the text been hidden?
82                 if ( ! display_header_text() ) :
83         ?>
84                 .site-title,
85                 .site-description {
86                         position: absolute;
87                         clip: rect(1px 1px 1px 1px); /* IE7 */
88                         clip: rect(1px, 1px, 1px, 1px);
89                 }
90         <?php
91                 // If the user has set a custom color for the text, use that.
92                 else :
93         ?>
94                 .site-header h1 a,
95                 .site-header h2 {
96                         color: #<?php echo $text_color; ?>;
97                 }
98         <?php endif; ?>
99         </style>
100         <?php
101 }
102
103 /**
104  * Styles the header image displayed on the Appearance > Header admin panel.
105  *
106  * @since Twenty Twelve 1.0
107  */
108 function twentytwelve_admin_header_style() {
109 ?>
110         <style type="text/css" id="twentytwelve-admin-header-css">
111         .appearance_page_custom-header #headimg {
112                 border: none;
113                 font-family: "Open Sans", Helvetica, Arial, sans-serif;
114         }
115         #headimg h1,
116         #headimg h2 {
117                 line-height: 1.84615;
118                 margin: 0;
119                 padding: 0;
120         }
121         #headimg h1 {
122                 font-size: 26px;
123         }
124         #headimg h1 a {
125                 color: #515151;
126                 text-decoration: none;
127         }
128         #headimg h1 a:hover {
129                 color: #21759b !important; /* Has to override custom inline style. */
130         }
131         #headimg h2 {
132                 color: #757575;
133                 font-size: 13px;
134                 margin-bottom: 24px;
135         }
136         #headimg img {
137                 max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px;
138         }
139         </style>
140 <?php
141 }
142
143 /**
144  * Outputs markup to be displayed on the Appearance > Header admin panel.
145  * This callback overrides the default markup displayed there.
146  *
147  * @since Twenty Twelve 1.0
148  */
149 function twentytwelve_admin_header_image() {
150         ?>
151         <div id="headimg">
152                 <?php
153                 if ( ! display_header_text() )
154                         $style = ' style="display:none;"';
155                 else
156                         $style = ' style="color:#' . get_header_textcolor() . ';"';
157                 ?>
158                 <h1 class="displaying-header-text"><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
159                 <h2 id="desc" class="displaying-header-text"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2>
160                 <?php $header_image = get_header_image();
161                 if ( ! empty( $header_image ) ) : ?>
162                         <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
163                 <?php endif; ?>
164         </div>
165 <?php }