author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* General template tags that can go anywhere in a template. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Load header template. |
|
11 |
* |
|
12 |
* Includes the header template for a theme or if a name is specified then a |
|
13 |
* specialised header will be included. |
|
14 |
* |
|
15 |
* For the parameter, if the file is called "header-special.php" then specify |
|
16 |
* "special". |
|
17 |
* |
|
18 |
* @since 1.5.0 |
|
19 |
* |
|
20 |
* @param string $name The name of the specialised header. |
|
21 |
*/ |
|
22 |
function get_header( $name = null ) { |
|
5 | 23 |
/** |
24 |
* Fires before the header template file is loaded. |
|
25 |
* |
|
26 |
* @since 2.1.0 |
|
27 |
* @since 2.8.0 $name parameter added. |
|
28 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
* @param string|null $name Name of the specific header file to use. null for the default header. |
5 | 30 |
*/ |
0 | 31 |
do_action( 'get_header', $name ); |
32 |
||
33 |
$templates = array(); |
|
34 |
$name = (string) $name; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
if ( '' !== $name ) { |
0 | 36 |
$templates[] = "header-{$name}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
} |
0 | 38 |
|
39 |
$templates[] = 'header.php'; |
|
40 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
locate_template( $templates, true ); |
0 | 42 |
} |
43 |
||
44 |
/** |
|
45 |
* Load footer template. |
|
46 |
* |
|
47 |
* Includes the footer template for a theme or if a name is specified then a |
|
48 |
* specialised footer will be included. |
|
49 |
* |
|
50 |
* For the parameter, if the file is called "footer-special.php" then specify |
|
51 |
* "special". |
|
52 |
* |
|
53 |
* @since 1.5.0 |
|
54 |
* |
|
55 |
* @param string $name The name of the specialised footer. |
|
56 |
*/ |
|
57 |
function get_footer( $name = null ) { |
|
5 | 58 |
/** |
59 |
* Fires before the footer template file is loaded. |
|
60 |
* |
|
61 |
* @since 2.1.0 |
|
62 |
* @since 2.8.0 $name parameter added. |
|
63 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* @param string|null $name Name of the specific footer file to use. null for the default footer. |
5 | 65 |
*/ |
0 | 66 |
do_action( 'get_footer', $name ); |
67 |
||
68 |
$templates = array(); |
|
69 |
$name = (string) $name; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
if ( '' !== $name ) { |
0 | 71 |
$templates[] = "footer-{$name}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
$templates[] = 'footer.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
locate_template( $templates, true ); |
0 | 77 |
} |
78 |
||
79 |
/** |
|
80 |
* Load sidebar template. |
|
81 |
* |
|
82 |
* Includes the sidebar template for a theme or if a name is specified then a |
|
83 |
* specialised sidebar will be included. |
|
84 |
* |
|
85 |
* For the parameter, if the file is called "sidebar-special.php" then specify |
|
86 |
* "special". |
|
87 |
* |
|
88 |
* @since 1.5.0 |
|
89 |
* |
|
90 |
* @param string $name The name of the specialised sidebar. |
|
91 |
*/ |
|
92 |
function get_sidebar( $name = null ) { |
|
5 | 93 |
/** |
94 |
* Fires before the sidebar template file is loaded. |
|
95 |
* |
|
96 |
* @since 2.2.0 |
|
97 |
* @since 2.8.0 $name parameter added. |
|
98 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. |
5 | 100 |
*/ |
0 | 101 |
do_action( 'get_sidebar', $name ); |
102 |
||
103 |
$templates = array(); |
|
104 |
$name = (string) $name; |
|
105 |
if ( '' !== $name ) |
|
106 |
$templates[] = "sidebar-{$name}.php"; |
|
107 |
||
108 |
$templates[] = 'sidebar.php'; |
|
109 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
locate_template( $templates, true ); |
0 | 111 |
} |
112 |
||
113 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* Loads a template part into a template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* Provides a simple mechanism for child themes to overload reusable sections of code |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* in the theme. |
0 | 118 |
* |
119 |
* Includes the named template part for a theme or if a name is specified then a |
|
120 |
* specialised part will be included. If the theme contains no {slug}.php file |
|
121 |
* then no template will be included. |
|
122 |
* |
|
123 |
* The template is included using require, not require_once, so you may include the |
|
124 |
* same template part multiple times. |
|
125 |
* |
|
126 |
* For the $name parameter, if the file is called "{slug}-special.php" then specify |
|
127 |
* "special". |
|
128 |
* |
|
129 |
* @since 3.0.0 |
|
130 |
* |
|
131 |
* @param string $slug The slug name for the generic template. |
|
132 |
* @param string $name The name of the specialised template. |
|
133 |
*/ |
|
134 |
function get_template_part( $slug, $name = null ) { |
|
5 | 135 |
/** |
136 |
* Fires before the specified template part file is loaded. |
|
137 |
* |
|
138 |
* The dynamic portion of the hook name, `$slug`, refers to the slug name |
|
139 |
* for the generic template part. |
|
140 |
* |
|
141 |
* @since 3.0.0 |
|
142 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* @param string $slug The slug name for the generic template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* @param string|null $name The name of the specialized template. |
5 | 145 |
*/ |
0 | 146 |
do_action( "get_template_part_{$slug}", $slug, $name ); |
147 |
||
148 |
$templates = array(); |
|
149 |
$name = (string) $name; |
|
150 |
if ( '' !== $name ) |
|
151 |
$templates[] = "{$slug}-{$name}.php"; |
|
152 |
||
153 |
$templates[] = "{$slug}.php"; |
|
154 |
||
155 |
locate_template($templates, true, false); |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* Display search form. |
|
160 |
* |
|
161 |
* Will first attempt to locate the searchform.php file in either the child or |
|
162 |
* the parent, then load it. If it doesn't exist, then the default search form |
|
163 |
* will be displayed. The default search form is HTML, which will be displayed. |
|
164 |
* There is a filter applied to the search form HTML in order to edit or replace |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* it. The filter is {@see 'get_search_form'}. |
0 | 166 |
* |
167 |
* This function is primarily used by themes which want to hardcode the search |
|
168 |
* form into the sidebar and also by the search widget in WordPress. |
|
169 |
* |
|
170 |
* There is also an action that is called whenever the function is run called, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
* {@see 'pre_get_search_form'}. This can be useful for outputting JavaScript that the |
0 | 172 |
* search relies on or various formatting that applies to the beginning of the |
173 |
* search. To give a few examples of what it can be used for. |
|
174 |
* |
|
175 |
* @since 2.7.0 |
|
176 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* @param bool $echo Default to echo and not return the form. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @return string|void String when $echo is false. |
0 | 179 |
*/ |
180 |
function get_search_form( $echo = true ) { |
|
5 | 181 |
/** |
182 |
* Fires before the search form is retrieved, at the start of get_search_form(). |
|
183 |
* |
|
184 |
* @since 2.7.0 as 'get_search_form' action. |
|
185 |
* @since 3.6.0 |
|
186 |
* |
|
187 |
* @link https://core.trac.wordpress.org/ticket/19321 |
|
188 |
*/ |
|
0 | 189 |
do_action( 'pre_get_search_form' ); |
190 |
||
191 |
$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; |
|
5 | 192 |
|
193 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* Filters the HTML format of the search form. |
5 | 195 |
* |
196 |
* @since 3.6.0 |
|
197 |
* |
|
198 |
* @param string $format The type of markup to use in the search form. |
|
199 |
* Accepts 'html5', 'xhtml'. |
|
200 |
*/ |
|
0 | 201 |
$format = apply_filters( 'search_form_format', $format ); |
202 |
||
203 |
$search_form_template = locate_template( 'searchform.php' ); |
|
204 |
if ( '' != $search_form_template ) { |
|
205 |
ob_start(); |
|
206 |
require( $search_form_template ); |
|
207 |
$form = ob_get_clean(); |
|
208 |
} else { |
|
209 |
if ( 'html5' == $format ) { |
|
210 |
$form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '"> |
|
211 |
<label> |
|
212 |
<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" /> |
0 | 214 |
</label> |
215 |
<input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" /> |
|
216 |
</form>'; |
|
217 |
} else { |
|
218 |
$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> |
|
219 |
<div> |
|
220 |
<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label> |
|
221 |
<input type="text" value="' . get_search_query() . '" name="s" id="s" /> |
|
222 |
<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" /> |
|
223 |
</div> |
|
224 |
</form>'; |
|
225 |
} |
|
226 |
} |
|
227 |
||
5 | 228 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
* Filters the HTML output of the search form. |
5 | 230 |
* |
231 |
* @since 2.7.0 |
|
232 |
* |
|
233 |
* @param string $form The search form HTML output. |
|
234 |
*/ |
|
0 | 235 |
$result = apply_filters( 'get_search_form', $form ); |
5 | 236 |
|
0 | 237 |
if ( null === $result ) |
238 |
$result = $form; |
|
239 |
||
240 |
if ( $echo ) |
|
241 |
echo $result; |
|
242 |
else |
|
243 |
return $result; |
|
244 |
} |
|
245 |
||
246 |
/** |
|
247 |
* Display the Log In/Out link. |
|
248 |
* |
|
249 |
* Displays a link, which allows users to navigate to the Log In page to log in |
|
250 |
* or log out depending on whether they are currently logged in. |
|
251 |
* |
|
252 |
* @since 1.5.0 |
|
253 |
* |
|
254 |
* @param string $redirect Optional path to redirect to on login/logout. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* @param bool $echo Default to echo and not return the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* @return string|void String when retrieving. |
0 | 257 |
*/ |
258 |
function wp_loginout($redirect = '', $echo = true) { |
|
259 |
if ( ! is_user_logged_in() ) |
|
260 |
$link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>'; |
|
261 |
else |
|
262 |
$link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>'; |
|
263 |
||
5 | 264 |
if ( $echo ) { |
265 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
* Filters the HTML output for the Log In/Log Out link. |
5 | 267 |
* |
268 |
* @since 1.5.0 |
|
269 |
* |
|
270 |
* @param string $link The HTML link content. |
|
271 |
*/ |
|
272 |
echo apply_filters( 'loginout', $link ); |
|
273 |
} else { |
|
274 |
/** This filter is documented in wp-includes/general-template.php */ |
|
275 |
return apply_filters( 'loginout', $link ); |
|
276 |
} |
|
0 | 277 |
} |
278 |
||
279 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* Retrieves the logout URL. |
0 | 281 |
* |
282 |
* Returns the URL that allows the user to log out of the site. |
|
283 |
* |
|
284 |
* @since 2.7.0 |
|
285 |
* |
|
286 |
* @param string $redirect Path to redirect to on logout. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url(). |
0 | 288 |
*/ |
289 |
function wp_logout_url($redirect = '') { |
|
290 |
$args = array( 'action' => 'logout' ); |
|
291 |
if ( !empty($redirect) ) { |
|
292 |
$args['redirect_to'] = urlencode( $redirect ); |
|
293 |
} |
|
294 |
||
295 |
$logout_url = add_query_arg($args, site_url('wp-login.php', 'login')); |
|
296 |
$logout_url = wp_nonce_url( $logout_url, 'log-out' ); |
|
297 |
||
5 | 298 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* Filters the logout URL. |
5 | 300 |
* |
301 |
* @since 2.8.0 |
|
302 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
* @param string $logout_url The HTML-encoded logout URL. |
5 | 304 |
* @param string $redirect Path to redirect to on logout. |
305 |
*/ |
|
306 |
return apply_filters( 'logout_url', $logout_url, $redirect ); |
|
0 | 307 |
} |
308 |
||
309 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
* Retrieves the login URL. |
0 | 311 |
* |
312 |
* @since 2.7.0 |
|
313 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* @param string $redirect Path to redirect to on log in. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* @return string The login URL. Not HTML-encoded. |
0 | 318 |
*/ |
319 |
function wp_login_url($redirect = '', $force_reauth = false) { |
|
320 |
$login_url = site_url('wp-login.php', 'login'); |
|
321 |
||
322 |
if ( !empty($redirect) ) |
|
323 |
$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url); |
|
324 |
||
325 |
if ( $force_reauth ) |
|
326 |
$login_url = add_query_arg('reauth', '1', $login_url); |
|
327 |
||
5 | 328 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* Filters the login URL. |
5 | 330 |
* |
331 |
* @since 2.8.0 |
|
332 |
* @since 4.2.0 The `$force_reauth` parameter was added. |
|
333 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* @param string $login_url The login URL. Not HTML-encoded. |
5 | 335 |
* @param string $redirect The path to redirect to on login, if supplied. |
336 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. |
|
337 |
*/ |
|
338 |
return apply_filters( 'login_url', $login_url, $redirect, $force_reauth ); |
|
0 | 339 |
} |
340 |
||
341 |
/** |
|
342 |
* Returns the URL that allows the user to register on the site. |
|
343 |
* |
|
344 |
* @since 3.6.0 |
|
345 |
* |
|
5 | 346 |
* @return string User registration URL. |
0 | 347 |
*/ |
348 |
function wp_registration_url() { |
|
5 | 349 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* Filters the user registration URL. |
5 | 351 |
* |
352 |
* @since 3.6.0 |
|
353 |
* |
|
354 |
* @param string $register The user registration URL. |
|
355 |
*/ |
|
0 | 356 |
return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) ); |
357 |
} |
|
358 |
||
359 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* Provides a simple login form for use anywhere within WordPress. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
* The login format HTML is echoed by default. Pass a false value for `$echo` to return it instead. |
0 | 363 |
* |
364 |
* @since 3.0.0 |
|
5 | 365 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
* Optional. Array of options to control the form output. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* @type bool $echo Whether to display the login form or return the form HTML code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* Default true (echo). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* Default is to redirect back to the request URI. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* @type string $form_id ID attribute value for the form. Default 'loginform'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* @type string $label_username Label for the username or email address field. Default 'Username or Email Address'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* @type string $label_password Label for the password field. Default 'Password'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* @type string $label_remember Label for the remember field. Default 'Remember Me'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* @type string $label_log_in Label for the submit button. Default 'Log In'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* @type string $id_username ID attribute value for the username field. Default 'user_login'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
* @type string $id_password ID attribute value for the password field. Default 'user_pass'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* @type string $id_remember ID attribute value for the remember field. Default 'rememberme'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @type string $id_submit ID attribute value for the submit button. Default 'wp-submit'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* @type bool $remember Whether to display the "rememberme" checkbox in the form. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* @type string $value_username Default value for the username field. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* Default false (unchecked). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @return string|void String when retrieving. |
0 | 389 |
*/ |
390 |
function wp_login_form( $args = array() ) { |
|
391 |
$defaults = array( |
|
392 |
'echo' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
// Default 'redirect' value takes the user back to the request URI. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], |
0 | 395 |
'form_id' => 'loginform', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
'label_username' => __( 'Username or Email Address' ), |
0 | 397 |
'label_password' => __( 'Password' ), |
398 |
'label_remember' => __( 'Remember Me' ), |
|
399 |
'label_log_in' => __( 'Log In' ), |
|
400 |
'id_username' => 'user_login', |
|
401 |
'id_password' => 'user_pass', |
|
402 |
'id_remember' => 'rememberme', |
|
403 |
'id_submit' => 'wp-submit', |
|
404 |
'remember' => true, |
|
405 |
'value_username' => '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
// Set 'value_remember' to true to default the "Remember me" checkbox to checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
'value_remember' => false, |
0 | 408 |
); |
5 | 409 |
|
410 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* Filters the default login form output arguments. |
5 | 412 |
* |
413 |
* @since 3.0.0 |
|
414 |
* |
|
415 |
* @see wp_login_form() |
|
416 |
* |
|
417 |
* @param array $defaults An array of default login form arguments. |
|
418 |
*/ |
|
0 | 419 |
$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) ); |
420 |
||
5 | 421 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
* Filters content to display at the top of the login form. |
5 | 423 |
* |
424 |
* The filter evaluates just following the opening form tag element. |
|
425 |
* |
|
426 |
* @since 3.0.0 |
|
427 |
* |
|
428 |
* @param string $content Content to display. Default empty. |
|
429 |
* @param array $args Array of login form arguments. |
|
430 |
*/ |
|
431 |
$login_form_top = apply_filters( 'login_form_top', '', $args ); |
|
432 |
||
433 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
* Filters content to display in the middle of the login form. |
5 | 435 |
* |
436 |
* The filter evaluates just following the location where the 'login-password' |
|
437 |
* field is displayed. |
|
438 |
* |
|
439 |
* @since 3.0.0 |
|
440 |
* |
|
441 |
* @param string $content Content to display. Default empty. |
|
442 |
* @param array $args Array of login form arguments. |
|
443 |
*/ |
|
444 |
$login_form_middle = apply_filters( 'login_form_middle', '', $args ); |
|
445 |
||
446 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* Filters content to display at the bottom of the login form. |
5 | 448 |
* |
449 |
* The filter evaluates just preceding the closing form tag element. |
|
450 |
* |
|
451 |
* @since 3.0.0 |
|
452 |
* |
|
453 |
* @param string $content Content to display. Default empty. |
|
454 |
* @param array $args Array of login form arguments. |
|
455 |
*/ |
|
456 |
$login_form_bottom = apply_filters( 'login_form_bottom', '', $args ); |
|
457 |
||
0 | 458 |
$form = ' |
459 |
<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post"> |
|
5 | 460 |
' . $login_form_top . ' |
0 | 461 |
<p class="login-username"> |
462 |
<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label> |
|
463 |
<input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" /> |
|
464 |
</p> |
|
465 |
<p class="login-password"> |
|
466 |
<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label> |
|
467 |
<input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" /> |
|
468 |
</p> |
|
5 | 469 |
' . $login_form_middle . ' |
0 | 470 |
' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . ' |
471 |
<p class="login-submit"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" /> |
0 | 473 |
<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" /> |
474 |
</p> |
|
5 | 475 |
' . $login_form_bottom . ' |
0 | 476 |
</form>'; |
477 |
||
478 |
if ( $args['echo'] ) |
|
479 |
echo $form; |
|
480 |
else |
|
481 |
return $form; |
|
482 |
} |
|
483 |
||
484 |
/** |
|
485 |
* Returns the URL that allows the user to retrieve the lost password |
|
486 |
* |
|
487 |
* @since 2.8.0 |
|
488 |
* |
|
489 |
* @param string $redirect Path to redirect to on login. |
|
490 |
* @return string Lost password URL. |
|
491 |
*/ |
|
492 |
function wp_lostpassword_url( $redirect = '' ) { |
|
493 |
$args = array( 'action' => 'lostpassword' ); |
|
494 |
if ( !empty($redirect) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
$args['redirect_to'] = urlencode( $redirect ); |
0 | 496 |
} |
497 |
||
498 |
$lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') ); |
|
5 | 499 |
|
500 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* Filters the Lost Password URL. |
5 | 502 |
* |
503 |
* @since 2.8.0 |
|
504 |
* |
|
505 |
* @param string $lostpassword_url The lost password page URL. |
|
506 |
* @param string $redirect The path to redirect to on login. |
|
507 |
*/ |
|
0 | 508 |
return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect ); |
509 |
} |
|
510 |
||
511 |
/** |
|
512 |
* Display the Registration or Admin link. |
|
513 |
* |
|
514 |
* Display a link which allows the user to navigate to the registration page if |
|
515 |
* not logged in and registration is enabled or to the dashboard if logged in. |
|
516 |
* |
|
517 |
* @since 1.5.0 |
|
518 |
* |
|
5 | 519 |
* @param string $before Text to output before the link. Default `<li>`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* @param string $after Text to output after the link. Default `</li>`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* @param bool $echo Default to echo and not return the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* @return string|void String when retrieving. |
0 | 523 |
*/ |
524 |
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) { |
|
525 |
if ( ! is_user_logged_in() ) { |
|
526 |
if ( get_option('users_can_register') ) |
|
527 |
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after; |
|
528 |
else |
|
529 |
$link = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
} elseif ( current_user_can( 'read' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after; |
0 | 532 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
$link = ''; |
0 | 534 |
} |
535 |
||
5 | 536 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* Filters the HTML link to the Registration or Admin page. |
5 | 538 |
* |
539 |
* Users are sent to the admin page if logged-in, or the registration page |
|
540 |
* if enabled and logged-out. |
|
541 |
* |
|
542 |
* @since 1.5.0 |
|
543 |
* |
|
544 |
* @param string $link The HTML code for the link to the Registration or Admin page. |
|
545 |
*/ |
|
546 |
$link = apply_filters( 'register', $link ); |
|
547 |
||
548 |
if ( $echo ) { |
|
549 |
echo $link; |
|
550 |
} else { |
|
551 |
return $link; |
|
552 |
} |
|
0 | 553 |
} |
554 |
||
555 |
/** |
|
556 |
* Theme container function for the 'wp_meta' action. |
|
557 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
* The {@see 'wp_meta'} action can have several purposes, depending on how you use it, |
0 | 559 |
* but one purpose might have been to allow for theme switching. |
560 |
* |
|
561 |
* @since 1.5.0 |
|
5 | 562 |
* |
563 |
* @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action. |
|
0 | 564 |
*/ |
565 |
function wp_meta() { |
|
5 | 566 |
/** |
567 |
* Fires before displaying echoed content in the sidebar. |
|
568 |
* |
|
569 |
* @since 1.5.0 |
|
570 |
*/ |
|
571 |
do_action( 'wp_meta' ); |
|
0 | 572 |
} |
573 |
||
574 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* Displays information about the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* |
0 | 577 |
* @since 0.71 |
578 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* @see get_bloginfo() For possible `$show` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
* @param string $show Optional. Site information to display. Default empty. |
0 | 582 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
function bloginfo( $show = '' ) { |
0 | 584 |
echo get_bloginfo( $show, 'display' ); |
585 |
} |
|
586 |
||
587 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* Retrieves information about the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* Possible values for `$show` include: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* - 'name' - Site title (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* - 'description' - Site tagline (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* - 'wpurl' - The WordPress address (URL) (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* - 'url' - The Site address (URL) (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
* - 'admin_email' - Admin email (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* - 'charset' - The "Encoding for pages and feeds" (set in Settings > Reading) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
* - 'version' - The current WordPress version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
* - 'html_type' - The content-type (default: "text/html"). Themes and plugins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
* can override the default value using the {@see 'pre_option_html_type'} filter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
* - 'text_direction' - The text direction determined by the site's language. is_rtl() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
* should be used instead |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
* - 'language' - Language code for the current site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* will take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
* - 'stylesheet_directory' - Directory path for the active theme. An active child theme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* will take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* - 'template_url' / 'template_directory' - URL of the active theme's directory. An active |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
* child theme will NOT take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
* - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
* - 'atom_url' - The Atom feed URL (/feed/atom) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
* - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rfd) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* - 'rss_url' - The RSS 0.92 feed URL (/feed/rss) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* - 'rss2_url' - The RSS 2.0 feed URL (/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* - 'comments_atom_url' - The comments Atom feed URL (/comments/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* - 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* Some `$show` values are deprecated and will be removed in future versions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* These options will trigger the _deprecated_argument() function. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* Deprecated arguments include: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* - 'siteurl' - Use 'url' instead |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* - 'home' - Use 'url' instead |
0 | 625 |
* |
626 |
* @since 0.71 |
|
627 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* @global string $wp_version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* @param string $show Optional. Site info to retrieve. Default empty (site name). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* @param string $filter Optional. How to filter what is retrieved. Default 'raw'. |
0 | 632 |
* @return string Mostly string values, might be empty. |
633 |
*/ |
|
634 |
function get_bloginfo( $show = '', $filter = 'raw' ) { |
|
635 |
switch( $show ) { |
|
636 |
case 'home' : // DEPRECATED |
|
637 |
case 'siteurl' : // DEPRECATED |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
_deprecated_argument( __FUNCTION__, '2.2.0', sprintf( |
5 | 639 |
/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */ |
640 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ), |
|
641 |
'<code>' . $show . '</code>', |
|
642 |
'<code>bloginfo()</code>', |
|
643 |
'<code>url</code>' |
|
644 |
) ); |
|
0 | 645 |
case 'url' : |
646 |
$output = home_url(); |
|
647 |
break; |
|
648 |
case 'wpurl' : |
|
649 |
$output = site_url(); |
|
650 |
break; |
|
651 |
case 'description': |
|
652 |
$output = get_option('blogdescription'); |
|
653 |
break; |
|
654 |
case 'rdf_url': |
|
655 |
$output = get_feed_link('rdf'); |
|
656 |
break; |
|
657 |
case 'rss_url': |
|
658 |
$output = get_feed_link('rss'); |
|
659 |
break; |
|
660 |
case 'rss2_url': |
|
661 |
$output = get_feed_link('rss2'); |
|
662 |
break; |
|
663 |
case 'atom_url': |
|
664 |
$output = get_feed_link('atom'); |
|
665 |
break; |
|
666 |
case 'comments_atom_url': |
|
667 |
$output = get_feed_link('comments_atom'); |
|
668 |
break; |
|
669 |
case 'comments_rss2_url': |
|
670 |
$output = get_feed_link('comments_rss2'); |
|
671 |
break; |
|
672 |
case 'pingback_url': |
|
673 |
$output = site_url( 'xmlrpc.php' ); |
|
674 |
break; |
|
675 |
case 'stylesheet_url': |
|
676 |
$output = get_stylesheet_uri(); |
|
677 |
break; |
|
678 |
case 'stylesheet_directory': |
|
679 |
$output = get_stylesheet_directory_uri(); |
|
680 |
break; |
|
681 |
case 'template_directory': |
|
682 |
case 'template_url': |
|
683 |
$output = get_template_directory_uri(); |
|
684 |
break; |
|
685 |
case 'admin_email': |
|
686 |
$output = get_option('admin_email'); |
|
687 |
break; |
|
688 |
case 'charset': |
|
689 |
$output = get_option('blog_charset'); |
|
690 |
if ('' == $output) $output = 'UTF-8'; |
|
691 |
break; |
|
692 |
case 'html_type' : |
|
693 |
$output = get_option('html_type'); |
|
694 |
break; |
|
695 |
case 'version': |
|
696 |
global $wp_version; |
|
697 |
$output = $wp_version; |
|
698 |
break; |
|
699 |
case 'language': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
/* translators: Translate this to the correct language tag for your locale, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* see https://www.w3.org/International/articles/language-tags/ for reference. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* Do not translate into your own language. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
$output = __( 'html_lang_attribute' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
$output = is_admin() ? get_user_locale() : get_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
$output = str_replace( '_', '-', $output ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
} |
0 | 709 |
break; |
710 |
case 'text_direction': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
_deprecated_argument( __FUNCTION__, '2.2.0', sprintf( |
5 | 712 |
/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */ |
713 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ), |
|
714 |
'<code>' . $show . '</code>', |
|
715 |
'<code>bloginfo()</code>', |
|
716 |
'<code>is_rtl()</code>' |
|
717 |
) ); |
|
0 | 718 |
if ( function_exists( 'is_rtl' ) ) { |
719 |
$output = is_rtl() ? 'rtl' : 'ltr'; |
|
720 |
} else { |
|
721 |
$output = 'ltr'; |
|
722 |
} |
|
723 |
break; |
|
724 |
case 'name': |
|
725 |
default: |
|
726 |
$output = get_option('blogname'); |
|
727 |
break; |
|
728 |
} |
|
729 |
||
730 |
$url = true; |
|
731 |
if (strpos($show, 'url') === false && |
|
732 |
strpos($show, 'directory') === false && |
|
733 |
strpos($show, 'home') === false) |
|
734 |
$url = false; |
|
735 |
||
736 |
if ( 'display' == $filter ) { |
|
5 | 737 |
if ( $url ) { |
738 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
* Filters the URL returned by get_bloginfo(). |
5 | 740 |
* |
741 |
* @since 2.0.5 |
|
742 |
* |
|
743 |
* @param mixed $output The URL returned by bloginfo(). |
|
744 |
* @param mixed $show Type of information requested. |
|
745 |
*/ |
|
746 |
$output = apply_filters( 'bloginfo_url', $output, $show ); |
|
747 |
} else { |
|
748 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* Filters the site information returned by get_bloginfo(). |
5 | 750 |
* |
751 |
* @since 0.71 |
|
752 |
* |
|
753 |
* @param mixed $output The requested non-URL site information. |
|
754 |
* @param mixed $show Type of information requested. |
|
755 |
*/ |
|
756 |
$output = apply_filters( 'bloginfo', $output, $show ); |
|
757 |
} |
|
0 | 758 |
} |
759 |
||
760 |
return $output; |
|
761 |
} |
|
762 |
||
763 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
* Returns the Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
* @param int $size Optional. Size of the site icon. Default 512 (pixels). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
* @param string $url Optional. Fallback url if no site icon is found. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
* @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
* @return string Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
774 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
775 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
$site_icon_id = get_option( 'site_icon' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
if ( $site_icon_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
if ( $size >= 512 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
$size_data = 'full'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
$size_data = array( $size, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
$url = wp_get_attachment_image_url( $site_icon_id, $size_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* Filters the site icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
* @param string $url Site icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* @param int $size Size of the site icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
* @param int $blog_id ID of the blog to get the site icon for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
return apply_filters( 'get_site_icon_url', $url, $size, $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
* Displays the Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
812 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* @param int $size Optional. Size of the site icon. Default 512 (pixels). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
* @param string $url Optional. Fallback url if no site icon is found. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
817 |
function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
echo esc_url( get_site_icon_url( $size, $url, $blog_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* Whether the site has a Site Icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param int $blog_id Optional. ID of the blog in question. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @return bool Whether the site has a site icon or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
function has_site_icon( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
return (bool) get_site_icon_url( 512, '', $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
832 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
* Determines whether the site has a custom logo. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
* @return bool Whether the site has a custom logo or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
function has_custom_logo( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
return (bool) $custom_logo_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* Returns a custom logo, linked to home. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* @return string Custom logo markup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
function get_custom_logo( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
$html = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
// We have a logo. Logo is go. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
if ( $custom_logo_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
$custom_logo_attr = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
'class' => 'custom-logo', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
'itemprop' => 'logo', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
* If the logo alt attribute is empty, get the site title and explicitly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* pass it to the attributes used by wp_get_attachment_image(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
if ( empty( $image_alt ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
* If the alt attribute is not empty, there's no need to explicitly pass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
* it because wp_get_attachment_image() already adds the alt attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
esc_url( home_url( '/' ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
elseif ( is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
$html = sprintf( '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
esc_url( home_url( '/' ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
* Filters the custom logo output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
* @since 4.6.0 Added the `$blog_id` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
* @param string $html Custom logo HTML output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
* @param int $blog_id ID of the blog to get the custom logo for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
return apply_filters( 'get_custom_logo', $html, $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
* Displays a custom logo, linked to home. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
function the_custom_logo( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
echo get_custom_logo( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* Returns document title for the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* @global int $page Page number of a single post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
* @global int $paged Page number of a list of posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
* @return string Tag with the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
function wp_get_document_title() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
* Filters the document title before it is generated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* Passing a non-empty value will short-circuit wp_get_document_title(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* returning that value instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
* @param string $title The document title. Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
$title = apply_filters( 'pre_get_document_title', '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
if ( ! empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
return $title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
global $page, $paged; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
$title = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
'title' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
// If it's a 404 page, use a "Page not found" title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
if ( is_404() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
$title['title'] = __( 'Page not found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
// If it's a search, use a dynamic search results title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
} elseif ( is_search() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
/* translators: %s: search phrase */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
$title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
// If on the front page, use the site title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
} elseif ( is_front_page() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
$title['title'] = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
// If on a post type archive, use the post type archive title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
} elseif ( is_post_type_archive() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
$title['title'] = post_type_archive_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
// If on a taxonomy archive, use the term title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
} elseif ( is_tax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
$title['title'] = single_term_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
* If we're on the blog page that is not the homepage or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
* a single post of any post type, use the post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
} elseif ( is_home() || is_singular() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
$title['title'] = single_post_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
// If on a category or tag archive, use the term title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
} elseif ( is_category() || is_tag() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
$title['title'] = single_term_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
// If on an author archive, use the author's display name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
} elseif ( is_author() && $author = get_queried_object() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
$title['title'] = $author->display_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
// If it's a date archive, use the date as the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
} elseif ( is_year() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
$title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
} elseif ( is_month() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
$title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
} elseif ( is_day() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
$title['title'] = get_the_date(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
// Add a page number if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
$title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
// Append the description or site title to give context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
if ( is_front_page() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
$title['tagline'] = get_bloginfo( 'description', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
$title['site'] = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* Filters the separator for the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
* @param string $sep Document title separator. Default '-'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
$sep = apply_filters( 'document_title_separator', '-' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* Filters the parts of the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
* @param array $title { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
* The document title parts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* @type string $title Title of the viewed page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
* @type string $page Optional. Page number if paginated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
* @type string $tagline Optional. Site description when on home page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
* @type string $site Optional. Site title when not on home page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
$title = apply_filters( 'document_title_parts', $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
$title = implode( " $sep ", array_filter( $title ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
$title = wptexturize( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
$title = convert_chars( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
$title = esc_html( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
$title = capital_P_dangit( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
return $title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* Displays title tag with content. |
5 | 1065 |
* |
1066 |
* @ignore |
|
1067 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @since 4.4.0 Improved title output replaced `wp_title()`. |
5 | 1069 |
* @access private |
1070 |
*/ |
|
1071 |
function _wp_render_title_tag() { |
|
1072 |
if ( ! current_theme_supports( 'title-tag' ) ) { |
|
1073 |
return; |
|
1074 |
} |
|
1075 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
echo '<title>' . wp_get_document_title() . '</title>' . "\n"; |
5 | 1077 |
} |
1078 |
||
1079 |
/** |
|
0 | 1080 |
* Display or retrieve page title for all areas of blog. |
1081 |
* |
|
1082 |
* By default, the page title will display the separator before the page title, |
|
1083 |
* so that the blog title will be before the page title. This is not good for |
|
1084 |
* title display, since the blog title shows up on most tabs and not what is |
|
1085 |
* important, which is the page that the user is looking at. |
|
1086 |
* |
|
1087 |
* There are also SEO benefits to having the blog title after or to the 'right' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* of the page title. However, it is mostly common sense to have the blog title |
0 | 1089 |
* to the right with most browsers supporting tabs. You can achieve this by |
1090 |
* using the seplocation parameter and setting the value to 'right'. This change |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* was introduced around 2.5.0, in case backward compatibility of themes is |
0 | 1092 |
* important. |
1093 |
* |
|
1094 |
* @since 1.0.0 |
|
1095 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* @param string $sep Optional, default is '»'. How to separate the various items |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* within the page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
0 | 1101 |
* @param string $seplocation Optional. Direction to display title, 'right'. |
1102 |
* @return string|null String on retrieve, null when displaying. |
|
1103 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
function wp_title( $sep = '»', $display = true, $seplocation = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
global $wp_locale; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
$m = get_query_var( 'm' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
$year = get_query_var( 'year' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
$monthnum = get_query_var( 'monthnum' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
$day = get_query_var( 'day' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
$search = get_query_var( 's' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
$title = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
$t_sep = '%WP_TITLE_SEP%'; // Temporary separator, for accurate flipping, if necessary |
0 | 1115 |
|
1116 |
// If there is a post |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) { |
0 | 1118 |
$title = single_post_title( '', false ); |
1119 |
} |
|
1120 |
||
1121 |
// If there's a post type archive |
|
1122 |
if ( is_post_type_archive() ) { |
|
1123 |
$post_type = get_query_var( 'post_type' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
if ( is_array( $post_type ) ) { |
0 | 1125 |
$post_type = reset( $post_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
} |
0 | 1127 |
$post_type_object = get_post_type_object( $post_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
if ( ! $post_type_object->has_archive ) { |
0 | 1129 |
$title = post_type_archive_title( '', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
} |
0 | 1131 |
} |
1132 |
||
1133 |
// If there's a category or tag |
|
1134 |
if ( is_category() || is_tag() ) { |
|
1135 |
$title = single_term_title( '', false ); |
|
1136 |
} |
|
1137 |
||
1138 |
// If there's a taxonomy |
|
1139 |
if ( is_tax() ) { |
|
1140 |
$term = get_queried_object(); |
|
1141 |
if ( $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
$tax = get_taxonomy( $term->taxonomy ); |
0 | 1143 |
$title = single_term_title( $tax->labels->name . $t_sep, false ); |
1144 |
} |
|
1145 |
} |
|
1146 |
||
1147 |
// If there's an author |
|
5 | 1148 |
if ( is_author() && ! is_post_type_archive() ) { |
0 | 1149 |
$author = get_queried_object(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
if ( $author ) { |
0 | 1151 |
$title = $author->display_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1152 |
} |
0 | 1153 |
} |
1154 |
||
1155 |
// Post type archives with has_archive should override terms. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
if ( is_post_type_archive() && $post_type_object->has_archive ) { |
0 | 1157 |
$title = post_type_archive_title( '', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
} |
0 | 1159 |
|
1160 |
// If there's a month |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
if ( is_archive() && ! empty( $m ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
$my_year = substr( $m, 0, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
$my_day = intval( substr( $m, 6, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
$title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' ); |
0 | 1166 |
} |
1167 |
||
1168 |
// If there's a year |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
if ( is_archive() && ! empty( $year ) ) { |
0 | 1170 |
$title = $year; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
if ( ! empty( $monthnum ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
$title .= $t_sep . $wp_locale->get_month( $monthnum ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
if ( ! empty( $day ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
$title .= $t_sep . zeroise( $day, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
} |
0 | 1177 |
} |
1178 |
||
1179 |
// If it's a search |
|
1180 |
if ( is_search() ) { |
|
1181 |
/* translators: 1: separator, 2: search phrase */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
$title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) ); |
0 | 1183 |
} |
1184 |
||
1185 |
// If it's a 404 page |
|
1186 |
if ( is_404() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
$title = __( 'Page not found' ); |
0 | 1188 |
} |
1189 |
||
1190 |
$prefix = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
if ( ! empty( $title ) ) { |
0 | 1192 |
$prefix = " $sep "; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
} |
0 | 1194 |
|
5 | 1195 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
* Filters the parts of the page title. |
5 | 1197 |
* |
1198 |
* @since 4.0.0 |
|
1199 |
* |
|
1200 |
* @param array $title_array Parts of the page title. |
|
1201 |
*/ |
|
1202 |
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); |
|
1203 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
// Determines position of the separator and direction of the breadcrumb |
0 | 1205 |
if ( 'right' == $seplocation ) { // sep on right, so reverse the order |
1206 |
$title_array = array_reverse( $title_array ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
$title = implode( " $sep ", $title_array ) . $prefix; |
0 | 1208 |
} else { |
1209 |
$title = $prefix . implode( " $sep ", $title_array ); |
|
1210 |
} |
|
1211 |
||
5 | 1212 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
* Filters the text of the page title. |
5 | 1214 |
* |
1215 |
* @since 2.0.0 |
|
1216 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
* @param string $title Page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* @param string $sep Title separator. |
5 | 1219 |
* @param string $seplocation Location of the separator (left or right). |
1220 |
*/ |
|
1221 |
$title = apply_filters( 'wp_title', $title, $sep, $seplocation ); |
|
0 | 1222 |
|
1223 |
// Send it out |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
if ( $display ) { |
0 | 1225 |
echo $title; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
} else { |
0 | 1227 |
return $title; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
} |
0 | 1229 |
} |
1230 |
||
1231 |
/** |
|
1232 |
* Display or retrieve page title for post. |
|
1233 |
* |
|
1234 |
* This is optimized for single.php template file for displaying the post title. |
|
1235 |
* |
|
1236 |
* It does not support placing the separator after the title, but by leaving the |
|
1237 |
* prefix parameter empty, you can set the title separator manually. The prefix |
|
1238 |
* does not automatically place a space between the prefix, so if there should |
|
1239 |
* be a space, the parameter value will need to have it at the end. |
|
1240 |
* |
|
1241 |
* @since 0.71 |
|
1242 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
* @return string|void Title when retrieving. |
0 | 1246 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
function single_post_title( $prefix = '', $display = true ) { |
0 | 1248 |
$_post = get_queried_object(); |
1249 |
||
1250 |
if ( !isset($_post->post_title) ) |
|
1251 |
return; |
|
1252 |
||
5 | 1253 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* Filters the page title for a single post. |
5 | 1255 |
* |
1256 |
* @since 0.71 |
|
1257 |
* |
|
1258 |
* @param string $_post_title The single post page title. |
|
1259 |
* @param object $_post The current queried object as returned by get_queried_object(). |
|
1260 |
*/ |
|
1261 |
$title = apply_filters( 'single_post_title', $_post->post_title, $_post ); |
|
0 | 1262 |
if ( $display ) |
1263 |
echo $prefix . $title; |
|
1264 |
else |
|
1265 |
return $prefix . $title; |
|
1266 |
} |
|
1267 |
||
1268 |
/** |
|
1269 |
* Display or retrieve title for a post type archive. |
|
1270 |
* |
|
1271 |
* This is optimized for archive.php and archive-{$post_type}.php template files |
|
1272 |
* for displaying the title of the post type. |
|
1273 |
* |
|
1274 |
* @since 3.1.0 |
|
1275 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* @return string|void Title when retrieving, null when displaying or failure. |
0 | 1279 |
*/ |
1280 |
function post_type_archive_title( $prefix = '', $display = true ) { |
|
1281 |
if ( ! is_post_type_archive() ) |
|
1282 |
return; |
|
1283 |
||
1284 |
$post_type = get_query_var( 'post_type' ); |
|
1285 |
if ( is_array( $post_type ) ) |
|
1286 |
$post_type = reset( $post_type ); |
|
1287 |
||
1288 |
$post_type_obj = get_post_type_object( $post_type ); |
|
5 | 1289 |
|
1290 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
* Filters the post type archive title. |
5 | 1292 |
* |
1293 |
* @since 3.1.0 |
|
1294 |
* |
|
1295 |
* @param string $post_type_name Post type 'name' label. |
|
1296 |
* @param string $post_type Post type. |
|
1297 |
*/ |
|
1298 |
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); |
|
0 | 1299 |
|
1300 |
if ( $display ) |
|
1301 |
echo $prefix . $title; |
|
1302 |
else |
|
1303 |
return $prefix . $title; |
|
1304 |
} |
|
1305 |
||
1306 |
/** |
|
1307 |
* Display or retrieve page title for category archive. |
|
1308 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
* Useful for category template files for displaying the category page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
* The prefix does not automatically place a space between the prefix, so if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* there should be a space, the parameter value will need to have it at the end. |
0 | 1312 |
* |
1313 |
* @since 0.71 |
|
1314 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* @return string|void Title when retrieving. |
0 | 1318 |
*/ |
1319 |
function single_cat_title( $prefix = '', $display = true ) { |
|
1320 |
return single_term_title( $prefix, $display ); |
|
1321 |
} |
|
1322 |
||
1323 |
/** |
|
1324 |
* Display or retrieve page title for tag post archive. |
|
1325 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
* Useful for tag template files for displaying the tag page title. The prefix |
0 | 1327 |
* does not automatically place a space between the prefix, so if there should |
1328 |
* be a space, the parameter value will need to have it at the end. |
|
1329 |
* |
|
1330 |
* @since 2.3.0 |
|
1331 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
* @return string|void Title when retrieving. |
0 | 1335 |
*/ |
1336 |
function single_tag_title( $prefix = '', $display = true ) { |
|
1337 |
return single_term_title( $prefix, $display ); |
|
1338 |
} |
|
1339 |
||
1340 |
/** |
|
1341 |
* Display or retrieve page title for taxonomy term archive. |
|
1342 |
* |
|
1343 |
* Useful for taxonomy term template files for displaying the taxonomy term page title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
* The prefix does not automatically place a space between the prefix, so if there should |
0 | 1345 |
* be a space, the parameter value will need to have it at the end. |
1346 |
* |
|
1347 |
* @since 3.1.0 |
|
1348 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
* @return string|void Title when retrieving. |
0 | 1352 |
*/ |
1353 |
function single_term_title( $prefix = '', $display = true ) { |
|
1354 |
$term = get_queried_object(); |
|
1355 |
||
1356 |
if ( !$term ) |
|
1357 |
return; |
|
1358 |
||
5 | 1359 |
if ( is_category() ) { |
1360 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
* Filters the category archive page title. |
5 | 1362 |
* |
1363 |
* @since 2.0.10 |
|
1364 |
* |
|
1365 |
* @param string $term_name Category name for archive being displayed. |
|
1366 |
*/ |
|
0 | 1367 |
$term_name = apply_filters( 'single_cat_title', $term->name ); |
5 | 1368 |
} elseif ( is_tag() ) { |
1369 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
* Filters the tag archive page title. |
5 | 1371 |
* |
1372 |
* @since 2.3.0 |
|
1373 |
* |
|
1374 |
* @param string $term_name Tag name for archive being displayed. |
|
1375 |
*/ |
|
0 | 1376 |
$term_name = apply_filters( 'single_tag_title', $term->name ); |
5 | 1377 |
} elseif ( is_tax() ) { |
1378 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
* Filters the custom taxonomy archive page title. |
5 | 1380 |
* |
1381 |
* @since 3.1.0 |
|
1382 |
* |
|
1383 |
* @param string $term_name Term name for archive being displayed. |
|
1384 |
*/ |
|
0 | 1385 |
$term_name = apply_filters( 'single_term_title', $term->name ); |
5 | 1386 |
} else { |
0 | 1387 |
return; |
5 | 1388 |
} |
0 | 1389 |
|
1390 |
if ( empty( $term_name ) ) |
|
1391 |
return; |
|
1392 |
||
1393 |
if ( $display ) |
|
1394 |
echo $prefix . $term_name; |
|
1395 |
else |
|
1396 |
return $prefix . $term_name; |
|
1397 |
} |
|
1398 |
||
1399 |
/** |
|
1400 |
* Display or retrieve page title for post archive based on date. |
|
1401 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
* Useful for when the template only needs to display the month and year, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* if either are available. The prefix does not automatically place a space |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
* between the prefix, so if there should be a space, the parameter value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
* will need to have it at the end. |
0 | 1406 |
* |
1407 |
* @since 0.71 |
|
1408 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
* @param string $prefix Optional. What to display before the title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
* @param bool $display Optional, default is true. Whether to display or retrieve title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* @return string|void Title when retrieving. |
0 | 1414 |
*/ |
1415 |
function single_month_title($prefix = '', $display = true ) { |
|
1416 |
global $wp_locale; |
|
1417 |
||
1418 |
$m = get_query_var('m'); |
|
1419 |
$year = get_query_var('year'); |
|
1420 |
$monthnum = get_query_var('monthnum'); |
|
1421 |
||
1422 |
if ( !empty($monthnum) && !empty($year) ) { |
|
1423 |
$my_year = $year; |
|
1424 |
$my_month = $wp_locale->get_month($monthnum); |
|
1425 |
} elseif ( !empty($m) ) { |
|
1426 |
$my_year = substr($m, 0, 4); |
|
1427 |
$my_month = $wp_locale->get_month(substr($m, 4, 2)); |
|
1428 |
} |
|
1429 |
||
1430 |
if ( empty($my_month) ) |
|
1431 |
return false; |
|
1432 |
||
1433 |
$result = $prefix . $my_month . $prefix . $my_year; |
|
1434 |
||
1435 |
if ( !$display ) |
|
1436 |
return $result; |
|
1437 |
echo $result; |
|
1438 |
} |
|
1439 |
||
1440 |
/** |
|
5 | 1441 |
* Display the archive title based on the queried object. |
1442 |
* |
|
1443 |
* @since 4.1.0 |
|
1444 |
* |
|
1445 |
* @see get_the_archive_title() |
|
1446 |
* |
|
1447 |
* @param string $before Optional. Content to prepend to the title. Default empty. |
|
1448 |
* @param string $after Optional. Content to append to the title. Default empty. |
|
1449 |
*/ |
|
1450 |
function the_archive_title( $before = '', $after = '' ) { |
|
1451 |
$title = get_the_archive_title(); |
|
1452 |
||
1453 |
if ( ! empty( $title ) ) { |
|
1454 |
echo $before . $title . $after; |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
/** |
|
1459 |
* Retrieve the archive title based on the queried object. |
|
1460 |
* |
|
1461 |
* @since 4.1.0 |
|
1462 |
* |
|
1463 |
* @return string Archive title. |
|
1464 |
*/ |
|
1465 |
function get_the_archive_title() { |
|
1466 |
if ( is_category() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
/* translators: Category archive title. 1: Category name */ |
5 | 1468 |
$title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); |
1469 |
} elseif ( is_tag() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
/* translators: Tag archive title. 1: Tag name */ |
5 | 1471 |
$title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); |
1472 |
} elseif ( is_author() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
/* translators: Author archive title. 1: Author name */ |
5 | 1474 |
$title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' ); |
1475 |
} elseif ( is_year() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
/* translators: Yearly archive title. 1: Year */ |
5 | 1477 |
$title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) ); |
1478 |
} elseif ( is_month() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
/* translators: Monthly archive title. 1: Month name and year */ |
5 | 1480 |
$title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) ); |
1481 |
} elseif ( is_day() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
/* translators: Daily archive title. 1: Date */ |
5 | 1483 |
$title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) ); |
1484 |
} elseif ( is_tax( 'post_format' ) ) { |
|
1485 |
if ( is_tax( 'post_format', 'post-format-aside' ) ) { |
|
1486 |
$title = _x( 'Asides', 'post format archive title' ); |
|
1487 |
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { |
|
1488 |
$title = _x( 'Galleries', 'post format archive title' ); |
|
1489 |
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) { |
|
1490 |
$title = _x( 'Images', 'post format archive title' ); |
|
1491 |
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) { |
|
1492 |
$title = _x( 'Videos', 'post format archive title' ); |
|
1493 |
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { |
|
1494 |
$title = _x( 'Quotes', 'post format archive title' ); |
|
1495 |
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) { |
|
1496 |
$title = _x( 'Links', 'post format archive title' ); |
|
1497 |
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) { |
|
1498 |
$title = _x( 'Statuses', 'post format archive title' ); |
|
1499 |
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { |
|
1500 |
$title = _x( 'Audio', 'post format archive title' ); |
|
1501 |
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { |
|
1502 |
$title = _x( 'Chats', 'post format archive title' ); |
|
1503 |
} |
|
1504 |
} elseif ( is_post_type_archive() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
/* translators: Post type archive title. 1: Post type name */ |
5 | 1506 |
$title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) ); |
1507 |
} elseif ( is_tax() ) { |
|
1508 |
$tax = get_taxonomy( get_queried_object()->taxonomy ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
/* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */ |
5 | 1510 |
$title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) ); |
1511 |
} else { |
|
1512 |
$title = __( 'Archives' ); |
|
1513 |
} |
|
1514 |
||
1515 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* Filters the archive title. |
5 | 1517 |
* |
1518 |
* @since 4.1.0 |
|
1519 |
* |
|
1520 |
* @param string $title Archive title to be displayed. |
|
1521 |
*/ |
|
1522 |
return apply_filters( 'get_the_archive_title', $title ); |
|
1523 |
} |
|
1524 |
||
1525 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
* Display category, tag, term, or author description. |
5 | 1527 |
* |
1528 |
* @since 4.1.0 |
|
1529 |
* |
|
1530 |
* @see get_the_archive_description() |
|
1531 |
* |
|
1532 |
* @param string $before Optional. Content to prepend to the description. Default empty. |
|
1533 |
* @param string $after Optional. Content to append to the description. Default empty. |
|
1534 |
*/ |
|
1535 |
function the_archive_description( $before = '', $after = '' ) { |
|
1536 |
$description = get_the_archive_description(); |
|
1537 |
if ( $description ) { |
|
1538 |
echo $before . $description . $after; |
|
1539 |
} |
|
1540 |
} |
|
1541 |
||
1542 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1543 |
* Retrieves the description for an author, post type, or term archive. |
5 | 1544 |
* |
1545 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
* @since 4.7.0 Added support for author archives. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
* @since 4.9.0 Added support for post type archives. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1549 |
* @see term_description() |
5 | 1550 |
* |
1551 |
* @return string Archive description. |
|
1552 |
*/ |
|
1553 |
function get_the_archive_description() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
if ( is_author() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
$description = get_the_author_meta( 'description' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
} elseif ( is_post_type_archive() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
$description = get_the_post_type_description(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
$description = term_description(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
|
5 | 1562 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
* Filters the archive description. |
5 | 1564 |
* |
1565 |
* @since 4.1.0 |
|
1566 |
* |
|
1567 |
* @param string $description Archive description to be displayed. |
|
1568 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
return apply_filters( 'get_the_archive_description', $description ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1570 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1573 |
* Retrieves the description for a post type archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
* @return string The post type description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
function get_the_post_type_description() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
$post_type = get_query_var( 'post_type' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
if ( is_array( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
$post_type = reset( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
$post_type_obj = get_post_type_object( $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
// Check if a description is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
if ( isset( $post_type_obj->description ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
$description = $post_type_obj->description; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
$description = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
* Filters the description for a post type archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1600 |
* @param string $description The post type description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1601 |
* @param WP_Post_Type $post_type_obj The post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1603 |
return apply_filters( 'get_the_post_type_description', $description, $post_type_obj ); |
5 | 1604 |
} |
1605 |
||
1606 |
/** |
|
0 | 1607 |
* Retrieve archive link content based on predefined or custom code. |
1608 |
* |
|
1609 |
* The format can be one of four styles. The 'link' for head element, 'option' |
|
1610 |
* for use in the select element, 'html' for use in list (either ol or ul HTML |
|
1611 |
* elements). Custom content is also supported using the before and after |
|
1612 |
* parameters. |
|
1613 |
* |
|
5 | 1614 |
* The 'link' format uses the `<link>` HTML element with the **archives** |
0 | 1615 |
* relationship. The before and after parameters are not used. The text |
1616 |
* parameter is used to describe the link. |
|
1617 |
* |
|
1618 |
* The 'option' format uses the option HTML element for use in select element. |
|
1619 |
* The value is the url parameter and the before and after parameters are used |
|
1620 |
* between the text description. |
|
1621 |
* |
|
1622 |
* The 'html' format, which is the default, uses the li HTML element for use in |
|
1623 |
* the list HTML elements. The before parameter is before the link and the after |
|
1624 |
* parameter is after the closing link. |
|
1625 |
* |
|
1626 |
* The custom format uses the before parameter before the link ('a' HTML |
|
1627 |
* element) and the after parameter after the closing link tag. If the above |
|
1628 |
* three values for the format are not used, then custom format is assumed. |
|
1629 |
* |
|
1630 |
* @since 1.0.0 |
|
1631 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
* @param string $url URL to archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
* @param string $text Archive text description. |
0 | 1634 |
* @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
* @param string $before Optional. Content to prepend to the description. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* @param string $after Optional. Content to append to the description. Default empty. |
0 | 1637 |
* @return string HTML link content for archive. |
1638 |
*/ |
|
1639 |
function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { |
|
1640 |
$text = wptexturize($text); |
|
1641 |
$url = esc_url($url); |
|
1642 |
||
1643 |
if ('link' == $format) |
|
1644 |
$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; |
|
1645 |
elseif ('option' == $format) |
|
1646 |
$link_html = "\t<option value='$url'>$before $text $after</option>\n"; |
|
1647 |
elseif ('html' == $format) |
|
1648 |
$link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n"; |
|
1649 |
else // custom |
|
1650 |
$link_html = "\t$before<a href='$url'>$text</a>$after\n"; |
|
1651 |
||
5 | 1652 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* Filters the archive link content. |
5 | 1654 |
* |
1655 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1656 |
* @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. |
5 | 1657 |
* |
1658 |
* @param string $link_html The archive HTML link content. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
* @param string $url URL to archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
* @param string $text Archive text description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
* @param string $format Link format. Can be 'link', 'option', 'html', or custom. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
* @param string $before Content to prepend to the description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
* @param string $after Content to append to the description. |
5 | 1664 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after ); |
0 | 1666 |
} |
1667 |
||
1668 |
/** |
|
1669 |
* Display archive links based on type and format. |
|
1670 |
* |
|
1671 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
* @since 4.4.0 $post_type arg was added. |
0 | 1673 |
* |
5 | 1674 |
* @see get_archives_link() |
1675 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
* |
5 | 1679 |
* @param string|array $args { |
1680 |
* Default archive links arguments. Optional. |
|
1681 |
* |
|
1682 |
* @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly', |
|
1683 |
* 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha' |
|
1684 |
* display the same archive link list as well as post titles instead |
|
1685 |
* of displaying dates. The difference between the two is that 'alpha' |
|
1686 |
* will order by post title and 'postbypost' will order by post date. |
|
1687 |
* Default 'monthly'. |
|
1688 |
* @type string|int $limit Number of links to limit the query to. Default empty (no limit). |
|
1689 |
* @type string $format Format each link should take using the $before and $after args. |
|
1690 |
* Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html' |
|
1691 |
* (`<li>` tag), or a custom format, which generates a link anchor |
|
1692 |
* with $before preceding and $after succeeding. Default 'html'. |
|
1693 |
* @type string $before Markup to prepend to the beginning of each link. Default empty. |
|
1694 |
* @type string $after Markup to append to the end of each link. Default empty. |
|
1695 |
* @type bool $show_post_count Whether to display the post count alongside the link. Default false. |
|
1696 |
* @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo. |
|
1697 |
* @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. |
|
1698 |
* Default 'DESC'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* @type string $post_type Post type. Default 'post'. |
5 | 1700 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1701 |
* @return string|void String when retrieving. |
0 | 1702 |
*/ |
5 | 1703 |
function wp_get_archives( $args = '' ) { |
0 | 1704 |
global $wpdb, $wp_locale; |
1705 |
||
1706 |
$defaults = array( |
|
1707 |
'type' => 'monthly', 'limit' => '', |
|
1708 |
'format' => 'html', 'before' => '', |
|
1709 |
'after' => '', 'show_post_count' => false, |
|
1710 |
'echo' => 1, 'order' => 'DESC', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
'post_type' => 'post' |
0 | 1712 |
); |
1713 |
||
1714 |
$r = wp_parse_args( $args, $defaults ); |
|
1715 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
$post_type_object = get_post_type_object( $r['post_type'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
if ( ! is_post_type_viewable( $post_type_object ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
$r['post_type'] = $post_type_object->name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
|
5 | 1722 |
if ( '' == $r['type'] ) { |
1723 |
$r['type'] = 'monthly'; |
|
0 | 1724 |
} |
1725 |
||
5 | 1726 |
if ( ! empty( $r['limit'] ) ) { |
1727 |
$r['limit'] = absint( $r['limit'] ); |
|
1728 |
$r['limit'] = ' LIMIT ' . $r['limit']; |
|
1729 |
} |
|
1730 |
||
1731 |
$order = strtoupper( $r['order'] ); |
|
1732 |
if ( $order !== 'ASC' ) { |
|
0 | 1733 |
$order = 'DESC'; |
5 | 1734 |
} |
0 | 1735 |
|
1736 |
// this is what will separate dates on weekly archive links |
|
1737 |
$archive_week_separator = '–'; |
|
1738 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] ); |
0 | 1740 |
|
5 | 1741 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* Filters the SQL WHERE clause for retrieving archives. |
5 | 1743 |
* |
1744 |
* @since 2.2.0 |
|
1745 |
* |
|
1746 |
* @param string $sql_where Portion of SQL query containing the WHERE clause. |
|
1747 |
* @param array $r An array of default arguments. |
|
1748 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
$where = apply_filters( 'getarchives_where', $sql_where, $r ); |
5 | 1750 |
|
1751 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
* Filters the SQL JOIN clause for retrieving archives. |
5 | 1753 |
* |
1754 |
* @since 2.2.0 |
|
1755 |
* |
|
1756 |
* @param string $sql_join Portion of SQL query containing JOIN clause. |
|
1757 |
* @param array $r An array of default arguments. |
|
1758 |
*/ |
|
0 | 1759 |
$join = apply_filters( 'getarchives_join', '', $r ); |
1760 |
||
1761 |
$output = ''; |
|
1762 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
0 | 1764 |
|
5 | 1765 |
$limit = $r['limit']; |
1766 |
||
1767 |
if ( 'monthly' == $r['type'] ) { |
|
0 | 1768 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; |
1769 |
$key = md5( $query ); |
|
1770 |
$key = "wp_get_archives:$key:$last_changed"; |
|
1771 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { |
|
1772 |
$results = $wpdb->get_results( $query ); |
|
1773 |
wp_cache_set( $key, $results, 'posts' ); |
|
1774 |
} |
|
1775 |
if ( $results ) { |
|
5 | 1776 |
$after = $r['after']; |
0 | 1777 |
foreach ( (array) $results as $result ) { |
1778 |
$url = get_month_link( $result->year, $result->month ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
if ( 'post' !== $r['post_type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
$url = add_query_arg( 'post_type', $r['post_type'], $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
} |
0 | 1782 |
/* translators: 1: month name, 2: 4-digit year */ |
5 | 1783 |
$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); |
1784 |
if ( $r['show_post_count'] ) { |
|
1785 |
$r['after'] = ' (' . $result->posts . ')' . $after; |
|
1786 |
} |
|
1787 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); |
|
0 | 1788 |
} |
1789 |
} |
|
5 | 1790 |
} elseif ( 'yearly' == $r['type'] ) { |
0 | 1791 |
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; |
1792 |
$key = md5( $query ); |
|
1793 |
$key = "wp_get_archives:$key:$last_changed"; |
|
1794 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { |
|
1795 |
$results = $wpdb->get_results( $query ); |
|
1796 |
wp_cache_set( $key, $results, 'posts' ); |
|
1797 |
} |
|
1798 |
if ( $results ) { |
|
5 | 1799 |
$after = $r['after']; |
0 | 1800 |
foreach ( (array) $results as $result) { |
5 | 1801 |
$url = get_year_link( $result->year ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
if ( 'post' !== $r['post_type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
$url = add_query_arg( 'post_type', $r['post_type'], $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1804 |
} |
5 | 1805 |
$text = sprintf( '%d', $result->year ); |
1806 |
if ( $r['show_post_count'] ) { |
|
1807 |
$r['after'] = ' (' . $result->posts . ')' . $after; |
|
1808 |
} |
|
1809 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); |
|
0 | 1810 |
} |
1811 |
} |
|
5 | 1812 |
} elseif ( 'daily' == $r['type'] ) { |
0 | 1813 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit"; |
1814 |
$key = md5( $query ); |
|
1815 |
$key = "wp_get_archives:$key:$last_changed"; |
|
1816 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { |
|
1817 |
$results = $wpdb->get_results( $query ); |
|
1818 |
wp_cache_set( $key, $results, 'posts' ); |
|
1819 |
} |
|
1820 |
if ( $results ) { |
|
5 | 1821 |
$after = $r['after']; |
0 | 1822 |
foreach ( (array) $results as $result ) { |
5 | 1823 |
$url = get_day_link( $result->year, $result->month, $result->dayofmonth ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
if ( 'post' !== $r['post_type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
$url = add_query_arg( 'post_type', $r['post_type'], $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
} |
5 | 1827 |
$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
$text = mysql2date( get_option( 'date_format' ), $date ); |
5 | 1829 |
if ( $r['show_post_count'] ) { |
1830 |
$r['after'] = ' (' . $result->posts . ')' . $after; |
|
1831 |
} |
|
1832 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); |
|
0 | 1833 |
} |
1834 |
} |
|
5 | 1835 |
} elseif ( 'weekly' == $r['type'] ) { |
0 | 1836 |
$week = _wp_mysql_week( '`post_date`' ); |
1837 |
$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; |
|
1838 |
$key = md5( $query ); |
|
1839 |
$key = "wp_get_archives:$key:$last_changed"; |
|
1840 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { |
|
1841 |
$results = $wpdb->get_results( $query ); |
|
1842 |
wp_cache_set( $key, $results, 'posts' ); |
|
1843 |
} |
|
1844 |
$arc_w_last = ''; |
|
1845 |
if ( $results ) { |
|
5 | 1846 |
$after = $r['after']; |
1847 |
foreach ( (array) $results as $result ) { |
|
1848 |
if ( $result->week != $arc_w_last ) { |
|
1849 |
$arc_year = $result->yr; |
|
1850 |
$arc_w_last = $result->week; |
|
1851 |
$arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
$arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
$arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1854 |
$url = add_query_arg( array( 'm' => $arc_year, 'w' => $result->week, ), home_url( '/' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1855 |
if ( 'post' !== $r['post_type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1856 |
$url = add_query_arg( 'post_type', $r['post_type'], $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
} |
5 | 1858 |
$text = $arc_week_start . $archive_week_separator . $arc_week_end; |
1859 |
if ( $r['show_post_count'] ) { |
|
1860 |
$r['after'] = ' (' . $result->posts . ')' . $after; |
|
0 | 1861 |
} |
5 | 1862 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); |
0 | 1863 |
} |
5 | 1864 |
} |
0 | 1865 |
} |
5 | 1866 |
} elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) { |
1867 |
$orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC '; |
|
0 | 1868 |
$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; |
1869 |
$key = md5( $query ); |
|
1870 |
$key = "wp_get_archives:$key:$last_changed"; |
|
1871 |
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { |
|
1872 |
$results = $wpdb->get_results( $query ); |
|
1873 |
wp_cache_set( $key, $results, 'posts' ); |
|
1874 |
} |
|
1875 |
if ( $results ) { |
|
1876 |
foreach ( (array) $results as $result ) { |
|
1877 |
if ( $result->post_date != '0000-00-00 00:00:00' ) { |
|
5 | 1878 |
$url = get_permalink( $result ); |
0 | 1879 |
if ( $result->post_title ) { |
1880 |
/** This filter is documented in wp-includes/post-template.php */ |
|
1881 |
$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) ); |
|
1882 |
} else { |
|
1883 |
$text = $result->ID; |
|
1884 |
} |
|
5 | 1885 |
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); |
0 | 1886 |
} |
1887 |
} |
|
1888 |
} |
|
1889 |
} |
|
5 | 1890 |
if ( $r['echo'] ) { |
0 | 1891 |
echo $output; |
5 | 1892 |
} else { |
0 | 1893 |
return $output; |
5 | 1894 |
} |
0 | 1895 |
} |
1896 |
||
1897 |
/** |
|
1898 |
* Get number of days since the start of the week. |
|
1899 |
* |
|
1900 |
* @since 1.5.0 |
|
1901 |
* |
|
1902 |
* @param int $num Number of day. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
* @return float Days since the start of the week. |
0 | 1904 |
*/ |
1905 |
function calendar_week_mod($num) { |
|
1906 |
$base = 7; |
|
1907 |
return ($num - $base*floor($num/$base)); |
|
1908 |
} |
|
1909 |
||
1910 |
/** |
|
1911 |
* Display calendar with days that have posts as links. |
|
1912 |
* |
|
1913 |
* The calendar is cached, which will be retrieved, if it exists. If there are |
|
1914 |
* no posts for the month, then it will not be displayed. |
|
1915 |
* |
|
1916 |
* @since 1.0.0 |
|
1917 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
* @global int $m |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
* @global int $monthnum |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
* @global int $year |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
* @global array $posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1924 |
* |
0 | 1925 |
* @param bool $initial Optional, default is true. Use initial calendar names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @param bool $echo Optional, default is true. Set to false for return. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
* @return string|void String when retrieving. |
0 | 1928 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
function get_calendar( $initial = true, $echo = true ) { |
0 | 1930 |
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
1931 |
||
1932 |
$key = md5( $m . $monthnum . $year ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
$cache = wp_cache_get( 'get_calendar', 'calendar' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
/** This filter is documented in wp-includes/general-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
$output = apply_filters( 'get_calendar', $cache[ $key ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
if ( $echo ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
echo $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1941 |
return; |
0 | 1942 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1943 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1944 |
return $output; |
0 | 1945 |
} |
1946 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
if ( ! is_array( $cache ) ) { |
0 | 1948 |
$cache = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1949 |
} |
0 | 1950 |
|
1951 |
// Quick check. If we have no posts at all, abort! |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
if ( ! $posts ) { |
0 | 1953 |
$gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1954 |
if ( ! $gotsome ) { |
0 | 1955 |
$cache[ $key ] = ''; |
1956 |
wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
|
1957 |
return; |
|
1958 |
} |
|
1959 |
} |
|
1960 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
if ( isset( $_GET['w'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
$w = (int) $_GET['w']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
} |
0 | 1964 |
// week_begins = 0 stands for Sunday |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
$week_begins = (int) get_option( 'start_of_week' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
$ts = current_time( 'timestamp' ); |
0 | 1967 |
|
1968 |
// Let's figure out when we are |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1969 |
if ( ! empty( $monthnum ) && ! empty( $year ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1970 |
$thismonth = zeroise( intval( $monthnum ), 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
$thisyear = (int) $year; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
} elseif ( ! empty( $w ) ) { |
0 | 1973 |
// We need to get the month from MySQL |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
$thisyear = (int) substr( $m, 0, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
//it seems MySQL's weeks disagree with PHP's |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1976 |
$d = ( ( $w - 1 ) * 7 ) + 6; |
0 | 1977 |
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
} elseif ( ! empty( $m ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
$thisyear = (int) substr( $m, 0, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
if ( strlen( $m ) < 6 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
$thismonth = '01'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
$thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
} |
0 | 1985 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
$thisyear = gmdate( 'Y', $ts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
$thismonth = gmdate( 'm', $ts ); |
0 | 1988 |
} |
1989 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
$unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
$last_day = date( 't', $unixmonth ); |
0 | 1992 |
|
1993 |
// Get the next and previous month and year with at least one post |
|
1994 |
$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
|
1995 |
FROM $wpdb->posts |
|
1996 |
WHERE post_date < '$thisyear-$thismonth-01' |
|
1997 |
AND post_type = 'post' AND post_status = 'publish' |
|
1998 |
ORDER BY post_date DESC |
|
1999 |
LIMIT 1"); |
|
2000 |
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
|
2001 |
FROM $wpdb->posts |
|
2002 |
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' |
|
2003 |
AND post_type = 'post' AND post_status = 'publish' |
|
2004 |
ORDER BY post_date ASC |
|
2005 |
LIMIT 1"); |
|
2006 |
||
2007 |
/* translators: Calendar caption: 1: month name, 2: 4-digit year */ |
|
2008 |
$calendar_caption = _x('%1$s %2$s', 'calendar caption'); |
|
2009 |
$calendar_output = '<table id="wp-calendar"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
<caption>' . sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
$calendar_caption, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
$wp_locale->get_month( $thismonth ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
date( 'Y', $unixmonth ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2014 |
) . '</caption> |
0 | 2015 |
<thead> |
2016 |
<tr>'; |
|
2017 |
||
2018 |
$myweek = array(); |
|
2019 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
$myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 ); |
0 | 2022 |
} |
2023 |
||
2024 |
foreach ( $myweek as $wd ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
$day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
$wd = esc_attr( $wd ); |
0 | 2027 |
$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>"; |
2028 |
} |
|
2029 |
||
2030 |
$calendar_output .= ' |
|
2031 |
</tr> |
|
2032 |
</thead> |
|
2033 |
||
2034 |
<tfoot> |
|
2035 |
<tr>'; |
|
2036 |
||
2037 |
if ( $previous ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
$wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
'</a></td>'; |
0 | 2041 |
} else { |
2042 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; |
|
2043 |
} |
|
2044 |
||
2045 |
$calendar_output .= "\n\t\t".'<td class="pad"> </td>'; |
|
2046 |
||
2047 |
if ( $next ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link( $next->year, $next->month ) . '">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
$wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
' »</a></td>'; |
0 | 2051 |
} else { |
2052 |
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; |
|
2053 |
} |
|
2054 |
||
2055 |
$calendar_output .= ' |
|
2056 |
</tr> |
|
2057 |
</tfoot> |
|
2058 |
||
2059 |
<tbody> |
|
2060 |
<tr>'; |
|
2061 |
||
5 | 2062 |
$daywithpost = array(); |
2063 |
||
0 | 2064 |
// Get days with posts |
2065 |
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) |
|
2066 |
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' |
|
2067 |
AND post_type = 'post' AND post_status = 'publish' |
|
2068 |
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); |
|
2069 |
if ( $dayswithposts ) { |
|
2070 |
foreach ( (array) $dayswithposts as $daywith ) { |
|
2071 |
$daywithpost[] = $daywith[0]; |
|
2072 |
} |
|
2073 |
} |
|
2074 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
// See how much we should pad in the beginning |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
$pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
if ( 0 != $pad ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
$calendar_output .= "\n\t\t".'<td colspan="'. esc_attr( $pad ) .'" class="pad"> </td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
$newrow = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
$daysinmonth = (int) date( 't', $unixmonth ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
if ( isset($newrow) && $newrow ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
$newrow = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
if ( $day == gmdate( 'j', $ts ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
$thismonth == gmdate( 'm', $ts ) && |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
$thisyear == gmdate( 'Y', $ts ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
$calendar_output .= '<td id="today">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
$calendar_output .= '<td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2097 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
if ( in_array( $day, $daywithpost ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
// any posts today? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
$date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2101 |
/* translators: Post calendar label. 1: Date */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
$label = sprintf( __( 'Posts published on %s' ), $date_format ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
$calendar_output .= sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
get_day_link( $thisyear, $thismonth, $day ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
esc_attr( $label ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
$day |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
$calendar_output .= $day; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
$calendar_output .= '</td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
$newrow = true; |
0 | 2116 |
} |
2117 |
} |
|
2118 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
$pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
if ( $pad != 0 && $pad != 7 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2121 |
$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr( $pad ) .'"> </td>'; |
0 | 2122 |
} |
2123 |
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; |
|
2124 |
||
2125 |
$cache[ $key ] = $calendar_output; |
|
2126 |
wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
|
2127 |
||
5 | 2128 |
if ( $echo ) { |
2129 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2130 |
* Filters the HTML calendar output. |
5 | 2131 |
* |
2132 |
* @since 3.0.0 |
|
2133 |
* |
|
2134 |
* @param string $calendar_output HTML output of the calendar. |
|
2135 |
*/ |
|
2136 |
echo apply_filters( 'get_calendar', $calendar_output ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2137 |
return; |
5 | 2138 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2139 |
/** This filter is documented in wp-includes/general-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
return apply_filters( 'get_calendar', $calendar_output ); |
0 | 2141 |
} |
2142 |
||
2143 |
/** |
|
2144 |
* Purge the cached results of get_calendar. |
|
2145 |
* |
|
2146 |
* @see get_calendar |
|
2147 |
* @since 2.1.0 |
|
2148 |
*/ |
|
2149 |
function delete_get_calendar_cache() { |
|
2150 |
wp_cache_delete( 'get_calendar', 'calendar' ); |
|
2151 |
} |
|
2152 |
||
2153 |
/** |
|
2154 |
* Display all of the allowed tags in HTML format with attributes. |
|
2155 |
* |
|
2156 |
* This is useful for displaying in the comment area, which elements and |
|
2157 |
* attributes are supported. As well as any plugins which want to display it. |
|
2158 |
* |
|
2159 |
* @since 1.0.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2161 |
* @global array $allowedtags |
0 | 2162 |
* |
2163 |
* @return string HTML allowed tags entity encoded. |
|
2164 |
*/ |
|
2165 |
function allowed_tags() { |
|
2166 |
global $allowedtags; |
|
2167 |
$allowed = ''; |
|
2168 |
foreach ( (array) $allowedtags as $tag => $attributes ) { |
|
2169 |
$allowed .= '<'.$tag; |
|
2170 |
if ( 0 < count($attributes) ) { |
|
2171 |
foreach ( $attributes as $attribute => $limits ) { |
|
2172 |
$allowed .= ' '.$attribute.'=""'; |
|
2173 |
} |
|
2174 |
} |
|
2175 |
$allowed .= '> '; |
|
2176 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
return htmlentities( $allowed ); |
0 | 2178 |
} |
2179 |
||
2180 |
/***** Date/Time tags *****/ |
|
2181 |
||
2182 |
/** |
|
2183 |
* Outputs the date in iso8601 format for xml files. |
|
2184 |
* |
|
2185 |
* @since 1.0.0 |
|
2186 |
*/ |
|
2187 |
function the_date_xml() { |
|
2188 |
echo mysql2date( 'Y-m-d', get_post()->post_date, false ); |
|
2189 |
} |
|
2190 |
||
2191 |
/** |
|
5 | 2192 |
* Display or Retrieve the date the current post was written (once per date) |
0 | 2193 |
* |
2194 |
* Will only output the date if the current post's date is different from the |
|
2195 |
* previous one output. |
|
2196 |
* |
|
2197 |
* i.e. Only one date listing will show per day worth of posts shown in the loop, even if the |
|
2198 |
* function is called several times for each post. |
|
2199 |
* |
|
2200 |
* HTML output can be filtered with 'the_date'. |
|
2201 |
* Date string output can be filtered with 'get_the_date'. |
|
2202 |
* |
|
2203 |
* @since 0.71 |
|
5 | 2204 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2205 |
* @global string|int|bool $currentday |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
* @global string|int|bool $previousday |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified. |
0 | 2209 |
* @param string $before Optional. Output before the date. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
* @param string $after Optional. Output after the date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
* @param bool $echo Optional, default is display. Whether to echo the date or return it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
* @return string|void String if retrieving. |
0 | 2213 |
*/ |
2214 |
function the_date( $d = '', $before = '', $after = '', $echo = true ) { |
|
2215 |
global $currentday, $previousday; |
|
5 | 2216 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
if ( is_new_day() ) { |
5 | 2218 |
$the_date = $before . get_the_date( $d ) . $after; |
0 | 2219 |
$previousday = $currentday; |
2220 |
||
5 | 2221 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* Filters the date a post was published for display. |
5 | 2223 |
* |
2224 |
* @since 0.71 |
|
2225 |
* |
|
2226 |
* @param string $the_date The formatted date string. |
|
2227 |
* @param string $d PHP date format. Defaults to 'date_format' option |
|
2228 |
* if not specified. |
|
2229 |
* @param string $before HTML output before the date. |
|
2230 |
* @param string $after HTML output after the date. |
|
2231 |
*/ |
|
2232 |
$the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); |
|
0 | 2233 |
|
2234 |
if ( $echo ) |
|
2235 |
echo $the_date; |
|
2236 |
else |
|
2237 |
return $the_date; |
|
2238 |
} |
|
2239 |
} |
|
2240 |
||
2241 |
/** |
|
5 | 2242 |
* Retrieve the date on which the post was written. |
0 | 2243 |
* |
2244 |
* Unlike the_date() this function will always return the date. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
* Modify output with the {@see 'get_the_date'} filter. |
0 | 2246 |
* |
2247 |
* @since 3.0.0 |
|
2248 |
* |
|
5 | 2249 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified. |
2250 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
|
2251 |
* @return false|string Date the current post was written. False on failure. |
|
0 | 2252 |
*/ |
5 | 2253 |
function get_the_date( $d = '', $post = null ) { |
2254 |
$post = get_post( $post ); |
|
2255 |
||
2256 |
if ( ! $post ) { |
|
2257 |
return false; |
|
2258 |
} |
|
0 | 2259 |
|
5 | 2260 |
if ( '' == $d ) { |
2261 |
$the_date = mysql2date( get_option( 'date_format' ), $post->post_date ); |
|
2262 |
} else { |
|
2263 |
$the_date = mysql2date( $d, $post->post_date ); |
|
2264 |
} |
|
0 | 2265 |
|
5 | 2266 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
* Filters the date a post was published. |
5 | 2268 |
* |
2269 |
* @since 3.0.0 |
|
2270 |
* |
|
2271 |
* @param string $the_date The formatted date. |
|
2272 |
* @param string $d PHP date format. Defaults to 'date_format' option |
|
2273 |
* if not specified. |
|
2274 |
* @param int|WP_Post $post The post object or ID. |
|
2275 |
*/ |
|
2276 |
return apply_filters( 'get_the_date', $the_date, $d, $post ); |
|
0 | 2277 |
} |
2278 |
||
2279 |
/** |
|
2280 |
* Display the date on which the post was last modified. |
|
2281 |
* |
|
2282 |
* @since 2.1.0 |
|
2283 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified. |
0 | 2285 |
* @param string $before Optional. Output before the date. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2286 |
* @param string $after Optional. Output after the date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
* @param bool $echo Optional, default is display. Whether to echo the date or return it. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2288 |
* @return string|void String if retrieving. |
0 | 2289 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2290 |
function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) { |
0 | 2291 |
$the_modified_date = $before . get_the_modified_date($d) . $after; |
5 | 2292 |
|
2293 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2294 |
* Filters the date a post was last modified for display. |
5 | 2295 |
* |
2296 |
* @since 2.1.0 |
|
2297 |
* |
|
2298 |
* @param string $the_modified_date The last modified date. |
|
2299 |
* @param string $d PHP date format. Defaults to 'date_format' option |
|
2300 |
* if not specified. |
|
2301 |
* @param string $before HTML output before the date. |
|
2302 |
* @param string $after HTML output after the date. |
|
2303 |
*/ |
|
2304 |
$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after ); |
|
0 | 2305 |
|
2306 |
if ( $echo ) |
|
2307 |
echo $the_modified_date; |
|
2308 |
else |
|
2309 |
return $the_modified_date; |
|
2310 |
||
2311 |
} |
|
2312 |
||
2313 |
/** |
|
2314 |
* Retrieve the date on which the post was last modified. |
|
2315 |
* |
|
2316 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
* @since 4.6.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
* @param string $d Optional. PHP date format defaults to the date_format option if not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
* @return false|string Date the current post was modified. False on failure. |
0 | 2322 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
function get_the_modified_date( $d = '', $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2327 |
// For backward compatibility, failures go through the filter below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2328 |
$the_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2329 |
} elseif ( empty( $d ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2330 |
$the_time = get_post_modified_time( get_option( 'date_format' ), false, $post, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
$the_time = get_post_modified_time( $d, false, $post, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2333 |
} |
5 | 2334 |
|
2335 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2336 |
* Filters the date a post was last modified. |
5 | 2337 |
* |
2338 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
* @since 4.6.0 Added the `$post` parameter. |
5 | 2340 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
* @param string|bool $the_time The formatted date or false if no post is found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
* @param string $d PHP date format. Defaults to value specified in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
* 'date_format' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
* @param WP_Post|null $post WP_Post object or null if no post is found. |
5 | 2345 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
return apply_filters( 'get_the_modified_date', $the_time, $d, $post ); |
0 | 2347 |
} |
2348 |
||
2349 |
/** |
|
2350 |
* Display the time at which the post was written. |
|
2351 |
* |
|
2352 |
* @since 0.71 |
|
2353 |
* |
|
2354 |
* @param string $d Either 'G', 'U', or php date format. |
|
2355 |
*/ |
|
2356 |
function the_time( $d = '' ) { |
|
5 | 2357 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2358 |
* Filters the time a post was written for display. |
5 | 2359 |
* |
2360 |
* @since 0.71 |
|
2361 |
* |
|
2362 |
* @param string $get_the_time The formatted time. |
|
2363 |
* @param string $d The time format. Accepts 'G', 'U', |
|
2364 |
* or php date format. |
|
2365 |
*/ |
|
2366 |
echo apply_filters( 'the_time', get_the_time( $d ), $d ); |
|
0 | 2367 |
} |
2368 |
||
2369 |
/** |
|
2370 |
* Retrieve the time at which the post was written. |
|
2371 |
* |
|
2372 |
* @since 1.5.0 |
|
2373 |
* |
|
5 | 2374 |
* @param string $d Optional. Format to use for retrieving the time the post |
2375 |
* was written. Either 'G', 'U', or php date format defaults |
|
2376 |
* to the value specified in the time_format option. Default empty. |
|
2377 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2378 |
* @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. |
0 | 2379 |
*/ |
2380 |
function get_the_time( $d = '', $post = null ) { |
|
2381 |
$post = get_post($post); |
|
2382 |
||
5 | 2383 |
if ( ! $post ) { |
2384 |
return false; |
|
2385 |
} |
|
2386 |
||
0 | 2387 |
if ( '' == $d ) |
2388 |
$the_time = get_post_time(get_option('time_format'), false, $post, true); |
|
2389 |
else |
|
2390 |
$the_time = get_post_time($d, false, $post, true); |
|
5 | 2391 |
|
2392 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
* Filters the time a post was written. |
5 | 2394 |
* |
2395 |
* @since 1.5.0 |
|
2396 |
* |
|
2397 |
* @param string $the_time The formatted time. |
|
2398 |
* @param string $d Format to use for retrieving the time the post was written. |
|
2399 |
* Accepts 'G', 'U', or php date format value specified |
|
2400 |
* in 'time_format' option. Default empty. |
|
2401 |
* @param int|WP_Post $post WP_Post object or ID. |
|
2402 |
*/ |
|
2403 |
return apply_filters( 'get_the_time', $the_time, $d, $post ); |
|
0 | 2404 |
} |
2405 |
||
2406 |
/** |
|
2407 |
* Retrieve the time at which the post was written. |
|
2408 |
* |
|
2409 |
* @since 2.0.0 |
|
2410 |
* |
|
5 | 2411 |
* @param string $d Optional. Format to use for retrieving the time the post |
2412 |
* was written. Either 'G', 'U', or php date format. Default 'U'. |
|
2413 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. |
|
2414 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object. |
|
2415 |
* @param bool $translate Whether to translate the time string. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2416 |
* @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. |
0 | 2417 |
*/ |
5 | 2418 |
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { |
0 | 2419 |
$post = get_post($post); |
2420 |
||
5 | 2421 |
if ( ! $post ) { |
2422 |
return false; |
|
2423 |
} |
|
2424 |
||
0 | 2425 |
if ( $gmt ) |
2426 |
$time = $post->post_date_gmt; |
|
2427 |
else |
|
2428 |
$time = $post->post_date; |
|
2429 |
||
2430 |
$time = mysql2date($d, $time, $translate); |
|
5 | 2431 |
|
2432 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2433 |
* Filters the localized time a post was written. |
5 | 2434 |
* |
2435 |
* @since 2.6.0 |
|
2436 |
* |
|
2437 |
* @param string $time The formatted time. |
|
2438 |
* @param string $d Format to use for retrieving the time the post was written. |
|
2439 |
* Accepts 'G', 'U', or php date format. Default 'U'. |
|
2440 |
* @param bool $gmt Whether to retrieve the GMT time. Default false. |
|
2441 |
*/ |
|
2442 |
return apply_filters( 'get_post_time', $time, $d, $gmt ); |
|
0 | 2443 |
} |
2444 |
||
2445 |
/** |
|
2446 |
* Display the time at which the post was last modified. |
|
2447 |
* |
|
2448 |
* @since 2.0.0 |
|
2449 |
* |
|
2450 |
* @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option. |
|
2451 |
*/ |
|
2452 |
function the_modified_time($d = '') { |
|
5 | 2453 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
* Filters the localized time a post was last modified, for display. |
5 | 2455 |
* |
2456 |
* @since 2.0.0 |
|
2457 |
* |
|
2458 |
* @param string $get_the_modified_time The formatted time. |
|
2459 |
* @param string $d The time format. Accepts 'G', 'U', |
|
2460 |
* or php date format. Defaults to value |
|
2461 |
* specified in 'time_format' option. |
|
2462 |
*/ |
|
2463 |
echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d ); |
|
0 | 2464 |
} |
2465 |
||
2466 |
/** |
|
2467 |
* Retrieve the time at which the post was last modified. |
|
2468 |
* |
|
2469 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2470 |
* @since 4.6.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2472 |
* @param string $d Optional. Format to use for retrieving the time the post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2473 |
* was modified. Either 'G', 'U', or php date format defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2474 |
* to the value specified in the time_format option. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2475 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2476 |
* @return false|string Formatted date string or Unix timestamp. False on failure. |
0 | 2477 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
function get_the_modified_time( $d = '', $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2479 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2480 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2482 |
// For backward compatibility, failures go through the filter below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2483 |
$the_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2484 |
} elseif ( empty( $d ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2485 |
$the_time = get_post_modified_time( get_option( 'time_format' ), false, $post, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2486 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2487 |
$the_time = get_post_modified_time( $d, false, $post, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2488 |
} |
5 | 2489 |
|
2490 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2491 |
* Filters the localized time a post was last modified. |
5 | 2492 |
* |
2493 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2494 |
* @since 4.6.0 Added the `$post` parameter. |
5 | 2495 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
* @param string|bool $the_time The formatted time or false if no post is found. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
* @param string $d Format to use for retrieving the time the post was |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2498 |
* written. Accepts 'G', 'U', or php date format. Defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
* to value specified in 'time_format' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2500 |
* @param WP_Post|null $post WP_Post object or null if no post is found. |
5 | 2501 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2502 |
return apply_filters( 'get_the_modified_time', $the_time, $d, $post ); |
0 | 2503 |
} |
2504 |
||
2505 |
/** |
|
2506 |
* Retrieve the time at which the post was last modified. |
|
2507 |
* |
|
2508 |
* @since 2.0.0 |
|
2509 |
* |
|
5 | 2510 |
* @param string $d Optional. Format to use for retrieving the time the post |
2511 |
* was modified. Either 'G', 'U', or php date format. Default 'U'. |
|
2512 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. |
|
2513 |
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object. |
|
2514 |
* @param bool $translate Whether to translate the time string. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2515 |
* @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. |
0 | 2516 |
*/ |
2517 |
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { |
|
2518 |
$post = get_post($post); |
|
2519 |
||
5 | 2520 |
if ( ! $post ) { |
2521 |
return false; |
|
2522 |
} |
|
2523 |
||
0 | 2524 |
if ( $gmt ) |
2525 |
$time = $post->post_modified_gmt; |
|
2526 |
else |
|
2527 |
$time = $post->post_modified; |
|
2528 |
$time = mysql2date($d, $time, $translate); |
|
2529 |
||
5 | 2530 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2531 |
* Filters the localized time a post was last modified. |
5 | 2532 |
* |
2533 |
* @since 2.8.0 |
|
2534 |
* |
|
2535 |
* @param string $time The formatted time. |
|
2536 |
* @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'. |
|
2537 |
* @param bool $gmt Whether to return the GMT time. Default false. |
|
2538 |
*/ |
|
2539 |
return apply_filters( 'get_post_modified_time', $time, $d, $gmt ); |
|
0 | 2540 |
} |
2541 |
||
2542 |
/** |
|
2543 |
* Display the weekday on which the post was written. |
|
2544 |
* |
|
2545 |
* @since 0.71 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2546 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2547 |
* @global WP_Locale $wp_locale |
0 | 2548 |
*/ |
2549 |
function the_weekday() { |
|
2550 |
global $wp_locale; |
|
2551 |
$the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) ); |
|
5 | 2552 |
|
2553 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2554 |
* Filters the weekday on which the post was written, for display. |
5 | 2555 |
* |
2556 |
* @since 0.71 |
|
2557 |
* |
|
2558 |
* @param string $the_weekday |
|
2559 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2560 |
echo apply_filters( 'the_weekday', $the_weekday ); |
0 | 2561 |
} |
2562 |
||
2563 |
/** |
|
2564 |
* Display the weekday on which the post was written. |
|
2565 |
* |
|
2566 |
* Will only output the weekday if the current post's weekday is different from |
|
2567 |
* the previous one output. |
|
2568 |
* |
|
2569 |
* @since 0.71 |
|
2570 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2572 |
* @global string|int|bool $currentday |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2573 |
* @global string|int|bool $previousweekday |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
* |
0 | 2575 |
* @param string $before Optional Output before the date. |
2576 |
* @param string $after Optional Output after the date. |
|
2577 |
*/ |
|
2578 |
function the_weekday_date($before='',$after='') { |
|
2579 |
global $wp_locale, $currentday, $previousweekday; |
|
2580 |
$the_weekday_date = ''; |
|
2581 |
if ( $currentday != $previousweekday ) { |
|
2582 |
$the_weekday_date .= $before; |
|
2583 |
$the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) ); |
|
2584 |
$the_weekday_date .= $after; |
|
2585 |
$previousweekday = $currentday; |
|
2586 |
} |
|
5 | 2587 |
|
2588 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2589 |
* Filters the localized date on which the post was written, for display. |
5 | 2590 |
* |
2591 |
* @since 0.71 |
|
2592 |
* |
|
2593 |
* @param string $the_weekday_date |
|
2594 |
* @param string $before The HTML to output before the date. |
|
2595 |
* @param string $after The HTML to output after the date. |
|
2596 |
*/ |
|
2597 |
$the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after ); |
|
0 | 2598 |
echo $the_weekday_date; |
2599 |
} |
|
2600 |
||
2601 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* Fire the wp_head action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
* See {@see 'wp_head'}. |
0 | 2605 |
* |
2606 |
* @since 1.2.0 |
|
2607 |
*/ |
|
2608 |
function wp_head() { |
|
5 | 2609 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
* Prints scripts or data in the head tag on the front end. |
5 | 2611 |
* |
2612 |
* @since 1.5.0 |
|
2613 |
*/ |
|
2614 |
do_action( 'wp_head' ); |
|
0 | 2615 |
} |
2616 |
||
2617 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2618 |
* Fire the wp_footer action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
* See {@see 'wp_footer'}. |
0 | 2621 |
* |
2622 |
* @since 1.5.1 |
|
2623 |
*/ |
|
2624 |
function wp_footer() { |
|
5 | 2625 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2626 |
* Prints scripts or data before the closing body tag on the front end. |
5 | 2627 |
* |
2628 |
* @since 1.5.1 |
|
2629 |
*/ |
|
2630 |
do_action( 'wp_footer' ); |
|
0 | 2631 |
} |
2632 |
||
2633 |
/** |
|
2634 |
* Display the links to the general feeds. |
|
2635 |
* |
|
2636 |
* @since 2.8.0 |
|
2637 |
* |
|
2638 |
* @param array $args Optional arguments. |
|
2639 |
*/ |
|
2640 |
function feed_links( $args = array() ) { |
|
2641 |
if ( !current_theme_supports('automatic-feed-links') ) |
|
2642 |
return; |
|
2643 |
||
2644 |
$defaults = array( |
|
2645 |
/* translators: Separator between blog name and feed type in feed links */ |
|
2646 |
'separator' => _x('»', 'feed link'), |
|
2647 |
/* translators: 1: blog title, 2: separator (raquo) */ |
|
2648 |
'feedtitle' => __('%1$s %2$s Feed'), |
|
2649 |
/* translators: 1: blog title, 2: separator (raquo) */ |
|
2650 |
'comstitle' => __('%1$s %2$s Comments Feed'), |
|
2651 |
); |
|
2652 |
||
2653 |
$args = wp_parse_args( $args, $defaults ); |
|
2654 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2655 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2656 |
* Filters whether to display the posts feed link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2657 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2659 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2660 |
* @param bool $show Whether to display the posts feed link. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2661 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2662 |
if ( apply_filters( 'feed_links_show_posts_feed', true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2663 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2664 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2667 |
* Filters whether to display the comments feed link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2668 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2669 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2670 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2671 |
* @param bool $show Whether to display the comments feed link. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2672 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
if ( apply_filters( 'feed_links_show_comments_feed', true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2674 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
} |
0 | 2676 |
} |
2677 |
||
2678 |
/** |
|
2679 |
* Display the links to the extra feeds such as category feeds. |
|
2680 |
* |
|
2681 |
* @since 2.8.0 |
|
2682 |
* |
|
2683 |
* @param array $args Optional arguments. |
|
2684 |
*/ |
|
2685 |
function feed_links_extra( $args = array() ) { |
|
2686 |
$defaults = array( |
|
2687 |
/* translators: Separator between blog name and feed type in feed links */ |
|
2688 |
'separator' => _x('»', 'feed link'), |
|
2689 |
/* translators: 1: blog name, 2: separator(raquo), 3: post title */ |
|
2690 |
'singletitle' => __('%1$s %2$s %3$s Comments Feed'), |
|
2691 |
/* translators: 1: blog name, 2: separator(raquo), 3: category name */ |
|
2692 |
'cattitle' => __('%1$s %2$s %3$s Category Feed'), |
|
2693 |
/* translators: 1: blog name, 2: separator(raquo), 3: tag name */ |
|
2694 |
'tagtitle' => __('%1$s %2$s %3$s Tag Feed'), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
/* translators: 1: blog name, 2: separator(raquo), 3: term name, 4: taxonomy singular name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
'taxtitle' => __('%1$s %2$s %3$s %4$s Feed'), |
0 | 2697 |
/* translators: 1: blog name, 2: separator(raquo), 3: author name */ |
2698 |
'authortitle' => __('%1$s %2$s Posts by %3$s Feed'), |
|
2699 |
/* translators: 1: blog name, 2: separator(raquo), 3: search phrase */ |
|
2700 |
'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'), |
|
2701 |
/* translators: 1: blog name, 2: separator(raquo), 3: post type name */ |
|
2702 |
'posttypetitle' => __('%1$s %2$s %3$s Feed'), |
|
2703 |
); |
|
2704 |
||
2705 |
$args = wp_parse_args( $args, $defaults ); |
|
2706 |
||
2707 |
if ( is_singular() ) { |
|
2708 |
$id = 0; |
|
2709 |
$post = get_post( $id ); |
|
2710 |
||
2711 |
if ( comments_open() || pings_open() || $post->comment_count > 0 ) { |
|
5 | 2712 |
$title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); |
0 | 2713 |
$href = get_post_comments_feed_link( $post->ID ); |
2714 |
} |
|
2715 |
} elseif ( is_post_type_archive() ) { |
|
2716 |
$post_type = get_query_var( 'post_type' ); |
|
2717 |
if ( is_array( $post_type ) ) |
|
2718 |
$post_type = reset( $post_type ); |
|
2719 |
||
2720 |
$post_type_obj = get_post_type_object( $post_type ); |
|
2721 |
$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); |
|
2722 |
$href = get_post_type_archive_feed_link( $post_type_obj->name ); |
|
2723 |
} elseif ( is_category() ) { |
|
2724 |
$term = get_queried_object(); |
|
2725 |
||
2726 |
if ( $term ) { |
|
2727 |
$title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name ); |
|
2728 |
$href = get_category_feed_link( $term->term_id ); |
|
2729 |
} |
|
2730 |
} elseif ( is_tag() ) { |
|
2731 |
$term = get_queried_object(); |
|
2732 |
||
2733 |
if ( $term ) { |
|
2734 |
$title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name ); |
|
2735 |
$href = get_tag_feed_link( $term->term_id ); |
|
2736 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2737 |
} elseif ( is_tax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
$term = get_queried_object(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2739 |
$tax = get_taxonomy( $term->taxonomy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2740 |
$title = sprintf( $args['taxtitle'], get_bloginfo('name'), $args['separator'], $term->name, $tax->labels->singular_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2741 |
$href = get_term_feed_link( $term->term_id, $term->taxonomy ); |
0 | 2742 |
} elseif ( is_author() ) { |
2743 |
$author_id = intval( get_query_var('author') ); |
|
2744 |
||
2745 |
$title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ); |
|
2746 |
$href = get_author_feed_link( $author_id ); |
|
2747 |
} elseif ( is_search() ) { |
|
2748 |
$title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) ); |
|
2749 |
$href = get_search_feed_link(); |
|
2750 |
} elseif ( is_post_type_archive() ) { |
|
2751 |
$title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) ); |
|
2752 |
$post_type_obj = get_queried_object(); |
|
2753 |
if ( $post_type_obj ) |
|
2754 |
$href = get_post_type_archive_feed_link( $post_type_obj->name ); |
|
2755 |
} |
|
2756 |
||
2757 |
if ( isset($title) && isset($href) ) |
|
2758 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n"; |
|
2759 |
} |
|
2760 |
||
2761 |
/** |
|
2762 |
* Display the link to the Really Simple Discovery service endpoint. |
|
2763 |
* |
|
2764 |
* @link http://archipelago.phrasewise.com/rsd |
|
2765 |
* @since 2.0.0 |
|
2766 |
*/ |
|
2767 |
function rsd_link() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2768 |
echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n"; |
0 | 2769 |
} |
2770 |
||
2771 |
/** |
|
2772 |
* Display the link to the Windows Live Writer manifest file. |
|
2773 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
* @link https://msdn.microsoft.com/en-us/library/bb463265.aspx |
0 | 2775 |
* @since 2.3.1 |
2776 |
*/ |
|
2777 |
function wlwmanifest_link() { |
|
5 | 2778 |
echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="', |
2779 |
includes_url( 'wlwmanifest.xml' ), '" /> ', "\n"; |
|
0 | 2780 |
} |
2781 |
||
2782 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2783 |
* Displays a noindex meta tag if required by the blog configuration. |
0 | 2784 |
* |
2785 |
* If a blog is marked as not being public then the noindex meta tag will be |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
* output to tell web robots not to index the page content. Add this to the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2787 |
* {@see 'wp_head'} action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2789 |
* Typical usage is as a {@see 'wp_head'} callback: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2790 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2791 |
* add_action( 'wp_head', 'noindex' ); |
0 | 2792 |
* |
2793 |
* @see wp_no_robots |
|
2794 |
* |
|
2795 |
* @since 2.1.0 |
|
2796 |
*/ |
|
2797 |
function noindex() { |
|
2798 |
// If the blog is not public, tell robots to go away. |
|
2799 |
if ( '0' == get_option('blog_public') ) |
|
2800 |
wp_no_robots(); |
|
2801 |
} |
|
2802 |
||
2803 |
/** |
|
2804 |
* Display a noindex meta tag. |
|
2805 |
* |
|
2806 |
* Outputs a noindex meta tag that tells web robots not to index the page content. |
|
2807 |
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' ); |
|
2808 |
* |
|
2809 |
* @since 3.3.0 |
|
2810 |
*/ |
|
2811 |
function wp_no_robots() { |
|
5 | 2812 |
echo "<meta name='robots' content='noindex,follow' />\n"; |
0 | 2813 |
} |
2814 |
||
2815 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
* Display site icon meta tags. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2819 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
* @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
function wp_site_icon() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2823 |
if ( ! has_site_icon() && ! is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2824 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2825 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2826 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2827 |
$meta_tags = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
$icon_32 = get_site_icon_url( 32 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2829 |
if ( empty( $icon_32 ) && is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2830 |
$icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2831 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2832 |
if ( $icon_32 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2833 |
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2834 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2835 |
$icon_192 = get_site_icon_url( 192 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2836 |
if ( $icon_192 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
$icon_180 = get_site_icon_url( 180 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
if ( $icon_180 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
$meta_tags[] = sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( $icon_180 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
$icon_270 = get_site_icon_url( 270 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
if ( $icon_270 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
$meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2848 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
* Filters the site icon meta tags, so Plugins can add their own. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
* @param array $meta_tags Site Icon meta elements. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
$meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2856 |
$meta_tags = array_filter( $meta_tags ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
foreach ( $meta_tags as $meta_tag ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
echo "$meta_tag\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
* Prints resource hints to browsers for pre-fetching, pre-rendering |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
* and pre-connecting to web sites. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2867 |
* Gives hints to browsers to prefetch specific pages or render them |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
* in the background, to perform DNS lookups or to begin the connection |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2869 |
* handshake (DNS, TCP, TLS) in the background. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
* These performance improving indicators work by using `<link rel"…">`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2872 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2874 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2875 |
function wp_resource_hints() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2876 |
$hints = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
'dns-prefetch' => wp_dependencies_unique_hosts(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2878 |
'preconnect' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2879 |
'prefetch' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2880 |
'prerender' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2881 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2883 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2884 |
* Add DNS prefetch for the Emoji CDN. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2885 |
* The path is removed in the foreach loop below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2887 |
/** This filter is documented in wp-includes/formatting.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2888 |
$hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/11/svg/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2889 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2890 |
foreach ( $hints as $relation_type => $urls ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2891 |
$unique_urls = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2892 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2893 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2894 |
* Filters domains and URLs for resource hints of relation type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2895 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2896 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2897 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2898 |
* @param array $urls URLs to print for resource hints. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2899 |
* @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2900 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2901 |
$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2903 |
foreach ( $urls as $key => $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2904 |
$atts = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2906 |
if ( is_array( $url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2907 |
if ( isset( $url['href'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
$atts = $url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
$url = $url['href']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2910 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2913 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
$url = esc_url( $url, array( 'http', 'https' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
if ( ! $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2918 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
if ( isset( $unique_urls[ $url ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
$parsed = wp_parse_url( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2928 |
if ( empty( $parsed['host'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
$url = $parsed['scheme'] . '://' . $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2934 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2935 |
// Use protocol-relative URLs for dns-prefetch or if scheme is missing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2936 |
$url = '//' . $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2940 |
$atts['rel'] = $relation_type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2941 |
$atts['href'] = $url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2942 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2943 |
$unique_urls[ $url ] = $atts; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2944 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2945 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2946 |
foreach ( $unique_urls as $atts ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
$html = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2949 |
foreach ( $atts as $attr => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2950 |
if ( ! is_scalar( $value ) || |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2951 |
( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr )) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2952 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2953 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2954 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2955 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2956 |
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2957 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
if ( ! is_string( $attr ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2959 |
$html .= " $value"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2960 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2961 |
$html .= " $attr='$value'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2962 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2963 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2964 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2965 |
$html = trim( $html ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2966 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
echo "<link $html />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2969 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2970 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2971 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2972 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
* Retrieves a list of unique hosts of all enqueued scripts and styles. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2974 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2975 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2977 |
* @return array A list of unique hosts of enqueued scripts and styles. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
function wp_dependencies_unique_hosts() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2980 |
global $wp_scripts, $wp_styles; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2981 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
$unique_hosts = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2986 |
foreach ( $dependencies->queue as $handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2987 |
if ( ! isset( $dependencies->registered[ $handle ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2988 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2991 |
/* @var _WP_Dependency $dependency */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2992 |
$dependency = $dependencies->registered[ $handle ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2993 |
$parsed = wp_parse_url( $dependency->src ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
$unique_hosts[] = $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
return $unique_hosts; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
* Whether the user can access the visual editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
* Checks if the user can access the visual editor and that it's supported by the user's browser. |
0 | 3009 |
* |
3010 |
* @since 2.0.0 |
|
3011 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3012 |
* @global bool $wp_rich_edit Whether the user can access the visual editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3013 |
* @global bool $is_gecko Whether the browser is Gecko-based. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3014 |
* @global bool $is_opera Whether the browser is Opera. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
* @global bool $is_safari Whether the browser is Safari. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
* @global bool $is_chrome Whether the browser is Chrome. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
* @global bool $is_IE Whether the browser is Internet Explorer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* @global bool $is_edge Whether the browser is Microsoft Edge. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3020 |
* @return bool True if the user can access the visual editor, false otherwise. |
0 | 3021 |
*/ |
3022 |
function user_can_richedit() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3023 |
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge; |
0 | 3024 |
|
3025 |
if ( !isset($wp_rich_edit) ) { |
|
3026 |
$wp_rich_edit = false; |
|
3027 |
||
3028 |
if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users |
|
3029 |
if ( $is_safari ) { |
|
3030 |
$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
} elseif ( $is_IE ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
$wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && !wp_is_mobile() ) ) { |
0 | 3034 |
$wp_rich_edit = true; |
3035 |
} |
|
3036 |
} |
|
3037 |
} |
|
3038 |
||
5 | 3039 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
* Filters whether the user can access the visual editor. |
5 | 3041 |
* |
3042 |
* @since 2.1.0 |
|
3043 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3044 |
* @param bool $wp_rich_edit Whether the user can access the visual editor. |
5 | 3045 |
*/ |
3046 |
return apply_filters( 'user_can_richedit', $wp_rich_edit ); |
|
0 | 3047 |
} |
3048 |
||
3049 |
/** |
|
3050 |
* Find out which editor should be displayed by default. |
|
3051 |
* |
|
3052 |
* Works out which of the two editors to display as the current editor for a |
|
3053 |
* user. The 'html' setting is for the "Text" editor tab. |
|
3054 |
* |
|
3055 |
* @since 2.5.0 |
|
3056 |
* |
|
3057 |
* @return string Either 'tinymce', or 'html', or 'test' |
|
3058 |
*/ |
|
3059 |
function wp_default_editor() { |
|
3060 |
$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults |
|
5 | 3061 |
if ( wp_get_current_user() ) { // look for cookie |
0 | 3062 |
$ed = get_user_setting('editor', 'tinymce'); |
3063 |
$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r; |
|
3064 |
} |
|
5 | 3065 |
|
3066 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* Filters which editor should be displayed by default. |
5 | 3068 |
* |
3069 |
* @since 2.5.0 |
|
3070 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
* @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'. |
5 | 3072 |
*/ |
3073 |
return apply_filters( 'wp_default_editor', $r ); |
|
0 | 3074 |
} |
3075 |
||
3076 |
/** |
|
3077 |
* Renders an editor. |
|
3078 |
* |
|
3079 |
* Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. |
|
5 | 3080 |
* _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144. |
0 | 3081 |
* |
3082 |
* NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
* running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. |
0 | 3084 |
* On the post edit screen several actions can be used to include additional editors |
3085 |
* containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'. |
|
5 | 3086 |
* See https://core.trac.wordpress.org/ticket/19173 for more information. |
0 | 3087 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3088 |
* @see _WP_Editors::editor() |
0 | 3089 |
* @since 3.3.0 |
3090 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
* @param string $content Initial content for the editor. |
0 | 3092 |
* @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
* @param array $settings See _WP_Editors::editor(). |
0 | 3094 |
*/ |
3095 |
function wp_editor( $content, $editor_id, $settings = array() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3096 |
if ( ! class_exists( '_WP_Editors', false ) ) |
0 | 3097 |
require( ABSPATH . WPINC . '/class-wp-editor.php' ); |
3098 |
_WP_Editors::editor($content, $editor_id, $settings); |
|
3099 |
} |
|
3100 |
||
3101 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3102 |
* Outputs the editor scripts, stylesheets, and default settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
* The editor can be initialized when needed after page load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
* See wp.editor.initialize() in wp-admin/js/editor.js for initialization options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3106 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
* @uses _WP_Editors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
function wp_enqueue_editor() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
if ( ! class_exists( '_WP_Editors', false ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
require( ABSPATH . WPINC . '/class-wp-editor.php' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
_WP_Editors::enqueue_default_editor(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
* Enqueue assets needed by the code editor for the given settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
* @see wp_enqueue_editor() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3124 |
* @see _WP_Editors::parse_settings() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3125 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
* Args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3128 |
* @type string $type The MIME type of the file to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
* @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
* @type WP_Theme $theme Theme being edited when on theme editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
* @type string $plugin Plugin being edited when on plugin editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
* @type array $codemirror Additional CodeMirror setting overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3133 |
* @type array $csslint CSSLint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3134 |
* @type array $jshint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
* @type array $htmlhint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3137 |
* @returns array|false Settings for the enqueued code editor, or false if the editor was not enqueued . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3139 |
function wp_enqueue_code_editor( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3140 |
if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
$settings = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
'codemirror' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3146 |
'indentUnit' => 4, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3147 |
'indentWithTabs' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3148 |
'inputStyle' => 'contenteditable', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
'lineNumbers' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3150 |
'lineWrapping' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
'styleActiveLine' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
'continueComments' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
'extraKeys' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
'Ctrl-Space' => 'autocomplete', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
'Ctrl-/' => 'toggleComment', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
'Cmd-/' => 'toggleComment', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
'Alt-F' => 'findPersistent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3158 |
'Ctrl-F' => 'findPersistent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3159 |
'Cmd-F' => 'findPersistent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3160 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3161 |
'direction' => 'ltr', // Code is shown in LTR even in RTL languages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3162 |
'gutters' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3163 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3164 |
'csslint' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
'errors' => true, // Parsing errors. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
'box-model' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3167 |
'display-property-grouping' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
'duplicate-properties' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3169 |
'known-properties' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3170 |
'outline-none' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3171 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3172 |
'jshint' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3173 |
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3174 |
'boss' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3175 |
'curly' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3176 |
'eqeqeq' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
'eqnull' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3178 |
'es3' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3179 |
'expr' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
'immed' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
'noarg' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3182 |
'nonbsp' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
'onevar' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
'quotmark' => 'single', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
'trailing' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
'undef' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3187 |
'unused' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3188 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3189 |
'browser' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
'globals' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
'_' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
'Backbone' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
'jQuery' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
'JSON' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
'wp' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
'htmlhint' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
'tagname-lowercase' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
'attr-lowercase' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
'attr-value-double-quotes' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
'doctype-first' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
'tag-pair' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
'spec-char-escape' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3206 |
'id-unique' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
'src-not-empty' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
'attr-no-duplication' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3209 |
'alt-require' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3210 |
'space-tab-mixed-disabled' => 'tab', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3211 |
'attr-unsafe-chars' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3214 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
$type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3216 |
if ( isset( $args['type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
$type = $args['type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3218 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3219 |
// Remap MIME types to ones that CodeMirror modes will recognize. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3221 |
$type = 'text/x-diff'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3222 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3223 |
} elseif ( isset( $args['file'] ) && false !== strpos( basename( $args['file'] ), '.' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3224 |
$extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3225 |
foreach ( wp_get_mime_types() as $exts => $mime ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3226 |
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3227 |
$type = $mime; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3228 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3229 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3230 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3232 |
// Supply any types that are not matched by wp_get_mime_types(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3233 |
if ( empty( $type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3234 |
switch ( $extension ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3235 |
case 'conf': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3236 |
$type = 'text/nginx'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3237 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3238 |
case 'css': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
$type = 'text/css'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3241 |
case 'diff': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
case 'patch': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
$type = 'text/x-diff'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3244 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
case 'html': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
case 'htm': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
$type = 'text/html'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3248 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
case 'http': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
$type = 'message/http'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
case 'js': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
$type = 'text/javascript'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
case 'json': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
$type = 'application/json'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
case 'jsx': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
$type = 'text/jsx'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3261 |
case 'less': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
$type = 'text/x-less'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3263 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3264 |
case 'md': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3265 |
$type = 'text/x-gfm'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3266 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
case 'php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
case 'phtml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3269 |
case 'php3': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3270 |
case 'php4': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3271 |
case 'php5': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
case 'php7': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
case 'phps': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3274 |
$type = 'application/x-httpd-php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
case 'scss': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
$type = 'text/x-scss'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
case 'sass': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
$type = 'text/x-sass'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3281 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3282 |
case 'sh': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3283 |
case 'bash': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
$type = 'text/x-sh'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3285 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
case 'sql': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
$type = 'text/x-sql'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
case 'svg': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
$type = 'application/svg+xml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3291 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
case 'xml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
$type = 'text/xml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
case 'yml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
case 'yaml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
$type = 'text/x-yaml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3299 |
case 'txt': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3300 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3301 |
$type = 'text/plain'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3302 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3303 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3307 |
if ( 'text/css' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3308 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3309 |
'mode' => 'css', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
'lint' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3311 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
} elseif ( 'text/x-scss' === $type || 'text/x-less' === $type || 'text/x-sass' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
'mode' => $type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
'lint' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3318 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3319 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3320 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3321 |
} elseif ( 'text/x-diff' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3323 |
'mode' => 'diff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
} elseif ( 'text/html' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3326 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
'mode' => 'htmlmixed', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
'lint' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
'autoCloseTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
'matchTags' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
'bothTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3334 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3335 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3336 |
if ( ! current_user_can( 'unfiltered_html' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3337 |
$settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
} elseif ( 'text/x-gfm' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3340 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3341 |
'mode' => 'gfm', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
'highlightFormatting' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3343 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3344 |
} elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3345 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
'mode' => 'javascript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3347 |
'lint' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3348 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3349 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3351 |
} elseif ( false !== strpos( $type, 'json' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3353 |
'mode' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
'name' => 'javascript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
'lint' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3358 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3359 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3360 |
if ( 'application/ld+json' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3361 |
$settings['codemirror']['mode']['jsonld'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3362 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3363 |
$settings['codemirror']['mode']['json'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3364 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3365 |
} elseif ( false !== strpos( $type, 'jsx' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3366 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
'mode' => 'jsx', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3368 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
} elseif ( 'text/x-markdown' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3372 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3373 |
'mode' => 'markdown', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
'highlightFormatting' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
} elseif ( 'text/nginx' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
'mode' => 'nginx', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
} elseif ( 'application/x-httpd-php' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
'mode' => 'php', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
'autoCloseTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
'matchTags' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
'bothTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
} elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
'mode' => 'sql', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
'matchBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
} elseif ( false !== strpos( $type, 'xml' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
'mode' => 'xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3399 |
'autoCloseBrackets' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
'autoCloseTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
'matchTags' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
'bothTags' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3404 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
} elseif ( 'text/x-yaml' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
$settings['codemirror'] = array_merge( $settings['codemirror'], array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
'mode' => 'yaml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
$settings['codemirror']['mode'] = $type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
if ( ! empty( $settings['codemirror']['lint'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
$settings['codemirror']['gutters'][] = 'CodeMirror-lint-markers'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
// Let settings supplied via args override any defaults. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3418 |
foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
$settings[ $key ] = array_merge( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
$settings[ $key ], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3421 |
$value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
* Filters settings that are passed into the code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
* Returning a falsey value will disable the syntax-highlighting code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3429 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3430 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3431 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
* @param array $settings The array of settings passed to the code editor. A falsey value disables the editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
* Args passed when calling `wp_enqueue_code_editor()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3436 |
* @type string $type The MIME type of the file to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3437 |
* @type string $file Filename being edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3438 |
* @type WP_Theme $theme Theme being edited when on theme editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3439 |
* @type string $plugin Plugin being edited when on plugin editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
* @type array $codemirror Additional CodeMirror setting overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3441 |
* @type array $csslint CSSLint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
* @type array $jshint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
* @type array $htmlhint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3444 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3445 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3446 |
$settings = apply_filters( 'wp_code_editor_settings', $settings, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3447 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3448 |
if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3449 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3450 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3451 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3452 |
wp_enqueue_script( 'code-editor' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3453 |
wp_enqueue_style( 'code-editor' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3454 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3455 |
if ( isset( $settings['codemirror']['mode'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3456 |
$mode = $settings['codemirror']['mode']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3457 |
if ( is_string( $mode ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3458 |
$mode = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3459 |
'name' => $mode, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3460 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3461 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3463 |
if ( ! empty( $settings['codemirror']['lint'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3464 |
switch ( $mode['name'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3465 |
case 'css': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
case 'text/css': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
case 'text/x-scss': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
case 'text/x-less': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3469 |
wp_enqueue_script( 'csslint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3470 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
case 'htmlmixed': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3472 |
case 'text/html': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3473 |
case 'php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3474 |
case 'application/x-httpd-php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3475 |
case 'text/x-php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3476 |
wp_enqueue_script( 'htmlhint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3477 |
wp_enqueue_script( 'csslint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3478 |
wp_enqueue_script( 'jshint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3479 |
if ( ! current_user_can( 'unfiltered_html' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3480 |
wp_enqueue_script( 'htmlhint-kses' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3481 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3482 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3483 |
case 'javascript': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3484 |
case 'application/ecmascript': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3485 |
case 'application/json': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3486 |
case 'application/javascript': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3487 |
case 'application/ld+json': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3488 |
case 'text/typescript': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
case 'application/typescript': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3490 |
wp_enqueue_script( 'jshint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3491 |
wp_enqueue_script( 'jsonlint' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3492 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3493 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3497 |
wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3499 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3500 |
* Fires when scripts and styles are enqueued for the code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3501 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3502 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3503 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3504 |
* @param array $settings Settings for the enqueued code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3505 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3506 |
do_action( 'wp_enqueue_code_editor', $settings ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3507 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3508 |
return $settings; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3511 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3512 |
* Retrieves the contents of the search WordPress query variable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
* The search query string is passed through esc_attr() to ensure that it is safe |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
* for placing in an html attribute. |
0 | 3516 |
* |
3517 |
* @since 2.3.0 |
|
3518 |
* |
|
3519 |
* @param bool $escaped Whether the result is escaped. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
* Only use when you are later escaping it. Do not use unescaped. |
0 | 3521 |
* @return string |
3522 |
*/ |
|
3523 |
function get_search_query( $escaped = true ) { |
|
5 | 3524 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3525 |
* Filters the contents of the search query variable. |
5 | 3526 |
* |
3527 |
* @since 2.3.0 |
|
3528 |
* |
|
3529 |
* @param mixed $search Contents of the search query variable. |
|
3530 |
*/ |
|
0 | 3531 |
$query = apply_filters( 'get_search_query', get_query_var( 's' ) ); |
5 | 3532 |
|
0 | 3533 |
if ( $escaped ) |
3534 |
$query = esc_attr( $query ); |
|
3535 |
return $query; |
|
3536 |
} |
|
3537 |
||
3538 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
* Displays the contents of the search query variable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
* The search query string is passed through esc_attr() to ensure that it is safe |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
* for placing in an html attribute. |
0 | 3543 |
* |
3544 |
* @since 2.1.0 |
|
3545 |
*/ |
|
3546 |
function the_search_query() { |
|
5 | 3547 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
* Filters the contents of the search query variable for display. |
5 | 3549 |
* |
3550 |
* @since 2.3.0 |
|
3551 |
* |
|
3552 |
* @param mixed $search Contents of the search query variable. |
|
3553 |
*/ |
|
0 | 3554 |
echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) ); |
3555 |
} |
|
3556 |
||
3557 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
* Gets the language attributes for the html tag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3559 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3560 |
* Builds up a set of html attributes containing the text direction and language |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
* information for the page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3565 |
* @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3567 |
function get_language_attributes( $doctype = 'html' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
$attributes = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
$attributes[] = 'dir="rtl"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
if ( $lang = get_bloginfo( 'language' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
if ( get_option( 'html_type' ) == 'text/html' || $doctype == 'html' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
$attributes[] = 'lang="' . esc_attr( $lang ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
if ( get_option( 'html_type' ) != 'text/html' || $doctype == 'xhtml' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
$attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
$output = implode(' ', $attributes); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
* Filters the language attributes for display in the html tag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
* @since 4.3.0 Added the `$doctype` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
* @param string $output A space-separated list of language attributes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
* @param string $doctype The type of html document (xhtml|html). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
return apply_filters( 'language_attributes', $output, $doctype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
* Displays the language attributes for the html tag. |
0 | 3599 |
* |
3600 |
* Builds up a set of html attributes containing the text direction and language |
|
3601 |
* information for the page. |
|
3602 |
* |
|
3603 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
* @since 4.3.0 Converted into a wrapper for get_language_attributes(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
* @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'. |
0 | 3607 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
function language_attributes( $doctype = 'html' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
echo get_language_attributes( $doctype ); |
0 | 3610 |
} |
3611 |
||
3612 |
/** |
|
3613 |
* Retrieve paginated link for archive post pages. |
|
3614 |
* |
|
3615 |
* Technically, the function can be used to create paginated link list for any |
|
3616 |
* area. The 'base' argument is used to reference the url, which will be used to |
|
3617 |
* create the paginated links. The 'format' argument is then used for replacing |
|
3618 |
* the page number. It is however, most likely and by default, to be used on the |
|
3619 |
* archive post pages. |
|
3620 |
* |
|
3621 |
* The 'type' argument controls format of the returned value. The default is |
|
3622 |
* 'plain', which is just a string with the links separated by a newline |
|
3623 |
* character. The other possible values are either 'array' or 'list'. The |
|
3624 |
* 'array' value will return an array of the paginated link list to offer full |
|
3625 |
* control of display. The 'list' value will place all of the paginated links in |
|
3626 |
* an unordered HTML list. |
|
3627 |
* |
|
3628 |
* The 'total' argument is the total amount of pages and is an integer. The |
|
3629 |
* 'current' argument is the current page number and is also an integer. |
|
3630 |
* |
|
3631 |
* An example of the 'base' argument is "http://example.com/all_posts.php%_%" |
|
3632 |
* and the '%_%' is required. The '%_%' will be replaced by the contents of in |
|
3633 |
* the 'format' argument. An example for the 'format' argument is "?page=%#%" |
|
3634 |
* and the '%#%' is also required. The '%#%' will be replaced with the page |
|
3635 |
* number. |
|
3636 |
* |
|
3637 |
* You can include the previous and next links in the list by setting the |
|
3638 |
* 'prev_next' argument to true, which it is by default. You can set the |
|
3639 |
* previous text, by using the 'prev_text' argument. You can set the next text |
|
3640 |
* by setting the 'next_text' argument. |
|
3641 |
* |
|
3642 |
* If the 'show_all' argument is set to true, then it will show all of the pages |
|
3643 |
* instead of a short list of the pages near the current page. By default, the |
|
3644 |
* 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' |
|
3645 |
* arguments. The 'end_size' argument is how many numbers on either the start |
|
3646 |
* and the end list edges, by default is 1. The 'mid_size' argument is how many |
|
3647 |
* numbers to either side of current page, but not including current page. |
|
3648 |
* |
|
3649 |
* It is possible to add query vars to the link by using the 'add_args' argument |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
* and see add_query_arg() for more information. |
0 | 3651 |
* |
5 | 3652 |
* The 'before_page_number' and 'after_page_number' arguments allow users to |
3653 |
* augment the links themselves. Typically this might be to add context to the |
|
3654 |
* numbered links so that screen reader users understand what the links are for. |
|
3655 |
* The text strings are added before and after the page number - within the |
|
3656 |
* anchor tag. |
|
3657 |
* |
|
0 | 3658 |
* @since 2.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
* @since 4.9.0 Added the `aria_current` argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
* @global WP_Query $wp_query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
* @global WP_Rewrite $wp_rewrite |
0 | 3663 |
* |
5 | 3664 |
* @param string|array $args { |
3665 |
* Optional. Array or string of arguments for generating paginated links for archives. |
|
3666 |
* |
|
3667 |
* @type string $base Base of the paginated url. Default empty. |
|
3668 |
* @type string $format Format for the pagination structure. Default empty. |
|
3669 |
* @type int $total The total amount of pages. Default is the value WP_Query's |
|
3670 |
* `max_num_pages` or 1. |
|
3671 |
* @type int $current The current page number. Default is 'paged' query var or 1. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
* @type string $aria_current The value for the aria-current attribute. Possible values are 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'. |
5 | 3674 |
* @type bool $show_all Whether to show all pages. Default false. |
3675 |
* @type int $end_size How many numbers on either the start and the end list edges. |
|
3676 |
* Default 1. |
|
3677 |
* @type int $mid_size How many numbers to either side of the current pages. Default 2. |
|
3678 |
* @type bool $prev_next Whether to include the previous and next links in the list. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
* @type bool $prev_text The previous page text. Default '« Previous'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
* @type bool $next_text The next page text. Default 'Next »'. |
5 | 3681 |
* @type string $type Controls format of the returned value. Possible values are 'plain', |
3682 |
* 'array' and 'list'. Default is 'plain'. |
|
3683 |
* @type array $add_args An array of query args to add. Default false. |
|
3684 |
* @type string $add_fragment A string to append to each link. Default empty. |
|
3685 |
* @type string $before_page_number A string to appear before the page number. Default empty. |
|
3686 |
* @type string $after_page_number A string to append after the page number. Default empty. |
|
3687 |
* } |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
* @return array|string|void String of page links or array of page links. |
0 | 3689 |
*/ |
3690 |
function paginate_links( $args = '' ) { |
|
5 | 3691 |
global $wp_query, $wp_rewrite; |
3692 |
||
3693 |
// Setting up default values based on the current URL. |
|
3694 |
$pagenum_link = html_entity_decode( get_pagenum_link() ); |
|
3695 |
$url_parts = explode( '?', $pagenum_link ); |
|
3696 |
||
3697 |
// Get max pages and current page out of the current query, if available. |
|
3698 |
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
3699 |
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; |
|
3700 |
||
3701 |
// Append the format placeholder to the base URL. |
|
3702 |
$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%'; |
|
3703 |
||
3704 |
// URL base depends on permalink settings. |
|
3705 |
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; |
|
3706 |
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; |
|
3707 |
||
0 | 3708 |
$defaults = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
'format' => $format, // ?page=%#% : %#% is replaced by the page number |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
'total' => $total, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
'current' => $current, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
'aria_current' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
'show_all' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3715 |
'prev_next' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
'prev_text' => __( '« Previous' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
'next_text' => __( 'Next »' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
'end_size' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
'mid_size' => 2, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
'type' => 'plain', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
'add_args' => array(), // array of query args to add |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
'add_fragment' => '', |
5 | 3723 |
'before_page_number' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3724 |
'after_page_number' => '', |
0 | 3725 |
); |
3726 |
||
3727 |
$args = wp_parse_args( $args, $defaults ); |
|
5 | 3728 |
|
3729 |
if ( ! is_array( $args['add_args'] ) ) { |
|
3730 |
$args['add_args'] = array(); |
|
3731 |
} |
|
3732 |
||
3733 |
// Merge additional query vars found in the original URL into 'add_args' array. |
|
3734 |
if ( isset( $url_parts[1] ) ) { |
|
3735 |
// Find the format argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3736 |
$format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3737 |
$format_query = isset( $format[1] ) ? $format[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
wp_parse_str( $format_query, $format_args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
// Find the query args of the requested URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
wp_parse_str( $url_parts[1], $url_query_args ); |
5 | 3742 |
|
3743 |
// Remove the format argument from the array of query arguments, to avoid overwriting custom format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
foreach ( $format_args as $format_arg => $format_arg_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
unset( $url_query_args[ $format_arg ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); |
5 | 3749 |
} |
0 | 3750 |
|
3751 |
// Who knows what else people pass in $args |
|
5 | 3752 |
$total = (int) $args['total']; |
3753 |
if ( $total < 2 ) { |
|
0 | 3754 |
return; |
5 | 3755 |
} |
3756 |
$current = (int) $args['current']; |
|
3757 |
$end_size = (int) $args['end_size']; // Out of bounds? Make it the default. |
|
3758 |
if ( $end_size < 1 ) { |
|
3759 |
$end_size = 1; |
|
3760 |
} |
|
3761 |
$mid_size = (int) $args['mid_size']; |
|
3762 |
if ( $mid_size < 0 ) { |
|
3763 |
$mid_size = 2; |
|
3764 |
} |
|
3765 |
$add_args = $args['add_args']; |
|
0 | 3766 |
$r = ''; |
3767 |
$page_links = array(); |
|
3768 |
$dots = false; |
|
3769 |
||
5 | 3770 |
if ( $args['prev_next'] && $current && 1 < $current ) : |
3771 |
$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); |
|
3772 |
$link = str_replace( '%#%', $current - 1, $link ); |
|
0 | 3773 |
if ( $add_args ) |
3774 |
$link = add_query_arg( $add_args, $link ); |
|
5 | 3775 |
$link .= $args['add_fragment']; |
3776 |
||
3777 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3778 |
* Filters the paginated links for the given archive pages. |
5 | 3779 |
* |
3780 |
* @since 3.0.0 |
|
3781 |
* |
|
3782 |
* @param string $link The paginated link URL. |
|
3783 |
*/ |
|
3784 |
$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>'; |
|
0 | 3785 |
endif; |
3786 |
for ( $n = 1; $n <= $total; $n++ ) : |
|
3787 |
if ( $n == $current ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3788 |
$page_links[] = "<span aria-current='" . esc_attr( $args['aria_current'] ) . "' class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>"; |
0 | 3789 |
$dots = true; |
3790 |
else : |
|
5 | 3791 |
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
3792 |
$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
|
3793 |
$link = str_replace( '%#%', $n, $link ); |
|
0 | 3794 |
if ( $add_args ) |
3795 |
$link = add_query_arg( $add_args, $link ); |
|
5 | 3796 |
$link .= $args['add_fragment']; |
3797 |
||
3798 |
/** This filter is documented in wp-includes/general-template.php */ |
|
3799 |
$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>"; |
|
0 | 3800 |
$dots = true; |
5 | 3801 |
elseif ( $dots && ! $args['show_all'] ) : |
0 | 3802 |
$page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>'; |
3803 |
$dots = false; |
|
3804 |
endif; |
|
3805 |
endif; |
|
3806 |
endfor; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
if ( $args['prev_next'] && $current && $current < $total ) : |
5 | 3808 |
$link = str_replace( '%_%', $args['format'], $args['base'] ); |
3809 |
$link = str_replace( '%#%', $current + 1, $link ); |
|
0 | 3810 |
if ( $add_args ) |
3811 |
$link = add_query_arg( $add_args, $link ); |
|
5 | 3812 |
$link .= $args['add_fragment']; |
3813 |
||
3814 |
/** This filter is documented in wp-includes/general-template.php */ |
|
3815 |
$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>'; |
|
0 | 3816 |
endif; |
5 | 3817 |
switch ( $args['type'] ) { |
0 | 3818 |
case 'array' : |
3819 |
return $page_links; |
|
5 | 3820 |
|
0 | 3821 |
case 'list' : |
3822 |
$r .= "<ul class='page-numbers'>\n\t<li>"; |
|
3823 |
$r .= join("</li>\n\t<li>", $page_links); |
|
3824 |
$r .= "</li>\n</ul>\n"; |
|
3825 |
break; |
|
5 | 3826 |
|
0 | 3827 |
default : |
3828 |
$r = join("\n", $page_links); |
|
3829 |
break; |
|
5 | 3830 |
} |
0 | 3831 |
return $r; |
3832 |
} |
|
3833 |
||
3834 |
/** |
|
3835 |
* Registers an admin colour scheme css file. |
|
3836 |
* |
|
3837 |
* Allows a plugin to register a new admin colour scheme. For example: |
|
5 | 3838 |
* |
3839 |
* wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array( |
|
3840 |
* '#07273E', '#14568A', '#D54E21', '#2683AE' |
|
3841 |
* ) ); |
|
0 | 3842 |
* |
3843 |
* @since 2.5.0 |
|
3844 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3845 |
* @global array $_wp_admin_css_colors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3846 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3847 |
* @param string $key The unique key for this theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3848 |
* @param string $name The name of the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3849 |
* @param string $url The URL of the CSS file containing the color scheme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3850 |
* @param array $colors Optional. An array of CSS color definition strings which are used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3851 |
* to give the user a feel for the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3852 |
* @param array $icons { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3853 |
* Optional. CSS color definitions used to color any SVG icons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3855 |
* @type string $base SVG icon base color. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3856 |
* @type string $focus SVG icon color on focus. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3857 |
* @type string $current SVG icon color of current admin menu link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3858 |
* } |
0 | 3859 |
*/ |
5 | 3860 |
function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { |
0 | 3861 |
global $_wp_admin_css_colors; |
3862 |
||
3863 |
if ( !isset($_wp_admin_css_colors) ) |
|
3864 |
$_wp_admin_css_colors = array(); |
|
3865 |
||
5 | 3866 |
$_wp_admin_css_colors[$key] = (object) array( |
3867 |
'name' => $name, |
|
3868 |
'url' => $url, |
|
3869 |
'colors' => $colors, |
|
3870 |
'icon_colors' => $icons, |
|
3871 |
); |
|
0 | 3872 |
} |
3873 |
||
3874 |
/** |
|
3875 |
* Registers the default Admin color schemes |
|
3876 |
* |
|
3877 |
* @since 3.0.0 |
|
3878 |
*/ |
|
3879 |
function register_admin_color_schemes() { |
|
5 | 3880 |
$suffix = is_rtl() ? '-rtl' : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
$suffix .= SCRIPT_DEBUG ? '' : '.min'; |
5 | 3882 |
|
3883 |
wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ), |
|
3884 |
false, |
|
3885 |
array( '#222', '#333', '#0073aa', '#00a0d2' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3886 |
array( 'base' => '#82878c', 'focus' => '#00a0d2', 'current' => '#fff' ) |
5 | 3887 |
); |
3888 |
||
3889 |
// Other color schemes are not available when running out of src |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
if ( false !== strpos( get_bloginfo( 'version' ), '-src' ) ) { |
5 | 3891 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3892 |
} |
5 | 3893 |
|
3894 |
wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ), |
|
3895 |
admin_url( "css/colors/light/colors$suffix.css" ), |
|
3896 |
array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ), |
|
3897 |
array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' ) |
|
3898 |
); |
|
3899 |
||
3900 |
wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ), |
|
3901 |
admin_url( "css/colors/blue/colors$suffix.css" ), |
|
3902 |
array( '#096484', '#4796b3', '#52accc', '#74B6CE' ), |
|
3903 |
array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' ) |
|
3904 |
); |
|
3905 |
||
3906 |
wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ), |
|
3907 |
admin_url( "css/colors/midnight/colors$suffix.css" ), |
|
3908 |
array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ), |
|
3909 |
array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' ) |
|
3910 |
); |
|
3911 |
||
3912 |
wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ), |
|
3913 |
admin_url( "css/colors/sunrise/colors$suffix.css" ), |
|
3914 |
array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ), |
|
3915 |
array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' ) |
|
3916 |
); |
|
3917 |
||
3918 |
wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ), |
|
3919 |
admin_url( "css/colors/ectoplasm/colors$suffix.css" ), |
|
3920 |
array( '#413256', '#523f6d', '#a3b745', '#d46f15' ), |
|
3921 |
array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' ) |
|
3922 |
); |
|
3923 |
||
3924 |
wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ), |
|
3925 |
admin_url( "css/colors/ocean/colors$suffix.css" ), |
|
3926 |
array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ), |
|
3927 |
array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' ) |
|
3928 |
); |
|
3929 |
||
3930 |
wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ), |
|
3931 |
admin_url( "css/colors/coffee/colors$suffix.css" ), |
|
3932 |
array( '#46403c', '#59524c', '#c7a589', '#9ea476' ), |
|
3933 |
array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' ) |
|
3934 |
); |
|
3935 |
||
0 | 3936 |
} |
3937 |
||
3938 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
* Displays the URL of a WordPress admin CSS file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
* @see WP_Styles::_css_href and its {@see 'style_loader_src'} filter. |
0 | 3942 |
* |
3943 |
* @since 2.3.0 |
|
3944 |
* |
|
3945 |
* @param string $file file relative to wp-admin/ without its ".css" extension. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
* @return string |
0 | 3947 |
*/ |
3948 |
function wp_admin_css_uri( $file = 'wp-admin' ) { |
|
3949 |
if ( defined('WP_INSTALLING') ) { |
|
3950 |
$_file = "./$file.css"; |
|
3951 |
} else { |
|
3952 |
$_file = admin_url("$file.css"); |
|
3953 |
} |
|
3954 |
$_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); |
|
3955 |
||
5 | 3956 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
* Filters the URI of a WordPress admin CSS file. |
5 | 3958 |
* |
3959 |
* @since 2.3.0 |
|
3960 |
* |
|
3961 |
* @param string $_file Relative path to the file with query arguments attached. |
|
3962 |
* @param string $file Relative path to the file, minus its ".css" extension. |
|
3963 |
*/ |
|
0 | 3964 |
return apply_filters( 'wp_admin_css_uri', $_file, $file ); |
3965 |
} |
|
3966 |
||
3967 |
/** |
|
3968 |
* Enqueues or directly prints a stylesheet link to the specified CSS file. |
|
3969 |
* |
|
3970 |
* "Intelligently" decides to enqueue or to print the CSS file. If the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
* {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
* enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will |
0 | 3973 |
* be printed. Printing may be forced by passing true as the $force_echo |
3974 |
* (second) parameter. |
|
3975 |
* |
|
3976 |
* For backward compatibility with WordPress 2.3 calling method: If the $file |
|
3977 |
* (first) parameter does not correspond to a registered CSS file, we assume |
|
3978 |
* $file is a file relative to wp-admin/ without its ".css" extension. A |
|
3979 |
* stylesheet link to that generated URL is printed. |
|
3980 |
* |
|
3981 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
* @param string $file Optional. Style handle name or file name (without ".css" extension) relative |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
* to wp-admin/. Defaults to 'wp-admin'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
* @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. |
0 | 3986 |
*/ |
3987 |
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { |
|
3988 |
// For backward compatibility |
|
3989 |
$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; |
|
3990 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
if ( wp_styles()->query( $handle ) ) { |
0 | 3992 |
if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately |
3993 |
wp_print_styles( $handle ); |
|
3994 |
else // Add to style queue |
|
3995 |
wp_enqueue_style( $handle ); |
|
3996 |
return; |
|
3997 |
} |
|
3998 |
||
5 | 3999 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
* Filters the stylesheet link to the specified CSS file. |
5 | 4001 |
* |
4002 |
* If the site is set to display right-to-left, the RTL stylesheet link |
|
4003 |
* will be used instead. |
|
4004 |
* |
|
4005 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4006 |
* @param string $stylesheet_link HTML link element for the stylesheet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4007 |
* @param string $file Style handle name or filename (without ".css" extension) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4008 |
* relative to wp-admin/. Defaults to 'wp-admin'. |
5 | 4009 |
*/ |
0 | 4010 |
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file ); |
5 | 4011 |
|
4012 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) { |
|
4013 |
/** This filter is documented in wp-includes/general-template.php */ |
|
0 | 4014 |
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" ); |
5 | 4015 |
} |
0 | 4016 |
} |
4017 |
||
4018 |
/** |
|
4019 |
* Enqueues the default ThickBox js and css. |
|
4020 |
* |
|
4021 |
* If any of the settings need to be changed, this can be done with another js |
|
4022 |
* file similar to media-upload.js. That file should |
|
4023 |
* require array('thickbox') to ensure it is loaded after. |
|
4024 |
* |
|
4025 |
* @since 2.5.0 |
|
4026 |
*/ |
|
4027 |
function add_thickbox() { |
|
4028 |
wp_enqueue_script( 'thickbox' ); |
|
4029 |
wp_enqueue_style( 'thickbox' ); |
|
4030 |
||
4031 |
if ( is_network_admin() ) |
|
4032 |
add_action( 'admin_head', '_thickbox_path_admin_subfolder' ); |
|
4033 |
} |
|
4034 |
||
4035 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4036 |
* Displays the XHTML generator that is generated on the wp_head hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4037 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4038 |
* See {@see 'wp_head'}. |
0 | 4039 |
* |
4040 |
* @since 2.5.0 |
|
4041 |
*/ |
|
4042 |
function wp_generator() { |
|
5 | 4043 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4044 |
* Filters the output of the XHTML generator tag. |
5 | 4045 |
* |
4046 |
* @since 2.5.0 |
|
4047 |
* |
|
4048 |
* @param string $generator_type The XHTML generator. |
|
4049 |
*/ |
|
0 | 4050 |
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) ); |
4051 |
} |
|
4052 |
||
4053 |
/** |
|
4054 |
* Display the generator XML or Comment for RSS, ATOM, etc. |
|
4055 |
* |
|
4056 |
* Returns the correct generator type for the requested output format. Allows |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
* for a plugin to filter generators overall the {@see 'the_generator'} filter. |
0 | 4058 |
* |
4059 |
* @since 2.5.0 |
|
4060 |
* |
|
4061 |
* @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export). |
|
4062 |
*/ |
|
4063 |
function the_generator( $type ) { |
|
5 | 4064 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4065 |
* Filters the output of the XHTML generator tag for display. |
5 | 4066 |
* |
4067 |
* @since 2.5.0 |
|
4068 |
* |
|
4069 |
* @param string $generator_type The generator output. |
|
4070 |
* @param string $type The type of generator to output. Accepts 'html', |
|
4071 |
* 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'. |
|
4072 |
*/ |
|
4073 |
echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n"; |
|
0 | 4074 |
} |
4075 |
||
4076 |
/** |
|
4077 |
* Creates the generator XML or Comment for RSS, ATOM, etc. |
|
4078 |
* |
|
4079 |
* Returns the correct generator type for the requested output format. Allows |
|
4080 |
* for a plugin to filter generators on an individual basis using the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4081 |
* {@see 'get_the_generator_$type'} filter. |
0 | 4082 |
* |
4083 |
* @since 2.5.0 |
|
4084 |
* |
|
4085 |
* @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4086 |
* @return string|void The HTML content for the generator. |
0 | 4087 |
*/ |
4088 |
function get_the_generator( $type = '' ) { |
|
4089 |
if ( empty( $type ) ) { |
|
4090 |
||
4091 |
$current_filter = current_filter(); |
|
4092 |
if ( empty( $current_filter ) ) |
|
4093 |
return; |
|
4094 |
||
4095 |
switch ( $current_filter ) { |
|
4096 |
case 'rss2_head' : |
|
4097 |
case 'commentsrss2_head' : |
|
4098 |
$type = 'rss2'; |
|
4099 |
break; |
|
4100 |
case 'rss_head' : |
|
4101 |
case 'opml_head' : |
|
4102 |
$type = 'comment'; |
|
4103 |
break; |
|
4104 |
case 'rdf_header' : |
|
4105 |
$type = 'rdf'; |
|
4106 |
break; |
|
4107 |
case 'atom_head' : |
|
4108 |
case 'comments_atom_head' : |
|
4109 |
case 'app_head' : |
|
4110 |
$type = 'atom'; |
|
4111 |
break; |
|
4112 |
} |
|
4113 |
} |
|
4114 |
||
4115 |
switch ( $type ) { |
|
4116 |
case 'html': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4117 |
$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">'; |
0 | 4118 |
break; |
4119 |
case 'xhtml': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4120 |
$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />'; |
0 | 4121 |
break; |
4122 |
case 'atom': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4123 |
$gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>'; |
0 | 4124 |
break; |
4125 |
case 'rss2': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4126 |
$gen = '<generator>' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>'; |
0 | 4127 |
break; |
4128 |
case 'rdf': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4129 |
$gen = '<admin:generatorAgent rdf:resource="' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />'; |
0 | 4130 |
break; |
4131 |
case 'comment': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4132 |
$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->'; |
0 | 4133 |
break; |
4134 |
case 'export': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4135 |
$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . date( 'Y-m-d H:i' ) . '" -->'; |
0 | 4136 |
break; |
4137 |
} |
|
5 | 4138 |
|
4139 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
* Filters the HTML for the retrieved generator type. |
5 | 4141 |
* |
4142 |
* The dynamic portion of the hook name, `$type`, refers to the generator type. |
|
4143 |
* |
|
4144 |
* @since 2.5.0 |
|
4145 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
* @param string $gen The HTML markup output to wp_head(). |
5 | 4147 |
* @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom', |
4148 |
* 'rss2', 'rdf', 'comment', 'export'. |
|
4149 |
*/ |
|
0 | 4150 |
return apply_filters( "get_the_generator_{$type}", $gen, $type ); |
4151 |
} |
|
4152 |
||
4153 |
/** |
|
4154 |
* Outputs the html checked attribute. |
|
4155 |
* |
|
4156 |
* Compares the first two arguments and if identical marks as checked |
|
4157 |
* |
|
4158 |
* @since 1.0.0 |
|
4159 |
* |
|
4160 |
* @param mixed $checked One of the values to compare |
|
4161 |
* @param mixed $current (true) The other value to compare if not just true |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4162 |
* @param bool $echo Whether to echo or just return the string |
0 | 4163 |
* @return string html attribute or empty string |
4164 |
*/ |
|
4165 |
function checked( $checked, $current = true, $echo = true ) { |
|
4166 |
return __checked_selected_helper( $checked, $current, $echo, 'checked' ); |
|
4167 |
} |
|
4168 |
||
4169 |
/** |
|
4170 |
* Outputs the html selected attribute. |
|
4171 |
* |
|
4172 |
* Compares the first two arguments and if identical marks as selected |
|
4173 |
* |
|
4174 |
* @since 1.0.0 |
|
4175 |
* |
|
4176 |
* @param mixed $selected One of the values to compare |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4177 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4178 |
* @param bool $echo Whether to echo or just return the string |
0 | 4179 |
* @return string html attribute or empty string |
4180 |
*/ |
|
4181 |
function selected( $selected, $current = true, $echo = true ) { |
|
4182 |
return __checked_selected_helper( $selected, $current, $echo, 'selected' ); |
|
4183 |
} |
|
4184 |
||
4185 |
/** |
|
4186 |
* Outputs the html disabled attribute. |
|
4187 |
* |
|
4188 |
* Compares the first two arguments and if identical marks as disabled |
|
4189 |
* |
|
4190 |
* @since 3.0.0 |
|
4191 |
* |
|
4192 |
* @param mixed $disabled One of the values to compare |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4193 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4194 |
* @param bool $echo Whether to echo or just return the string |
0 | 4195 |
* @return string html attribute or empty string |
4196 |
*/ |
|
4197 |
function disabled( $disabled, $current = true, $echo = true ) { |
|
4198 |
return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); |
|
4199 |
} |
|
4200 |
||
4201 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4202 |
* Outputs the html readonly attribute. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4203 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4204 |
* Compares the first two arguments and if identical marks as readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4205 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4206 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4207 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4208 |
* @param mixed $readonly One of the values to compare |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4209 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* @param bool $echo Whether to echo or just return the string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4211 |
* @return string html attribute or empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4212 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4213 |
function readonly( $readonly, $current = true, $echo = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
return __checked_selected_helper( $readonly, $current, $echo, 'readonly' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4217 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
* Private helper function for checked, selected, disabled and readonly. |
0 | 4219 |
* |
4220 |
* Compares the first two arguments and if identical marks as $type |
|
4221 |
* |
|
4222 |
* @since 2.8.0 |
|
4223 |
* @access private |
|
4224 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4225 |
* @param mixed $helper One of the values to compare |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4226 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4227 |
* @param bool $echo Whether to echo or just return the string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4228 |
* @param string $type The type of checked|selected|disabled|readonly we are doing |
0 | 4229 |
* @return string html attribute or empty string |
4230 |
*/ |
|
4231 |
function __checked_selected_helper( $helper, $current, $echo, $type ) { |
|
4232 |
if ( (string) $helper === (string) $current ) |
|
4233 |
$result = " $type='$type'"; |
|
4234 |
else |
|
4235 |
$result = ''; |
|
4236 |
||
4237 |
if ( $echo ) |
|
4238 |
echo $result; |
|
4239 |
||
4240 |
return $result; |
|
4241 |
} |
|
4242 |
||
4243 |
/** |
|
4244 |
* Default settings for heartbeat |
|
4245 |
* |
|
4246 |
* Outputs the nonce used in the heartbeat XHR |
|
4247 |
* |
|
4248 |
* @since 3.6.0 |
|
4249 |
* |
|
4250 |
* @param array $settings |
|
4251 |
* @return array $settings |
|
4252 |
*/ |
|
4253 |
function wp_heartbeat_settings( $settings ) { |
|
4254 |
if ( ! is_admin() ) |
|
4255 |
$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' ); |
|
4256 |
||
4257 |
if ( is_user_logged_in() ) |
|
4258 |
$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' ); |
|
4259 |
||
4260 |
return $settings; |
|
4261 |
} |