1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Functions and template tags for using site logos. |
4
|
|
|
* |
5
|
|
|
* @package Jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Retrieve the site logo URL or ID (URL by default). Pass in the string 'id' for ID. |
10
|
|
|
* |
11
|
|
|
* @uses get_option() |
12
|
|
|
* @uses esc_url_raw() |
13
|
|
|
* @uses set_url_scheme() |
14
|
|
|
* @return mixed The URL or ID of our site logo, false if not set |
15
|
|
|
* @since 1.0 |
16
|
|
|
*/ |
17
|
|
|
function jetpack_get_site_logo( $show = 'url' ) { |
18
|
|
|
$logo = site_logo()->logo; |
19
|
|
|
|
20
|
|
|
// Return false if no logo is set |
21
|
|
|
if ( ! isset( $logo['id'] ) || 0 == $logo['id'] ) { |
22
|
|
|
return false; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// Return the ID if specified, otherwise return the URL by default |
26
|
|
|
if ( 'id' == $show ) { |
27
|
|
|
return $logo['id']; |
28
|
|
|
} else { |
29
|
|
|
return esc_url_raw( set_url_scheme( $logo['url'] ) ); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Retrieve an array of the dimensions of the Site Logo. |
35
|
|
|
* |
36
|
|
|
* @uses Site_Logo::theme_size() |
37
|
|
|
* @uses get_option( 'thumbnail_size_w' ) |
38
|
|
|
* @uses get_option( 'thumbnail_size_h' ) |
39
|
|
|
* @uses global $_wp_additional_image_sizes; |
40
|
|
|
* |
41
|
|
|
* @since 3.6.0 |
42
|
|
|
* |
43
|
|
|
* @return array $dimensions { |
44
|
|
|
* An array of dimensions of the Site Logo. |
45
|
|
|
* |
46
|
|
|
* @type string $width Width of the logo in pixels. |
47
|
|
|
* @type string $height Height of the logo in pixels. |
48
|
|
|
* } |
49
|
|
|
*/ |
50
|
|
|
function jetpack_get_site_logo_dimensions() { |
51
|
|
|
// Get the image size to use with the logo. |
52
|
|
|
$size = site_logo()->theme_size(); |
53
|
|
|
|
54
|
|
|
// If the size is the default `thumbnail`, get its dimensions. Otherwise, get them from $_wp_additional_image_sizes |
55
|
|
|
if ( empty( $size ) ) { |
56
|
|
|
return false; |
57
|
|
|
} elseif ( 'thumbnail' == $size ) { |
58
|
|
|
$dimensions = array( |
59
|
|
|
'width' => get_option( 'thumbnail_size_w' ), |
60
|
|
|
'height' => get_option( 'thumbnail_size_h' ), |
61
|
|
|
); |
62
|
|
|
} else { |
63
|
|
|
global $_wp_additional_image_sizes; |
64
|
|
|
|
65
|
|
|
if ( ! isset( $_wp_additional_image_sizes[ $size ] ) ) { |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$dimensions = array( |
70
|
|
|
'width' => $_wp_additional_image_sizes[ $size ]['width'], |
71
|
|
|
'height' => $_wp_additional_image_sizes[ $size ]['height'], |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $dimensions; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Determine if a site logo is assigned or not. |
80
|
|
|
* |
81
|
|
|
* @uses get_option |
82
|
|
|
* @return boolean True if there is an active logo, false otherwise |
83
|
|
|
*/ |
84
|
|
|
function jetpack_has_site_logo() { |
85
|
|
|
return site_logo()->has_site_logo(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Output an <img> tag of the site logo, at the size specified |
90
|
|
|
* in the theme's add_theme_support() declaration. |
91
|
|
|
* |
92
|
|
|
* @uses Site_Logo::logo |
93
|
|
|
* @uses Site_Logo::theme_size() |
94
|
|
|
* @uses jetpack_has_site_logo() |
95
|
|
|
* @uses jetpack_is_customize_preview() |
96
|
|
|
* @uses esc_url() |
97
|
|
|
* @uses home_url() |
98
|
|
|
* @uses esc_attr() |
99
|
|
|
* @uses wp_get_attachment_image() |
100
|
|
|
* @uses apply_filters() |
101
|
|
|
* @since 1.0 |
102
|
|
|
*/ |
103
|
|
|
function jetpack_the_site_logo() { |
104
|
|
|
$logo = site_logo()->logo; |
105
|
|
|
$logo_id = get_theme_mod( 'custom_logo' ); // Check for WP 4.5 Site Logo |
106
|
|
|
$logo_id = $logo_id ? $logo_id : ( isset( $logo['id'] ) ? $logo['id'] : false ); // Use WP Core logo if present, otherwise use Jetpack's. |
107
|
|
|
$size = site_logo()->theme_size(); |
108
|
|
|
$html = ''; |
109
|
|
|
|
110
|
|
|
// If no logo is set, but we're in the Customizer, leave a placeholder (needed for the live preview). |
111
|
|
|
if ( ! jetpack_has_site_logo() ) { |
112
|
|
|
if ( jetpack_is_customize_preview() ) { |
113
|
|
|
$html = sprintf( |
114
|
|
|
'<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', |
115
|
|
|
esc_url( home_url( '/' ) ), |
116
|
|
|
esc_attr( $size ) |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
// We have a logo. Logo is go. |
122
|
|
|
else { |
123
|
|
|
$html = sprintf( |
124
|
|
|
'<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>', |
125
|
|
|
esc_url( home_url( '/' ) ), |
126
|
|
|
wp_get_attachment_image( |
127
|
|
|
$logo_id, |
128
|
|
|
$size, |
129
|
|
|
false, |
130
|
|
|
array( |
131
|
|
|
'class' => "site-logo attachment-$size", |
132
|
|
|
'data-size' => $size, |
133
|
|
|
'itemprop' => 'logo', |
134
|
|
|
) |
135
|
|
|
) |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Filter the Site Logo output. |
141
|
|
|
* |
142
|
|
|
* @module theme-tools |
143
|
|
|
* |
144
|
|
|
* @since 3.2.0 |
145
|
|
|
* |
146
|
|
|
* @param string $html Site Logo HTML output. |
147
|
|
|
* @param array $logo Array of Site Logo details. |
148
|
|
|
* @param string $size Size specified in add_theme_support declaration, or 'thumbnail' default. |
149
|
|
|
*/ |
150
|
|
|
echo apply_filters( 'jetpack_the_site_logo', $html, $logo, $size ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Whether the site is being previewed in the Customizer. |
155
|
|
|
* Duplicate of core function until 4.0 is released. |
156
|
|
|
* |
157
|
|
|
* @global WP_Customize_Manager $wp_customize Customizer instance. |
158
|
|
|
* @return bool True if the site is being previewed in the Customizer, false otherwise. |
159
|
|
|
*/ |
160
|
|
|
function jetpack_is_customize_preview() { |
161
|
|
|
global $wp_customize; |
162
|
|
|
|
163
|
|
|
return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Sanitize the string of classes used for header text. |
168
|
|
|
* Limit to A-Z,a-z,0-9,(space),(comma),_,- |
169
|
|
|
* |
170
|
|
|
* @return string Sanitized string of CSS classes. |
171
|
|
|
*/ |
172
|
|
|
function jetpack_sanitize_header_text_classes( $classes ) { |
173
|
|
|
$classes = preg_replace( '/[^A-Za-z0-9\,\ ._-]/', '', $classes ); |
174
|
|
|
|
175
|
|
|
return $classes; |
176
|
|
|
} |
177
|
|
|
|