~canonical-sysadmins/wordpress/4.7.4

« back to all changes in this revision

Viewing changes to wp-content/themes/twentyfourteen/inc/custom-header.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Implement Custom Header functionality for Twenty Fourteen
 
4
 *
 
5
 * @package WordPress
 
6
 * @subpackage Twenty_Fourteen
 
7
 * @since Twenty Fourteen 1.0
 
8
 */
 
9
 
 
10
/**
 
11
 * Set up the WordPress core custom header settings.
 
12
 *
 
13
 * @since Twenty Fourteen 1.0
 
14
 *
 
15
 * @uses twentyfourteen_header_style()
 
16
 * @uses twentyfourteen_admin_header_style()
 
17
 * @uses twentyfourteen_admin_header_image()
 
18
 */
 
19
function twentyfourteen_custom_header_setup() {
 
20
        /**
 
21
         * Filter Twenty Fourteen custom-header support arguments.
 
22
         *
 
23
         * @since Twenty Fourteen 1.0
 
24
         *
 
25
         * @param array $args {
 
26
         *     An array of custom-header support arguments.
 
27
         *
 
28
         *     @type bool   $header_text            Whether to display custom header text. Default false.
 
29
         *     @type int    $width                  Width in pixels of the custom header image. Default 1260.
 
30
         *     @type int    $height                 Height in pixels of the custom header image. Default 240.
 
31
         *     @type bool   $flex_height            Whether to allow flexible-height header images. Default true.
 
32
         *     @type string $admin_head_callback    Callback function used to style the image displayed in
 
33
         *                                          the Appearance > Header screen.
 
34
         *     @type string $admin_preview_callback Callback function used to create the custom header markup in
 
35
         *                                          the Appearance > Header screen.
 
36
         * }
 
37
         */
 
38
        add_theme_support( 'custom-header', apply_filters( 'twentyfourteen_custom_header_args', array(
 
39
                'default-text-color'     => 'fff',
 
40
                'width'                  => 1260,
 
41
                'height'                 => 240,
 
42
                'flex-height'            => true,
 
43
                'wp-head-callback'       => 'twentyfourteen_header_style',
 
44
                'admin-head-callback'    => 'twentyfourteen_admin_header_style',
 
45
                'admin-preview-callback' => 'twentyfourteen_admin_header_image',
 
46
        ) ) );
 
47
}
 
48
add_action( 'after_setup_theme', 'twentyfourteen_custom_header_setup' );
 
49
 
 
50
if ( ! function_exists( 'twentyfourteen_header_style' ) ) :
 
51
/**
 
52
 * Styles the header image and text displayed on the blog
 
53
 *
 
54
 * @see twentyfourteen_custom_header_setup().
 
55
 *
 
56
 */
 
57
function twentyfourteen_header_style() {
 
58
        $text_color = get_header_textcolor();
 
59
 
 
60
        // If no custom color for text is set, let's bail.
 
61
        if ( display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) )
 
62
                return;
 
63
 
 
64
        // If we get this far, we have custom styles.
 
65
        ?>
 
66
        <style type="text/css" id="twentyfourteen-header-css">
 
67
        <?php
 
68
                // Has the text been hidden?
 
69
                if ( ! display_header_text() ) :
 
70
        ?>
 
71
                .site-title,
 
72
                .site-description {
 
73
                        clip: rect(1px 1px 1px 1px); /* IE7 */
 
74
                        clip: rect(1px, 1px, 1px, 1px);
 
75
                        position: absolute;
 
76
                }
 
77
        <?php
 
78
                // If the user has set a custom color for the text, use that.
 
79
                elseif ( $text_color != get_theme_support( 'custom-header', 'default-text-color' ) ) :
 
80
        ?>
 
81
                .site-title a {
 
82
                        color: #<?php echo esc_attr( $text_color ); ?>;
 
83
                }
 
84
        <?php endif; ?>
 
85
        </style>
 
86
        <?php
 
87
}
 
88
endif; // twentyfourteen_header_style
 
89
 
 
90
 
 
91
if ( ! function_exists( 'twentyfourteen_admin_header_style' ) ) :
 
92
/**
 
93
 * Style the header image displayed on the Appearance > Header screen.
 
94
 *
 
95
 * @see twentyfourteen_custom_header_setup()
 
96
 *
 
97
 * @since Twenty Fourteen 1.0
 
98
 */
 
99
function twentyfourteen_admin_header_style() {
 
100
?>
 
101
        <style type="text/css" id="twentyfourteen-admin-header-css">
 
102
        .appearance_page_custom-header #headimg {
 
103
                background-color: #000;
 
104
                border: none;
 
105
                max-width: 1260px;
 
106
                min-height: 48px;
 
107
        }
 
108
        #headimg h1 {
 
109
                font-family: Lato, sans-serif;
 
110
                font-size: 18px;
 
111
                line-height: 48px;
 
112
                margin: 0 0 0 30px;
 
113
        }
 
114
        .rtl #headimg h1  {
 
115
                margin: 0 30px 0 0;
 
116
        }
 
117
        #headimg h1 a {
 
118
                color: #fff;
 
119
                text-decoration: none;
 
120
        }
 
121
        #headimg img {
 
122
                vertical-align: middle;
 
123
        }
 
124
        </style>
 
125
<?php
 
126
}
 
127
endif; // twentyfourteen_admin_header_style
 
128
 
 
129
if ( ! function_exists( 'twentyfourteen_admin_header_image' ) ) :
 
130
/**
 
131
 * Create the custom header image markup displayed on the Appearance > Header screen.
 
132
 *
 
133
 * @see twentyfourteen_custom_header_setup()
 
134
 *
 
135
 * @since Twenty Fourteen 1.0
 
136
 */
 
137
function twentyfourteen_admin_header_image() {
 
138
?>
 
139
        <div id="headimg">
 
140
                <?php if ( get_header_image() ) : ?>
 
141
                <img src="<?php header_image(); ?>" alt="">
 
142
                <?php endif; ?>
 
143
                <h1 class="displaying-header-text"><a id="name"<?php echo sprintf( ' style="color:#%s;"', get_header_textcolor() ); ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
 
144
        </div>
 
145
<?php
 
146
}
 
147
endif; // twentyfourteen_admin_header_image