Make WordPress Core

Ticket #40508: general-template.php

File general-template.php, 122.2 KB (added by rajanit2000, 9 years ago)

updated general-template.php

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