3 * General template tags that can go anywhere in a template.
10 * Load header template.
12 * Includes the header template for a theme or if a name is specified then a
13 * specialised header will be included.
15 * For the parameter, if the file is called "header-special.php" then specify
18 * @uses locate_template()
20 * @uses do_action() Calls 'get_header' action.
22 * @param string $name The name of the specialised header.
24 function get_header( $name = null ) {
25 do_action( 'get_header', $name );
28 $name = (string) $name;
30 $templates[] = "header-{$name}.php";
32 $templates[] = 'header.php';
34 // Backward compat code will be removed in a future release
35 if ('' == locate_template($templates, true))
36 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
40 * Load footer template.
42 * Includes the footer template for a theme or if a name is specified then a
43 * specialised footer will be included.
45 * For the parameter, if the file is called "footer-special.php" then specify
48 * @uses locate_template()
50 * @uses do_action() Calls 'get_footer' action.
52 * @param string $name The name of the specialised footer.
54 function get_footer( $name = null ) {
55 do_action( 'get_footer', $name );
58 $name = (string) $name;
60 $templates[] = "footer-{$name}.php";
62 $templates[] = 'footer.php';
64 // Backward compat code will be removed in a future release
65 if ('' == locate_template($templates, true))
66 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
70 * Load sidebar template.
72 * Includes the sidebar template for a theme or if a name is specified then a
73 * specialised sidebar will be included.
75 * For the parameter, if the file is called "sidebar-special.php" then specify
78 * @uses locate_template()
80 * @uses do_action() Calls 'get_sidebar' action.
82 * @param string $name The name of the specialised sidebar.
84 function get_sidebar( $name = null ) {
85 do_action( 'get_sidebar', $name );
88 $name = (string) $name;
90 $templates[] = "sidebar-{$name}.php";
92 $templates[] = 'sidebar.php';
94 // Backward compat code will be removed in a future release
95 if ('' == locate_template($templates, true))
96 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
100 * Load a template part into a template
102 * Makes it easy for a theme to reuse sections of code in a easy to overload way
105 * Includes the named template part for a theme or if a name is specified then a
106 * specialised part will be included. If the theme contains no {slug}.php file
107 * then no template will be included.
109 * The template is included using require, not require_once, so you may include the
110 * same template part multiple times.
112 * For the $name parameter, if the file is called "{slug}-special.php" then specify
115 * @uses locate_template()
117 * @uses do_action() Calls 'get_template_part_{$slug}' action.
119 * @param string $slug The slug name for the generic template.
120 * @param string $name The name of the specialised template.
122 function get_template_part( $slug, $name = null ) {
123 do_action( "get_template_part_{$slug}", $slug, $name );
125 $templates = array();
126 $name = (string) $name;
128 $templates[] = "{$slug}-{$name}.php";
130 $templates[] = "{$slug}.php";
132 locate_template($templates, true, false);
136 * Display search form.
138 * Will first attempt to locate the searchform.php file in either the child or
139 * the parent, then load it. If it doesn't exist, then the default search form
140 * will be displayed. The default search form is HTML, which will be displayed.
141 * There is a filter applied to the search form HTML in order to edit or replace
142 * it. The filter is 'get_search_form'.
144 * This function is primarily used by themes which want to hardcode the search
145 * form into the sidebar and also by the search widget in WordPress.
147 * There is also an action that is called whenever the function is run called,
148 * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
149 * search relies on or various formatting that applies to the beginning of the
150 * search. To give a few examples of what it can be used for.
153 * @uses apply_filters() Calls 'search_form_format' filter to determine which type to use for the search field.
154 * If set to 'html5', it changes to search input type and adds placeholder text.
156 * @param boolean $echo Default to echo and not return the form.
157 * @return string|null String when retrieving, null when displaying or if searchform.php exists.
159 function get_search_form( $echo = true ) {
160 do_action( 'pre_get_search_form' );
162 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
163 $format = apply_filters( 'search_form_format', $format );
165 $search_form_template = locate_template( 'searchform.php' );
166 if ( '' != $search_form_template ) {
168 require( $search_form_template );
169 $form = ob_get_clean();
171 if ( 'html5' == $format ) {
172 $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
174 <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
175 <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
177 <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
180 $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
182 <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
183 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
184 <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
190 $result = apply_filters( 'get_search_form', $form );
191 if ( null === $result )
201 * Display the Log In/Out link.
203 * Displays a link, which allows users to navigate to the Log In page to log in
204 * or log out depending on whether they are currently logged in.
207 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
209 * @param string $redirect Optional path to redirect to on login/logout.
210 * @param boolean $echo Default to echo and not return the link.
211 * @return string|null String when retrieving, null when displaying.
213 function wp_loginout($redirect = '', $echo = true) {
214 if ( ! is_user_logged_in() )
215 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
217 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
220 echo apply_filters('loginout', $link);
222 return apply_filters('loginout', $link);
226 * Returns the Log Out URL.
228 * Returns the URL that allows the user to log out of the site.
231 * @uses wp_nonce_url() To protect against CSRF.
232 * @uses site_url() To generate the log out URL.
233 * @uses apply_filters() calls 'logout_url' hook on final logout URL.
235 * @param string $redirect Path to redirect to on logout.
236 * @return string A log out URL.
238 function wp_logout_url($redirect = '') {
239 $args = array( 'action' => 'logout' );
240 if ( !empty($redirect) ) {
241 $args['redirect_to'] = urlencode( $redirect );
244 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
245 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
247 return apply_filters('logout_url', $logout_url, $redirect);
251 * Returns the Log In URL.
253 * Returns the URL that allows the user to log in to the site.
256 * @uses site_url() To generate the log in URL.
257 * @uses apply_filters() calls 'login_url' hook on final login URL.
259 * @param string $redirect Path to redirect to on login.
260 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
261 * @return string A log in URL.
263 function wp_login_url($redirect = '', $force_reauth = false) {
264 $login_url = site_url('wp-login.php', 'login');
266 if ( !empty($redirect) )
267 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
270 $login_url = add_query_arg('reauth', '1', $login_url);
272 return apply_filters('login_url', $login_url, $redirect);
276 * Returns the user registration URL.
278 * Returns the URL that allows the user to register on the site.
281 * @uses site_url() To generate the registration URL.
282 * @uses apply_filters() calls 'register_url' hook on final URL.
286 function wp_registration_url() {
287 return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
291 * Provides a simple login form for use anywhere within WordPress. By default, it echoes
292 * the HTML immediately. Pass array('echo'=>false) to return the string instead.
295 * @param array $args Configuration options to modify the form output.
296 * @return string|null String when retrieving, null when displaying.
298 function wp_login_form( $args = array() ) {
301 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
302 'form_id' => 'loginform',
303 'label_username' => __( 'Username' ),
304 'label_password' => __( 'Password' ),
305 'label_remember' => __( 'Remember Me' ),
306 'label_log_in' => __( 'Log In' ),
307 'id_username' => 'user_login',
308 'id_password' => 'user_pass',
309 'id_remember' => 'rememberme',
310 'id_submit' => 'wp-submit',
312 'value_username' => '',
313 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
315 $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
318 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
319 ' . apply_filters( 'login_form_top', '', $args ) . '
320 <p class="login-username">
321 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
322 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
324 <p class="login-password">
325 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
326 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
328 ' . apply_filters( 'login_form_middle', '', $args ) . '
329 ' . ( $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>' : '' ) . '
330 <p class="login-submit">
331 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
332 <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
334 ' . apply_filters( 'login_form_bottom', '', $args ) . '
344 * Returns the Lost Password URL.
346 * Returns the URL that allows the user to retrieve the lost password
349 * @uses site_url() To generate the lost password URL
350 * @uses apply_filters() calls 'lostpassword_url' hook on the lostpassword url
352 * @param string $redirect Path to redirect to on login.
353 * @return string Lost password URL.
355 function wp_lostpassword_url( $redirect = '' ) {
356 $args = array( 'action' => 'lostpassword' );
357 if ( !empty($redirect) ) {
358 $args['redirect_to'] = $redirect;
361 $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
362 return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
366 * Display the Registration or Admin link.
368 * Display a link which allows the user to navigate to the registration page if
369 * not logged in and registration is enabled or to the dashboard if logged in.
372 * @uses apply_filters() Calls 'register' hook on register / admin link content.
374 * @param string $before Text to output before the link (defaults to <li>).
375 * @param string $after Text to output after the link (defaults to </li>).
376 * @param boolean $echo Default to echo and not return the link.
377 * @return string|null String when retrieving, null when displaying.
379 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
381 if ( ! is_user_logged_in() ) {
382 if ( get_option('users_can_register') )
383 $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
387 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
391 echo apply_filters('register', $link);
393 return apply_filters('register', $link);
397 * Theme container function for the 'wp_meta' action.
399 * The 'wp_meta' action can have several purposes, depending on how you use it,
400 * but one purpose might have been to allow for theme switching.
403 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
404 * @uses do_action() Calls 'wp_meta' hook.
407 do_action('wp_meta');
411 * Display information about the blog.
413 * @see get_bloginfo() For possible values for the parameter.
416 * @param string $show What to display.
418 function bloginfo( $show='' ) {
419 echo get_bloginfo( $show, 'display' );
423 * Retrieve information about the blog.
425 * Some show parameter values are deprecated and will be removed in future
426 * versions. These options will trigger the _deprecated_argument() function.
427 * The deprecated blog info options are listed in the function contents.
429 * The possible values for the 'show' parameter are listed below.
431 * <li><strong>url</strong> - Blog URI to homepage.</li>
432 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
433 * <li><strong>description</strong> - Secondary title</li>
436 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
437 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
438 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
439 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
443 * @param string $show Blog info to retrieve.
444 * @param string $filter How to filter what is retrieved.
445 * @return string Mostly string values, might be empty.
447 function get_bloginfo( $show = '', $filter = 'raw' ) {
450 case 'home' : // DEPRECATED
451 case 'siteurl' : // DEPRECATED
452 _deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url' ) );
454 $output = home_url();
457 $output = site_url();
460 $output = get_option('blogdescription');
463 $output = get_feed_link('rdf');
466 $output = get_feed_link('rss');
469 $output = get_feed_link('rss2');
472 $output = get_feed_link('atom');
474 case 'comments_atom_url':
475 $output = get_feed_link('comments_atom');
477 case 'comments_rss2_url':
478 $output = get_feed_link('comments_rss2');
481 $output = site_url( 'xmlrpc.php' );
483 case 'stylesheet_url':
484 $output = get_stylesheet_uri();
486 case 'stylesheet_directory':
487 $output = get_stylesheet_directory_uri();
489 case 'template_directory':
491 $output = get_template_directory_uri();
494 $output = get_option('admin_email');
497 $output = get_option('blog_charset');
498 if ('' == $output) $output = 'UTF-8';
501 $output = get_option('html_type');
505 $output = $wp_version;
508 $output = get_locale();
509 $output = str_replace('_', '-', $output);
511 case 'text_direction':
512 //_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()' ) );
513 if ( function_exists( 'is_rtl' ) ) {
514 $output = is_rtl() ? 'rtl' : 'ltr';
521 $output = get_option('blogname');
526 if (strpos($show, 'url') === false &&
527 strpos($show, 'directory') === false &&
528 strpos($show, 'home') === false)
531 if ( 'display' == $filter ) {
533 $output = apply_filters('bloginfo_url', $output, $show);
535 $output = apply_filters('bloginfo', $output, $show);
542 * Display or retrieve page title for all areas of blog.
544 * By default, the page title will display the separator before the page title,
545 * so that the blog title will be before the page title. This is not good for
546 * title display, since the blog title shows up on most tabs and not what is
547 * important, which is the page that the user is looking at.
549 * There are also SEO benefits to having the blog title after or to the 'right'
550 * or the page title. However, it is mostly common sense to have the blog title
551 * to the right with most browsers supporting tabs. You can achieve this by
552 * using the seplocation parameter and setting the value to 'right'. This change
553 * was introduced around 2.5.0, in case backwards compatibility of themes is
558 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
559 * @param bool $display Optional, default is true. Whether to display or retrieve title.
560 * @param string $seplocation Optional. Direction to display title, 'right'.
561 * @return string|null String on retrieve, null when displaying.
563 function wp_title($sep = '»', $display = true, $seplocation = '') {
564 global $wpdb, $wp_locale;
566 $m = get_query_var('m');
567 $year = get_query_var('year');
568 $monthnum = get_query_var('monthnum');
569 $day = get_query_var('day');
570 $search = get_query_var('s');
573 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
575 // If there is a post
576 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
577 $title = single_post_title( '', false );
580 // If there's a post type archive
581 if ( is_post_type_archive() ) {
582 $post_type = get_query_var( 'post_type' );
583 if ( is_array( $post_type ) )
584 $post_type = reset( $post_type );
585 $post_type_object = get_post_type_object( $post_type );
586 if ( ! $post_type_object->has_archive )
587 $title = post_type_archive_title( '', false );
590 // If there's a category or tag
591 if ( is_category() || is_tag() ) {
592 $title = single_term_title( '', false );
595 // If there's a taxonomy
597 $term = get_queried_object();
599 $tax = get_taxonomy( $term->taxonomy );
600 $title = single_term_title( $tax->labels->name . $t_sep, false );
604 // If there's an author
606 $author = get_queried_object();
608 $title = $author->display_name;
611 // Post type archives with has_archive should override terms.
612 if ( is_post_type_archive() && $post_type_object->has_archive )
613 $title = post_type_archive_title( '', false );
615 // If there's a month
616 if ( is_archive() && !empty($m) ) {
617 $my_year = substr($m, 0, 4);
618 $my_month = $wp_locale->get_month(substr($m, 4, 2));
619 $my_day = intval(substr($m, 6, 2));
620 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
624 if ( is_archive() && !empty($year) ) {
626 if ( !empty($monthnum) )
627 $title .= $t_sep . $wp_locale->get_month($monthnum);
629 $title .= $t_sep . zeroise($day, 2);
634 /* translators: 1: separator, 2: search phrase */
635 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
638 // If it's a 404 page
640 $title = __('Page not found');
644 if ( !empty($title) )
647 // Determines position of the separator and direction of the breadcrumb
648 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
649 $title_array = explode( $t_sep, $title );
650 $title_array = array_reverse( $title_array );
651 $title = implode( " $sep ", $title_array ) . $prefix;
653 $title_array = explode( $t_sep, $title );
654 $title = $prefix . implode( " $sep ", $title_array );
657 $title = apply_filters('wp_title', $title, $sep, $seplocation);
668 * Display or retrieve page title for post.
670 * This is optimized for single.php template file for displaying the post title.
672 * It does not support placing the separator after the title, but by leaving the
673 * prefix parameter empty, you can set the title separator manually. The prefix
674 * does not automatically place a space between the prefix, so if there should
675 * be a space, the parameter value will need to have it at the end.
679 * @param string $prefix Optional. What to display before the title.
680 * @param bool $display Optional, default is true. Whether to display or retrieve title.
681 * @return string|null Title when retrieving, null when displaying or failure.
683 function single_post_title($prefix = '', $display = true) {
684 $_post = get_queried_object();
686 if ( !isset($_post->post_title) )
689 $title = apply_filters('single_post_title', $_post->post_title, $_post);
691 echo $prefix . $title;
693 return $prefix . $title;
697 * Display or retrieve title for a post type archive.
699 * This is optimized for archive.php and archive-{$post_type}.php template files
700 * for displaying the title of the post type.
704 * @param string $prefix Optional. What to display before the title.
705 * @param bool $display Optional, default is true. Whether to display or retrieve title.
706 * @return string|null Title when retrieving, null when displaying or failure.
708 function post_type_archive_title( $prefix = '', $display = true ) {
709 if ( ! is_post_type_archive() )
712 $post_type = get_query_var( 'post_type' );
713 if ( is_array( $post_type ) )
714 $post_type = reset( $post_type );
716 $post_type_obj = get_post_type_object( $post_type );
717 $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
720 echo $prefix . $title;
722 return $prefix . $title;
726 * Display or retrieve page title for category archive.
728 * This is useful for category template file or files, because it is optimized
729 * for category page title and with less overhead than {@link wp_title()}.
731 * It does not support placing the separator after the title, but by leaving the
732 * prefix parameter empty, you can set the title separator manually. The prefix
733 * does not automatically place a space between the prefix, so if there should
734 * be a space, the parameter value will need to have it at the end.
738 * @param string $prefix Optional. What to display before the title.
739 * @param bool $display Optional, default is true. Whether to display or retrieve title.
740 * @return string|null Title when retrieving, null when displaying or failure.
742 function single_cat_title( $prefix = '', $display = true ) {
743 return single_term_title( $prefix, $display );
747 * Display or retrieve page title for tag post archive.
749 * Useful for tag template files for displaying the tag page title. It has less
750 * overhead than {@link wp_title()}, because of its limited implementation.
752 * It does not support placing the separator after the title, but by leaving the
753 * prefix parameter empty, you can set the title separator manually. The prefix
754 * does not automatically place a space between the prefix, so if there should
755 * be a space, the parameter value will need to have it at the end.
759 * @param string $prefix Optional. What to display before the title.
760 * @param bool $display Optional, default is true. Whether to display or retrieve title.
761 * @return string|null Title when retrieving, null when displaying or failure.
763 function single_tag_title( $prefix = '', $display = true ) {
764 return single_term_title( $prefix, $display );
768 * Display or retrieve page title for taxonomy term archive.
770 * Useful for taxonomy term template files for displaying the taxonomy term page title.
771 * It has less overhead than {@link wp_title()}, because of its limited implementation.
773 * It does not support placing the separator after the title, but by leaving the
774 * prefix parameter empty, you can set the title separator manually. The prefix
775 * does not automatically place a space between the prefix, so if there should
776 * be a space, the parameter value will need to have it at the end.
780 * @param string $prefix Optional. What to display before the title.
781 * @param bool $display Optional, default is true. Whether to display or retrieve title.
782 * @return string|null Title when retrieving, null when displaying or failure.
784 function single_term_title( $prefix = '', $display = true ) {
785 $term = get_queried_object();
791 $term_name = apply_filters( 'single_cat_title', $term->name );
793 $term_name = apply_filters( 'single_tag_title', $term->name );
795 $term_name = apply_filters( 'single_term_title', $term->name );
799 if ( empty( $term_name ) )
803 echo $prefix . $term_name;
805 return $prefix . $term_name;
809 * Display or retrieve page title for post archive based on date.
811 * Useful for when the template only needs to display the month and year, if
812 * either are available. Optimized for just this purpose, so if it is all that
813 * is needed, should be better than {@link wp_title()}.
815 * It does not support placing the separator after the title, but by leaving the
816 * prefix parameter empty, you can set the title separator manually. The prefix
817 * does not automatically place a space between the prefix, so if there should
818 * be a space, the parameter value will need to have it at the end.
822 * @param string $prefix Optional. What to display before the title.
823 * @param bool $display Optional, default is true. Whether to display or retrieve title.
824 * @return string|null Title when retrieving, null when displaying or failure.
826 function single_month_title($prefix = '', $display = true ) {
829 $m = get_query_var('m');
830 $year = get_query_var('year');
831 $monthnum = get_query_var('monthnum');
833 if ( !empty($monthnum) && !empty($year) ) {
835 $my_month = $wp_locale->get_month($monthnum);
836 } elseif ( !empty($m) ) {
837 $my_year = substr($m, 0, 4);
838 $my_month = $wp_locale->get_month(substr($m, 4, 2));
841 if ( empty($my_month) )
844 $result = $prefix . $my_month . $prefix . $my_year;
852 * Retrieve archive link content based on predefined or custom code.
854 * The format can be one of four styles. The 'link' for head element, 'option'
855 * for use in the select element, 'html' for use in list (either ol or ul HTML
856 * elements). Custom content is also supported using the before and after
859 * The 'link' format uses the link HTML element with the <em>archives</em>
860 * relationship. The before and after parameters are not used. The text
861 * parameter is used to describe the link.
863 * The 'option' format uses the option HTML element for use in select element.
864 * The value is the url parameter and the before and after parameters are used
865 * between the text description.
867 * The 'html' format, which is the default, uses the li HTML element for use in
868 * the list HTML elements. The before parameter is before the link and the after
869 * parameter is after the closing link.
871 * The custom format uses the before parameter before the link ('a' HTML
872 * element) and the after parameter after the closing link tag. If the above
873 * three values for the format are not used, then custom format is assumed.
877 * @param string $url URL to archive.
878 * @param string $text Archive text description.
879 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
880 * @param string $before Optional.
881 * @param string $after Optional.
882 * @return string HTML link content for archive.
884 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
885 $text = wptexturize($text);
886 $url = esc_url($url);
888 if ('link' == $format)
889 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
890 elseif ('option' == $format)
891 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
892 elseif ('html' == $format)
893 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
895 $link_html = "\t$before<a href='$url'>$text</a>$after\n";
897 $link_html = apply_filters( 'get_archives_link', $link_html );
903 * Display archive links based on type and format.
905 * The 'type' argument offers a few choices and by default will display monthly
906 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
907 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
908 * same archive link list, the difference between the two is that 'alpha'
909 * will order by post title and 'postbypost' will order by post date.
911 * The date archives will logically display dates with links to the archive post
912 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
915 * The 'limit' argument will only display a limited amount of links, specified
916 * by the 'limit' integer value. By default, there is no limit. The
917 * 'show_post_count' argument will show how many posts are within the archive.
918 * By default, the 'show_post_count' argument is set to false.
920 * For the 'format', 'before', and 'after' arguments, see {@link
921 * get_archives_link()}. The values of these arguments have to do with that
926 * @param string|array $args Optional. Override defaults.
927 * @return string|null String when retrieving, null when displaying.
929 function wp_get_archives($args = '') {
930 global $wpdb, $wp_locale;
933 'type' => 'monthly', 'limit' => '',
934 'format' => 'html', 'before' => '',
935 'after' => '', 'show_post_count' => false,
936 'echo' => 1, 'order' => 'DESC',
939 $r = wp_parse_args( $args, $defaults );
940 extract( $r, EXTR_SKIP );
945 if ( '' != $limit ) {
946 $limit = absint($limit);
947 $limit = ' LIMIT '.$limit;
950 $order = strtoupper( $order );
951 if ( $order !== 'ASC' )
954 // this is what will separate dates on weekly archive links
955 $archive_week_separator = '–';
957 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
958 $archive_date_format_over_ride = 0;
960 // options for daily archive (only if you over-ride the general date format)
961 $archive_day_date_format = 'Y/m/d';
963 // options for weekly archive (only if you over-ride the general date format)
964 $archive_week_start_date_format = 'Y/m/d';
965 $archive_week_end_date_format = 'Y/m/d';
967 if ( !$archive_date_format_over_ride ) {
968 $archive_day_date_format = get_option('date_format');
969 $archive_week_start_date_format = get_option('date_format');
970 $archive_week_end_date_format = get_option('date_format');
973 $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
974 $join = apply_filters( 'getarchives_join', '', $r );
978 $last_changed = wp_cache_get( 'last_changed', 'posts' );
979 if ( ! $last_changed ) {
980 $last_changed = microtime();
981 wp_cache_set( 'last_changed', $last_changed, 'posts' );
984 if ( 'monthly' == $type ) {
985 $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";
986 $key = md5( $query );
987 $key = "wp_get_archives:$key:$last_changed";
988 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
989 $results = $wpdb->get_results( $query );
990 wp_cache_set( $key, $results, 'posts' );
993 $afterafter = $after;
994 foreach ( (array) $results as $result ) {
995 $url = get_month_link( $result->year, $result->month );
996 /* translators: 1: month name, 2: 4-digit year */
997 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
998 if ( $show_post_count )
999 $after = ' ('.$result->posts.')' . $afterafter;
1000 $output .= get_archives_link($url, $text, $format, $before, $after);
1003 } elseif ('yearly' == $type) {
1004 $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";
1005 $key = md5( $query );
1006 $key = "wp_get_archives:$key:$last_changed";
1007 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1008 $results = $wpdb->get_results( $query );
1009 wp_cache_set( $key, $results, 'posts' );
1012 $afterafter = $after;
1013 foreach ( (array) $results as $result) {
1014 $url = get_year_link($result->year);
1015 $text = sprintf('%d', $result->year);
1016 if ($show_post_count)
1017 $after = ' ('.$result->posts.')' . $afterafter;
1018 $output .= get_archives_link($url, $text, $format, $before, $after);
1021 } elseif ( 'daily' == $type ) {
1022 $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";
1023 $key = md5( $query );
1024 $key = "wp_get_archives:$key:$last_changed";
1025 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1026 $results = $wpdb->get_results( $query );
1027 $cache[ $key ] = $results;
1028 wp_cache_set( $key, $results, 'posts' );
1031 $afterafter = $after;
1032 foreach ( (array) $results as $result ) {
1033 $url = get_day_link($result->year, $result->month, $result->dayofmonth);
1034 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth);
1035 $text = mysql2date($archive_day_date_format, $date);
1036 if ($show_post_count)
1037 $after = ' ('.$result->posts.')'.$afterafter;
1038 $output .= get_archives_link($url, $text, $format, $before, $after);
1041 } elseif ( 'weekly' == $type ) {
1042 $week = _wp_mysql_week( '`post_date`' );
1043 $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";
1044 $key = md5( $query );
1045 $key = "wp_get_archives:$key:$last_changed";
1046 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1047 $results = $wpdb->get_results( $query );
1048 wp_cache_set( $key, $results, 'posts' );
1051 $afterafter = $after;
1053 foreach ( (array) $results as $result ) {
1054 if ( $result->week != $arc_w_last ) {
1055 $arc_year = $result->yr;
1056 $arc_w_last = $result->week;
1057 $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week'));
1058 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
1059 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
1060 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week);
1061 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
1062 if ($show_post_count)
1063 $after = ' ('.$result->posts.')'.$afterafter;
1064 $output .= get_archives_link($url, $text, $format, $before, $after);
1068 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
1069 $orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';
1070 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1071 $key = md5( $query );
1072 $key = "wp_get_archives:$key:$last_changed";
1073 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1074 $results = $wpdb->get_results( $query );
1075 wp_cache_set( $key, $results, 'posts' );
1078 foreach ( (array) $results as $result ) {
1079 if ( $result->post_date != '0000-00-00 00:00:00' ) {
1080 $url = get_permalink( $result );
1081 if ( $result->post_title ) {
1082 /** This filter is documented in wp-includes/post-template.php */
1083 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1085 $text = $result->ID;
1087 $output .= get_archives_link($url, $text, $format, $before, $after);
1099 * Get number of days since the start of the week.
1103 * @param int $num Number of day.
1104 * @return int Days since the start of the week.
1106 function calendar_week_mod($num) {
1108 return ($num - $base*floor($num/$base));
1112 * Display calendar with days that have posts as links.
1114 * The calendar is cached, which will be retrieved, if it exists. If there are
1115 * no posts for the month, then it will not be displayed.
1118 * @uses calendar_week_mod()
1120 * @param bool $initial Optional, default is true. Use initial calendar names.
1121 * @param bool $echo Optional, default is true. Set to false for return.
1122 * @return string|null String when retrieving, null when displaying.
1124 function get_calendar($initial = true, $echo = true) {
1125 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1128 $key = md5( $m . $monthnum . $year );
1129 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
1130 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
1132 echo apply_filters( 'get_calendar', $cache[$key] );
1135 return apply_filters( 'get_calendar', $cache[$key] );
1140 if ( !is_array($cache) )
1143 // Quick check. If we have no posts at all, abort!
1145 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1147 $cache[ $key ] = '';
1148 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1153 if ( isset($_GET['w']) )
1154 $w = ''.intval($_GET['w']);
1156 // week_begins = 0 stands for Sunday
1157 $week_begins = intval(get_option('start_of_week'));
1159 // Let's figure out when we are
1160 if ( !empty($monthnum) && !empty($year) ) {
1161 $thismonth = ''.zeroise(intval($monthnum), 2);
1162 $thisyear = ''.intval($year);
1163 } elseif ( !empty($w) ) {
1164 // We need to get the month from MySQL
1165 $thisyear = ''.intval(substr($m, 0, 4));
1166 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
1167 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1168 } elseif ( !empty($m) ) {
1169 $thisyear = ''.intval(substr($m, 0, 4));
1170 if ( strlen($m) < 6 )
1173 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1175 $thisyear = gmdate('Y', current_time('timestamp'));
1176 $thismonth = gmdate('m', current_time('timestamp'));
1179 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1180 $last_day = date('t', $unixmonth);
1182 // Get the next and previous month and year with at least one post
1183 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1185 WHERE post_date < '$thisyear-$thismonth-01'
1186 AND post_type = 'post' AND post_status = 'publish'
1187 ORDER BY post_date DESC
1189 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1191 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1192 AND post_type = 'post' AND post_status = 'publish'
1193 ORDER BY post_date ASC
1196 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1197 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1198 $calendar_output = '<table id="wp-calendar">
1199 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1205 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1206 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1209 foreach ( $myweek as $wd ) {
1210 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1211 $wd = esc_attr($wd);
1212 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1215 $calendar_output .= '
1223 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
1225 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1228 $calendar_output .= "\n\t\t".'<td class="pad"> </td>';
1231 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
1233 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1236 $calendar_output .= '
1243 // Get days with posts
1244 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1245 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1246 AND post_type = 'post' AND post_status = 'publish'
1247 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1248 if ( $dayswithposts ) {
1249 foreach ( (array) $dayswithposts as $daywith ) {
1250 $daywithpost[] = $daywith[0];
1253 $daywithpost = array();
1256 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
1257 $ak_title_separator = "\n";
1259 $ak_title_separator = ', ';
1261 $ak_titles_for_day = array();
1262 $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
1263 ."FROM $wpdb->posts "
1264 ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
1265 ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
1266 ."AND post_type = 'post' AND post_status = 'publish'"
1268 if ( $ak_post_titles ) {
1269 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1271 /** This filter is documented in wp-includes/post-template.php */
1272 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
1274 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1275 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1276 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1277 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1279 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1283 // See how much we should pad in the beginning
1284 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1286 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';
1288 $daysinmonth = intval(date('t', $unixmonth));
1289 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1290 if ( isset($newrow) && $newrow )
1291 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1294 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
1295 $calendar_output .= '<td id="today">';
1297 $calendar_output .= '<td>';
1299 if ( in_array($day, $daywithpost) ) // any posts today?
1300 $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
1302 $calendar_output .= $day;
1303 $calendar_output .= '</td>';
1305 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1309 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1310 if ( $pad != 0 && $pad != 7 )
1311 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';
1313 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1315 $cache[ $key ] = $calendar_output;
1316 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1319 echo apply_filters( 'get_calendar', $calendar_output );
1321 return apply_filters( 'get_calendar', $calendar_output );
1326 * Purge the cached results of get_calendar.
1331 function delete_get_calendar_cache() {
1332 wp_cache_delete( 'get_calendar', 'calendar' );
1334 add_action( 'save_post', 'delete_get_calendar_cache' );
1335 add_action( 'delete_post', 'delete_get_calendar_cache' );
1336 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1337 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1340 * Display all of the allowed tags in HTML format with attributes.
1342 * This is useful for displaying in the comment area, which elements and
1343 * attributes are supported. As well as any plugins which want to display it.
1346 * @uses $allowedtags
1348 * @return string HTML allowed tags entity encoded.
1350 function allowed_tags() {
1351 global $allowedtags;
1353 foreach ( (array) $allowedtags as $tag => $attributes ) {
1354 $allowed .= '<'.$tag;
1355 if ( 0 < count($attributes) ) {
1356 foreach ( $attributes as $attribute => $limits ) {
1357 $allowed .= ' '.$attribute.'=""';
1362 return htmlentities($allowed);
1365 /***** Date/Time tags *****/
1368 * Outputs the date in iso8601 format for xml files.
1372 function the_date_xml() {
1373 echo mysql2date( 'Y-m-d', get_post()->post_date, false );
1377 * Display or Retrieve the date the current $post was written (once per date)
1379 * Will only output the date if the current post's date is different from the
1380 * previous one output.
1382 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
1383 * function is called several times for each post.
1385 * HTML output can be filtered with 'the_date'.
1386 * Date string output can be filtered with 'get_the_date'.
1389 * @uses get_the_date()
1390 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1391 * @param string $before Optional. Output before the date.
1392 * @param string $after Optional. Output after the date.
1393 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1394 * @return string|null Null if displaying, string if retrieving.
1396 function the_date( $d = '', $before = '', $after = '', $echo = true ) {
1397 global $currentday, $previousday;
1399 if ( $currentday != $previousday ) {
1400 $the_date .= $before;
1401 $the_date .= get_the_date( $d );
1402 $the_date .= $after;
1403 $previousday = $currentday;
1405 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
1417 * Retrieve the date the current $post was written.
1419 * Unlike the_date() this function will always return the date.
1420 * Modify output with 'get_the_date' filter.
1424 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1425 * @return string|null Null if displaying, string if retrieving.
1427 function get_the_date( $d = '' ) {
1432 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
1434 $the_date .= mysql2date($d, $post->post_date);
1436 return apply_filters('get_the_date', $the_date, $d);
1440 * Display the date on which the post was last modified.
1444 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1445 * @param string $before Optional. Output before the date.
1446 * @param string $after Optional. Output after the date.
1447 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1448 * @return string|null Null if displaying, string if retrieving.
1450 function the_modified_date($d = '', $before='', $after='', $echo = true) {
1452 $the_modified_date = $before . get_the_modified_date($d) . $after;
1453 $the_modified_date = apply_filters('the_modified_date', $the_modified_date, $d, $before, $after);
1456 echo $the_modified_date;
1458 return $the_modified_date;
1463 * Retrieve the date on which the post was last modified.
1467 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1470 function get_the_modified_date($d = '') {
1472 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1474 $the_time = get_post_modified_time($d, null, null, true);
1475 return apply_filters('get_the_modified_date', $the_time, $d);
1479 * Display the time at which the post was written.
1483 * @param string $d Either 'G', 'U', or php date format.
1485 function the_time( $d = '' ) {
1486 echo apply_filters('the_time', get_the_time( $d ), $d);
1490 * Retrieve the time at which the post was written.
1494 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1495 * @param int|object $post Optional post ID or object. Default is global $post object.
1498 function get_the_time( $d = '', $post = null ) {
1499 $post = get_post($post);
1502 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1504 $the_time = get_post_time($d, false, $post, true);
1505 return apply_filters('get_the_time', $the_time, $d, $post);
1509 * Retrieve the time at which the post was written.
1513 * @param string $d Optional Either 'G', 'U', or php date format.
1514 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
1515 * @param int|object $post Optional post ID or object. Default is global $post object.
1516 * @param bool $translate Whether to translate the time string
1519 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
1520 $post = get_post($post);
1523 $time = $post->post_date_gmt;
1525 $time = $post->post_date;
1527 $time = mysql2date($d, $time, $translate);
1528 return apply_filters('get_post_time', $time, $d, $gmt);
1532 * Display the time at which the post was last modified.
1536 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1538 function the_modified_time($d = '') {
1539 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
1543 * Retrieve the time at which the post was last modified.
1547 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1550 function get_the_modified_time($d = '') {
1552 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1554 $the_time = get_post_modified_time($d, null, null, true);
1555 return apply_filters('get_the_modified_time', $the_time, $d);
1559 * Retrieve the time at which the post was last modified.
1563 * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
1564 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
1565 * @param int|object $post Optional, default is global post object. A post_id or post object
1566 * @param bool $translate Optional, default is false. Whether to translate the result
1567 * @return string Returns timestamp
1569 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1570 $post = get_post($post);
1573 $time = $post->post_modified_gmt;
1575 $time = $post->post_modified;
1576 $time = mysql2date($d, $time, $translate);
1578 return apply_filters('get_post_modified_time', $time, $d, $gmt);
1582 * Display the weekday on which the post was written.
1588 function the_weekday() {
1590 $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
1591 $the_weekday = apply_filters('the_weekday', $the_weekday);
1596 * Display the weekday on which the post was written.
1598 * Will only output the weekday if the current post's weekday is different from
1599 * the previous one output.
1603 * @param string $before Optional Output before the date.
1604 * @param string $after Optional Output after the date.
1606 function the_weekday_date($before='',$after='') {
1607 global $wp_locale, $currentday, $previousweekday;
1608 $the_weekday_date = '';
1609 if ( $currentday != $previousweekday ) {
1610 $the_weekday_date .= $before;
1611 $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
1612 $the_weekday_date .= $after;
1613 $previousweekday = $currentday;
1615 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
1616 echo $the_weekday_date;
1620 * Fire the wp_head action
1623 * @uses do_action() Calls 'wp_head' hook.
1625 function wp_head() {
1626 do_action('wp_head');
1630 * Fire the wp_footer action
1633 * @uses do_action() Calls 'wp_footer' hook.
1635 function wp_footer() {
1636 do_action('wp_footer');
1640 * Display the links to the general feeds.
1644 * @param array $args Optional arguments.
1646 function feed_links( $args = array() ) {
1647 if ( !current_theme_supports('automatic-feed-links') )
1651 /* translators: Separator between blog name and feed type in feed links */
1652 'separator' => _x('»', 'feed link'),
1653 /* translators: 1: blog title, 2: separator (raquo) */
1654 'feedtitle' => __('%1$s %2$s Feed'),
1655 /* translators: 1: blog title, 2: separator (raquo) */
1656 'comstitle' => __('%1$s %2$s Comments Feed'),
1659 $args = wp_parse_args( $args, $defaults );
1661 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";
1662 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";
1666 * Display the links to the extra feeds such as category feeds.
1670 * @param array $args Optional arguments.
1672 function feed_links_extra( $args = array() ) {
1674 /* translators: Separator between blog name and feed type in feed links */
1675 'separator' => _x('»', 'feed link'),
1676 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
1677 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
1678 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
1679 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
1680 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
1681 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
1682 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
1683 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
1684 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
1685 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
1686 /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
1687 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
1690 $args = wp_parse_args( $args, $defaults );
1692 if ( is_singular() ) {
1694 $post = get_post( $id );
1696 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
1697 $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) );
1698 $href = get_post_comments_feed_link( $post->ID );
1700 } elseif ( is_post_type_archive() ) {
1701 $post_type = get_query_var( 'post_type' );
1702 if ( is_array( $post_type ) )
1703 $post_type = reset( $post_type );
1705 $post_type_obj = get_post_type_object( $post_type );
1706 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
1707 $href = get_post_type_archive_feed_link( $post_type_obj->name );
1708 } elseif ( is_category() ) {
1709 $term = get_queried_object();
1712 $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
1713 $href = get_category_feed_link( $term->term_id );
1715 } elseif ( is_tag() ) {
1716 $term = get_queried_object();
1719 $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
1720 $href = get_tag_feed_link( $term->term_id );
1722 } elseif ( is_author() ) {
1723 $author_id = intval( get_query_var('author') );
1725 $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
1726 $href = get_author_feed_link( $author_id );
1727 } elseif ( is_search() ) {
1728 $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
1729 $href = get_search_feed_link();
1730 } elseif ( is_post_type_archive() ) {
1731 $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
1732 $post_type_obj = get_queried_object();
1733 if ( $post_type_obj )
1734 $href = get_post_type_archive_feed_link( $post_type_obj->name );
1737 if ( isset($title) && isset($href) )
1738 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
1742 * Display the link to the Really Simple Discovery service endpoint.
1744 * @link http://archipelago.phrasewise.com/rsd
1747 function rsd_link() {
1748 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
1752 * Display the link to the Windows Live Writer manifest file.
1754 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
1757 function wlwmanifest_link() {
1758 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
1759 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
1763 * Display a noindex meta tag if required by the blog configuration.
1765 * If a blog is marked as not being public then the noindex meta tag will be
1766 * output to tell web robots not to index the page content. Add this to the wp_head action.
1767 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
1773 function noindex() {
1774 // If the blog is not public, tell robots to go away.
1775 if ( '0' == get_option('blog_public') )
1780 * Display a noindex meta tag.
1782 * Outputs a noindex meta tag that tells web robots not to index the page content.
1783 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
1787 function wp_no_robots() {
1788 echo "<meta name='robots' content='noindex,nofollow' />\n";
1792 * Determine if TinyMCE is available.
1794 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
1798 * @return bool Whether TinyMCE exists.
1800 function rich_edit_exists() {
1801 global $wp_rich_edit_exists;
1802 if ( !isset($wp_rich_edit_exists) )
1803 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
1804 return $wp_rich_edit_exists;
1808 * Whether the user should have a WYSIWIG editor.
1810 * Checks that the user requires a WYSIWIG editor and that the editor is
1811 * supported in the users browser.
1817 function user_can_richedit() {
1818 global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
1820 if ( !isset($wp_rich_edit) ) {
1821 $wp_rich_edit = false;
1823 if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
1825 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
1826 } elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
1827 $wp_rich_edit = true;
1832 return apply_filters('user_can_richedit', $wp_rich_edit);
1836 * Find out which editor should be displayed by default.
1838 * Works out which of the two editors to display as the current editor for a
1839 * user. The 'html' setting is for the "Text" editor tab.
1843 * @return string Either 'tinymce', or 'html', or 'test'
1845 function wp_default_editor() {
1846 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
1847 if ( $user = wp_get_current_user() ) { // look for cookie
1848 $ed = get_user_setting('editor', 'tinymce');
1849 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
1851 return apply_filters( 'wp_default_editor', $r ); // filter
1855 * Renders an editor.
1857 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
1858 * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
1860 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
1861 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
1862 * On the post edit screen several actions can be used to include additional editors
1863 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
1864 * See http://core.trac.wordpress.org/ticket/19173 for more information.
1866 * @see wp-includes/class-wp-editor.php
1869 * @param string $content Initial content for the editor.
1870 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
1871 * @param array $settings See _WP_Editors::editor().
1873 function wp_editor( $content, $editor_id, $settings = array() ) {
1874 if ( ! class_exists( '_WP_Editors' ) )
1875 require( ABSPATH . WPINC . '/class-wp-editor.php' );
1877 _WP_Editors::editor($content, $editor_id, $settings);
1881 * Retrieve the contents of the search WordPress query variable.
1883 * The search query string is passed through {@link esc_attr()}
1884 * to ensure that it is safe for placing in an html attribute.
1889 * @param bool $escaped Whether the result is escaped. Default true.
1890 * Only use when you are later escaping it. Do not use unescaped.
1893 function get_search_query( $escaped = true ) {
1894 $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
1896 $query = esc_attr( $query );
1901 * Display the contents of the search query variable.
1903 * The search query string is passed through {@link esc_attr()}
1904 * to ensure that it is safe for placing in an html attribute.
1909 function the_search_query() {
1910 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
1914 * Display the language attributes for the html tag.
1916 * Builds up a set of html attributes containing the text direction and language
1917 * information for the page.
1921 * @param string $doctype The type of html document (xhtml|html).
1923 function language_attributes($doctype = 'html') {
1924 $attributes = array();
1927 if ( function_exists( 'is_rtl' ) && is_rtl() )
1928 $attributes[] = 'dir="rtl"';
1930 if ( $lang = get_bloginfo('language') ) {
1931 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
1932 $attributes[] = "lang=\"$lang\"";
1934 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1935 $attributes[] = "xml:lang=\"$lang\"";
1938 $output = implode(' ', $attributes);
1939 $output = apply_filters('language_attributes', $output);
1944 * Retrieve paginated link for archive post pages.
1946 * Technically, the function can be used to create paginated link list for any
1947 * area. The 'base' argument is used to reference the url, which will be used to
1948 * create the paginated links. The 'format' argument is then used for replacing
1949 * the page number. It is however, most likely and by default, to be used on the
1950 * archive post pages.
1952 * The 'type' argument controls format of the returned value. The default is
1953 * 'plain', which is just a string with the links separated by a newline
1954 * character. The other possible values are either 'array' or 'list'. The
1955 * 'array' value will return an array of the paginated link list to offer full
1956 * control of display. The 'list' value will place all of the paginated links in
1957 * an unordered HTML list.
1959 * The 'total' argument is the total amount of pages and is an integer. The
1960 * 'current' argument is the current page number and is also an integer.
1962 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
1963 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
1964 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
1965 * and the '%#%' is also required. The '%#%' will be replaced with the page
1968 * You can include the previous and next links in the list by setting the
1969 * 'prev_next' argument to true, which it is by default. You can set the
1970 * previous text, by using the 'prev_text' argument. You can set the next text
1971 * by setting the 'next_text' argument.
1973 * If the 'show_all' argument is set to true, then it will show all of the pages
1974 * instead of a short list of the pages near the current page. By default, the
1975 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
1976 * arguments. The 'end_size' argument is how many numbers on either the start
1977 * and the end list edges, by default is 1. The 'mid_size' argument is how many
1978 * numbers to either side of current page, but not including current page.
1980 * It is possible to add query vars to the link by using the 'add_args' argument
1981 * and see {@link add_query_arg()} for more information.
1985 * @param string|array $args Optional. Override defaults.
1986 * @return array|string String of page links or array of page links.
1988 function paginate_links( $args = '' ) {
1990 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1991 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1994 'show_all' => false,
1995 'prev_next' => true,
1996 'prev_text' => __('« Previous'),
1997 'next_text' => __('Next »'),
2001 'add_args' => false, // array of query args to add
2002 'add_fragment' => ''
2005 $args = wp_parse_args( $args, $defaults );
2006 extract($args, EXTR_SKIP);
2008 // Who knows what else people pass in $args
2009 $total = (int) $total;
2012 $current = (int) $current;
2013 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
2014 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
2015 $add_args = is_array($add_args) ? $add_args : false;
2017 $page_links = array();
2021 if ( $prev_next && $current && 1 < $current ) :
2022 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
2023 $link = str_replace('%#%', $current - 1, $link);
2025 $link = add_query_arg( $add_args, $link );
2026 $link .= $add_fragment;
2027 $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';
2029 for ( $n = 1; $n <= $total; $n++ ) :
2030 $n_display = number_format_i18n($n);
2031 if ( $n == $current ) :
2032 $page_links[] = "<span class='page-numbers current'>$n_display</span>";
2035 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
2036 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
2037 $link = str_replace('%#%', $n, $link);
2039 $link = add_query_arg( $add_args, $link );
2040 $link .= $add_fragment;
2041 $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
2043 elseif ( $dots && !$show_all ) :
2044 $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
2049 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
2050 $link = str_replace('%_%', $format, $base);
2051 $link = str_replace('%#%', $current + 1, $link);
2053 $link = add_query_arg( $add_args, $link );
2054 $link .= $add_fragment;
2055 $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';
2062 $r .= "<ul class='page-numbers'>\n\t<li>";
2063 $r .= join("</li>\n\t<li>", $page_links);
2064 $r .= "</li>\n</ul>\n";
2067 $r = join("\n", $page_links);
2074 * Registers an admin colour scheme css file.
2076 * Allows a plugin to register a new admin colour scheme. For example:
2078 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
2079 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
2084 * @param string $key The unique key for this theme.
2085 * @param string $name The name of the theme.
2086 * @param string $url The url of the css file containing the colour scheme.
2087 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
2089 function wp_admin_css_color($key, $name, $url, $colors = array()) {
2090 global $_wp_admin_css_colors;
2092 if ( !isset($_wp_admin_css_colors) )
2093 $_wp_admin_css_colors = array();
2095 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
2099 * Registers the default Admin color schemes
2103 function register_admin_color_schemes() {
2104 wp_admin_css_color( 'classic', _x( 'Blue', 'admin color scheme' ), admin_url( 'css/colors-classic.min.css' ),
2105 array( '#5589aa', '#cfdfe9', '#d1e5ee', '#eff8ff' ) );
2106 wp_admin_css_color( 'fresh', _x( 'Gray', 'admin color scheme' ), admin_url( 'css/colors-fresh.min.css' ),
2107 array( '#555', '#a0a0a0', '#ccc', '#f1f1f1' ) );
2111 * Display the URL of a WordPress admin CSS file.
2113 * @see WP_Styles::_css_href and its style_loader_src filter.
2117 * @param string $file file relative to wp-admin/ without its ".css" extension.
2119 function wp_admin_css_uri( $file = 'wp-admin' ) {
2120 if ( defined('WP_INSTALLING') ) {
2121 $_file = "./$file.css";
2123 $_file = admin_url("$file.css");
2125 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
2127 return apply_filters( 'wp_admin_css_uri', $_file, $file );
2131 * Enqueues or directly prints a stylesheet link to the specified CSS file.
2133 * "Intelligently" decides to enqueue or to print the CSS file. If the
2134 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
2135 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
2136 * be printed. Printing may be forced by passing true as the $force_echo
2137 * (second) parameter.
2139 * For backward compatibility with WordPress 2.3 calling method: If the $file
2140 * (first) parameter does not correspond to a registered CSS file, we assume
2141 * $file is a file relative to wp-admin/ without its ".css" extension. A
2142 * stylesheet link to that generated URL is printed.
2144 * @package WordPress
2146 * @uses $wp_styles WordPress Styles Object
2148 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
2149 * to wp-admin/. Defaults to 'wp-admin'.
2150 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
2152 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
2154 if ( !is_a($wp_styles, 'WP_Styles') )
2155 $wp_styles = new WP_Styles();
2157 // For backward compatibility
2158 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
2160 if ( $wp_styles->query( $handle ) ) {
2161 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
2162 wp_print_styles( $handle );
2163 else // Add to style queue
2164 wp_enqueue_style( $handle );
2168 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
2169 if ( function_exists( 'is_rtl' ) && is_rtl() )
2170 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
2174 * Enqueues the default ThickBox js and css.
2176 * If any of the settings need to be changed, this can be done with another js
2177 * file similar to media-upload.js. That file should
2178 * require array('thickbox') to ensure it is loaded after.
2182 function add_thickbox() {
2183 wp_enqueue_script( 'thickbox' );
2184 wp_enqueue_style( 'thickbox' );
2186 if ( is_network_admin() )
2187 add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
2191 * Display the XHTML generator that is generated on the wp_head hook.
2195 function wp_generator() {
2196 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
2200 * Display the generator XML or Comment for RSS, ATOM, etc.
2202 * Returns the correct generator type for the requested output format. Allows
2203 * for a plugin to filter generators overall the the_generator filter.
2206 * @uses apply_filters() Calls 'the_generator' hook.
2208 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2210 function the_generator( $type ) {
2211 echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
2215 * Creates the generator XML or Comment for RSS, ATOM, etc.
2217 * Returns the correct generator type for the requested output format. Allows
2218 * for a plugin to filter generators on an individual basis using the
2219 * 'get_the_generator_{$type}' filter.
2222 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
2224 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2225 * @return string The HTML content for the generator.
2227 function get_the_generator( $type = '' ) {
2228 if ( empty( $type ) ) {
2230 $current_filter = current_filter();
2231 if ( empty( $current_filter ) )
2234 switch ( $current_filter ) {
2236 case 'commentsrss2_head' :
2247 case 'comments_atom_head' :
2256 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2259 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2262 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2265 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2268 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2271 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2274 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
2277 return apply_filters( "get_the_generator_{$type}", $gen, $type );
2281 * Outputs the html checked attribute.
2283 * Compares the first two arguments and if identical marks as checked
2287 * @param mixed $checked One of the values to compare
2288 * @param mixed $current (true) The other value to compare if not just true
2289 * @param bool $echo Whether to echo or just return the string
2290 * @return string html attribute or empty string
2292 function checked( $checked, $current = true, $echo = true ) {
2293 return __checked_selected_helper( $checked, $current, $echo, 'checked' );
2297 * Outputs the html selected attribute.
2299 * Compares the first two arguments and if identical marks as selected
2303 * @param mixed $selected One of the values to compare
2304 * @param mixed $current (true) The other value to compare if not just true
2305 * @param bool $echo Whether to echo or just return the string
2306 * @return string html attribute or empty string
2308 function selected( $selected, $current = true, $echo = true ) {
2309 return __checked_selected_helper( $selected, $current, $echo, 'selected' );
2313 * Outputs the html disabled attribute.
2315 * Compares the first two arguments and if identical marks as disabled
2319 * @param mixed $disabled One of the values to compare
2320 * @param mixed $current (true) The other value to compare if not just true
2321 * @param bool $echo Whether to echo or just return the string
2322 * @return string html attribute or empty string
2324 function disabled( $disabled, $current = true, $echo = true ) {
2325 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
2329 * Private helper function for checked, selected, and disabled.
2331 * Compares the first two arguments and if identical marks as $type
2336 * @param mixed $helper One of the values to compare
2337 * @param mixed $current (true) The other value to compare if not just true
2338 * @param bool $echo Whether to echo or just return the string
2339 * @param string $type The type of checked|selected|disabled we are doing
2340 * @return string html attribute or empty string
2342 function __checked_selected_helper( $helper, $current, $echo, $type ) {
2343 if ( (string) $helper === (string) $current )
2344 $result = " $type='$type'";
2355 * Default settings for heartbeat
2357 * Outputs the nonce used in the heartbeat XHR
2361 * @param array $settings
2362 * @return array $settings
2364 function wp_heartbeat_settings( $settings ) {
2366 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
2368 if ( is_user_logged_in() )
2369 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );