]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentytwelve/inc/custom-header.php
WordPress 3.9-scripts
[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 function twentytwelve_custom_header_fonts() {
56         $font_url = twentytwelve_get_font_url();
57         if ( ! empty( $font_url ) )
58                 wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
59 }
60 add_action( 'admin_print_styles-appearance_page_custom-header', 'twentytwelve_custom_header_fonts' );
61
62 /**
63  * Style the header text displayed on the blog.
64  *
65  * get_header_textcolor() options: 515151 is default, hide text (returns 'blank'), or any hex value.
66  *
67  * @since Twenty Twelve 1.0
68  */
69 function twentytwelve_header_style() {
70         $text_color = get_header_textcolor();
71
72         // If no custom options for text are set, let's bail
73         if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
74                 return;
75
76         // If we get this far, we have custom styles.
77         ?>
78         <style type="text/css" id="twentytwelve-header-css">
79         <?php
80                 // Has the text been hidden?
81                 if ( ! display_header_text() ) :
82         ?>
83                 .site-title,
84                 .site-description {
85                         position: absolute;
86                         clip: rect(1px 1px 1px 1px); /* IE7 */
87                         clip: rect(1px, 1px, 1px, 1px);
88                 }
89         <?php
90                 // If the user has set a custom color for the text, use that.
91                 else :
92         ?>
93                 .site-header h1 a,
94                 .site-header h2 {
95                         color: #<?php echo $text_color; ?>;
96                 }
97         <?php endif; ?>
98         </style>
99         <?php
100 }
101
102 /**
103  * Style the header image displayed on the Appearance > Header admin panel.
104  *
105  * @since Twenty Twelve 1.0
106  */
107 function twentytwelve_admin_header_style() {
108 ?>
109         <style type="text/css" id="twentytwelve-admin-header-css">
110         .appearance_page_custom-header #headimg {
111                 border: none;
112                 font-family: "Open Sans", Helvetica, Arial, sans-serif;
113         }
114         #headimg h1,
115         #headimg h2 {
116                 line-height: 1.84615;
117                 margin: 0;
118                 padding: 0;
119         }
120         #headimg h1 {
121                 font-size: 26px;
122         }
123         #headimg h1 a {
124                 color: #515151;
125                 text-decoration: none;
126         }
127         #headimg h1 a:hover {
128                 color: #21759b !important; /* Has to override custom inline style. */
129         }
130         #headimg h2 {
131                 color: #757575;
132                 font-size: 13px;
133                 margin-bottom: 24px;
134         }
135         #headimg img {
136                 max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px;
137         }
138         </style>
139 <?php
140 }
141
142 /**
143  * Output markup to be displayed on the Appearance > Header admin panel.
144  *
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 }