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