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 );
29 $templates[] = "header-{$name}.php";
31 $templates[] = "header.php";
33 // Backward compat code will be removed in a future release
34 if ('' == locate_template($templates, true))
35 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
39 * Load footer template.
41 * Includes the footer template for a theme or if a name is specified then a
42 * specialised footer will be included.
44 * For the parameter, if the file is called "footer-special.php" then specify
47 * @uses locate_template()
49 * @uses do_action() Calls 'get_footer' action.
51 * @param string $name The name of the specialised footer.
53 function get_footer( $name = null ) {
54 do_action( 'get_footer', $name );
58 $templates[] = "footer-{$name}.php";
60 $templates[] = "footer.php";
62 // Backward compat code will be removed in a future release
63 if ('' == locate_template($templates, true))
64 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
68 * Load sidebar template.
70 * Includes the sidebar template for a theme or if a name is specified then a
71 * specialised sidebar will be included.
73 * For the parameter, if the file is called "sidebar-special.php" then specify
76 * @uses locate_template()
78 * @uses do_action() Calls 'get_sidebar' action.
80 * @param string $name The name of the specialised sidebar.
82 function get_sidebar( $name = null ) {
83 do_action( 'get_sidebar', $name );
87 $templates[] = "sidebar-{$name}.php";
89 $templates[] = "sidebar.php";
91 // Backward compat code will be removed in a future release
92 if ('' == locate_template($templates, true))
93 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
97 * Load a template part into a template
99 * Makes it easy for a theme to reuse sections of code in a easy to overload way
102 * Includes the named template part for a theme or if a name is specified then a
103 * specialised part will be included. If the theme contains no {slug}.php file
104 * then no template will be included.
106 * The template is included using require, not require_once, so you may include the
107 * same template part multiple times.
109 * For the parameter, if the file is called "{slug}-special.php" then specify
112 * @uses locate_template()
114 * @uses do_action() Calls 'get_template_part{$slug}' action.
116 * @param string $slug The slug name for the generic template.
117 * @param string $name The name of the specialised template.
119 function get_template_part( $slug, $name = null ) {
120 do_action( "get_template_part_{$slug}", $slug, $name );
122 $templates = array();
124 $templates[] = "{$slug}-{$name}.php";
126 $templates[] = "{$slug}.php";
128 locate_template($templates, true, false);
132 * Display search form.
134 * Will first attempt to locate the searchform.php file in either the child or
135 * the parent, then load it. If it doesn't exist, then the default search form
136 * will be displayed. The default search form is HTML, which will be displayed.
137 * There is a filter applied to the search form HTML in order to edit or replace
138 * it. The filter is 'get_search_form'.
140 * This function is primarily used by themes which want to hardcode the search
141 * form into the sidebar and also by the search widget in WordPress.
143 * There is also an action that is called whenever the function is run called,
144 * 'get_search_form'. This can be useful for outputting JavaScript that the
145 * search relies on or various formatting that applies to the beginning of the
146 * search. To give a few examples of what it can be used for.
149 * @param boolean $echo Default to echo and not return the form.
151 function get_search_form($echo = true) {
152 do_action( 'get_search_form' );
154 $search_form_template = locate_template(array('searchform.php'));
155 if ( '' != $search_form_template ) {
156 require($search_form_template);
160 $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
161 <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
162 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
163 <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
168 echo apply_filters('get_search_form', $form);
170 return apply_filters('get_search_form', $form);
174 * Display the Log In/Out link.
176 * Displays a link, which allows users to navigate to the Log In page to log in
177 * or log out depending on whether they are currently logged in.
180 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
182 * @param string $redirect Optional path to redirect to on login/logout.
183 * @param boolean $echo Default to echo and not return the link.
185 function wp_loginout($redirect = '', $echo = true) {
186 if ( ! is_user_logged_in() )
187 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
189 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
192 echo apply_filters('loginout', $link);
194 return apply_filters('loginout', $link);
198 * Returns the Log Out URL.
200 * Returns the URL that allows the user to log out of the site
203 * @uses wp_nonce_url() To protect against CSRF
204 * @uses site_url() To generate the log in URL
205 * @uses apply_filters() calls 'logout_url' hook on final logout url
207 * @param string $redirect Path to redirect to on logout.
209 function wp_logout_url($redirect = '') {
210 $args = array( 'action' => 'logout' );
211 if ( !empty($redirect) ) {
212 $args['redirect_to'] = urlencode( $redirect );
215 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
216 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
218 return apply_filters('logout_url', $logout_url, $redirect);
222 * Returns the Log In URL.
224 * Returns the URL that allows the user to log in to the site
227 * @uses site_url() To generate the log in URL
228 * @uses apply_filters() calls 'login_url' hook on final login url
230 * @param string $redirect Path to redirect to on login.
231 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
232 * @return string A log in url
234 function wp_login_url($redirect = '', $force_reauth = false) {
235 $login_url = site_url('wp-login.php', 'login');
237 if ( !empty($redirect) )
238 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
241 $login_url = add_query_arg('reauth', '1', $login_url);
243 return apply_filters('login_url', $login_url, $redirect);
247 * Provides a simple login form for use anywhere within WordPress. By default, it echoes
248 * the HTML immediately. Pass array('echo'=>false) to return the string instead.
251 * @param array $args Configuration options to modify the form output
252 * @return Void, or string containing the form
254 function wp_login_form( $args = array() ) {
255 $defaults = array( 'echo' => true,
256 'redirect' => site_url( $_SERVER['REQUEST_URI'] ), // Default redirect is back to the current page
257 'form_id' => 'loginform',
258 'label_username' => __( 'Username' ),
259 'label_password' => __( 'Password' ),
260 'label_remember' => __( 'Remember Me' ),
261 'label_log_in' => __( 'Log In' ),
262 'id_username' => 'user_login',
263 'id_password' => 'user_pass',
264 'id_remember' => 'rememberme',
265 'id_submit' => 'wp-submit',
267 'value_username' => '',
268 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
270 $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
273 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . site_url( 'wp-login.php', 'login' ) . '" method="post">
274 ' . apply_filters( 'login_form_top', '' ) . '
275 <p class="login-username">
276 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
277 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" tabindex="10" />
279 <p class="login-password">
280 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
281 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" tabindex="20" />
283 ' . apply_filters( 'login_form_middle', '' ) . '
284 ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever" tabindex="90"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
285 <p class="login-submit">
286 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" tabindex="100" />
287 <input type="hidden" name="redirect_to" value="' . esc_attr( $args['redirect'] ) . '" />
289 ' . apply_filters( 'login_form_bottom', '' ) . '
299 * Returns the Lost Password URL.
301 * Returns the URL that allows the user to retrieve the lost password
304 * @uses site_url() To generate the lost password URL
305 * @uses apply_filters() calls 'lostpassword_url' hook on the lostpassword url
307 * @param string $redirect Path to redirect to on login.
309 function wp_lostpassword_url($redirect = '') {
310 $args = array( 'action' => 'lostpassword' );
311 if ( !empty($redirect) ) {
312 $args['redirect_to'] = $redirect;
315 $lostpassword_url = add_query_arg($args, site_url('wp-login.php', 'login'));
316 return apply_filters('lostpassword_url', $lostpassword_url, $redirect);
320 * Display the Registration or Admin link.
322 * Display a link which allows the user to navigate to the registration page if
323 * not logged in and registration is enabled or to the dashboard if logged in.
326 * @uses apply_filters() Calls 'register' hook on register / admin link content.
328 * @param string $before Text to output before the link (defaults to <li>).
329 * @param string $after Text to output after the link (defaults to </li>).
330 * @param boolean $echo Default to echo and not return the link.
332 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
334 if ( ! is_user_logged_in() ) {
335 if ( get_option('users_can_register') )
336 $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
340 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
344 echo apply_filters('register', $link);
346 return apply_filters('register', $link);
350 * Theme container function for the 'wp_meta' action.
352 * The 'wp_meta' action can have several purposes, depending on how you use it,
353 * but one purpose might have been to allow for theme switching.
356 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
357 * @uses do_action() Calls 'wp_meta' hook.
360 do_action('wp_meta');
364 * Display information about the blog.
366 * @see get_bloginfo() For possible values for the parameter.
369 * @param string $show What to display.
371 function bloginfo( $show='' ) {
372 echo get_bloginfo( $show, 'display' );
376 * Retrieve information about the blog.
378 * Some show parameter values are deprecated and will be removed in future
379 * versions. These options will trigger the _deprecated_argument() function.
380 * The deprecated blog info options are listed in the function contents.
382 * The possible values for the 'show' parameter are listed below.
384 * <li><strong>url<strong> - Blog URI to homepage.</li>
385 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
386 * <li><strong>description</strong> - Secondary title</li>
389 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
390 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
391 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
392 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
396 * @param string $show Blog info to retrieve.
397 * @param string $filter How to filter what is retrieved.
398 * @return string Mostly string values, might be empty.
400 function get_bloginfo( $show = '', $filter = 'raw' ) {
403 case 'home' : // DEPRECATED
404 case 'siteurl' : // DEPRECATED
405 _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' ) );
407 $output = home_url();
410 $output = site_url();
413 $output = get_option('blogdescription');
416 $output = get_feed_link('rdf');
419 $output = get_feed_link('rss');
422 $output = get_feed_link('rss2');
425 $output = get_feed_link('atom');
427 case 'comments_atom_url':
428 $output = get_feed_link('comments_atom');
430 case 'comments_rss2_url':
431 $output = get_feed_link('comments_rss2');
434 $output = get_option('siteurl') .'/xmlrpc.php';
436 case 'stylesheet_url':
437 $output = get_stylesheet_uri();
439 case 'stylesheet_directory':
440 $output = get_stylesheet_directory_uri();
442 case 'template_directory':
444 $output = get_template_directory_uri();
447 $output = get_option('admin_email');
450 $output = get_option('blog_charset');
451 if ('' == $output) $output = 'UTF-8';
454 $output = get_option('html_type');
458 $output = $wp_version;
461 $output = get_locale();
462 $output = str_replace('_', '-', $output);
464 case 'text_direction':
465 //_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()' ) );
466 if ( function_exists( 'is_rtl' ) ) {
467 $output = is_rtl() ? 'rtl' : 'ltr';
474 $output = get_option('blogname');
479 if (strpos($show, 'url') === false &&
480 strpos($show, 'directory') === false &&
481 strpos($show, 'home') === false)
484 if ( 'display' == $filter ) {
486 $output = apply_filters('bloginfo_url', $output, $show);
488 $output = apply_filters('bloginfo', $output, $show);
495 * Display or retrieve page title for all areas of blog.
497 * By default, the page title will display the separator before the page title,
498 * so that the blog title will be before the page title. This is not good for
499 * title display, since the blog title shows up on most tabs and not what is
500 * important, which is the page that the user is looking at.
502 * There are also SEO benefits to having the blog title after or to the 'right'
503 * or the page title. However, it is mostly common sense to have the blog title
504 * to the right with most browsers supporting tabs. You can achieve this by
505 * using the seplocation parameter and setting the value to 'right'. This change
506 * was introduced around 2.5.0, in case backwards compatibility of themes is
511 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
512 * @param bool $display Optional, default is true. Whether to display or retrieve title.
513 * @param string $seplocation Optional. Direction to display title, 'right'.
514 * @return string|null String on retrieve, null when displaying.
516 function wp_title($sep = '»', $display = true, $seplocation = '') {
517 global $wpdb, $wp_locale, $wp_query;
519 $cat = get_query_var('cat');
520 $tag = get_query_var('tag_id');
521 $category_name = get_query_var('category_name');
522 $author = get_query_var('author');
523 $author_name = get_query_var('author_name');
524 $m = get_query_var('m');
525 $year = get_query_var('year');
526 $monthnum = get_query_var('monthnum');
527 $day = get_query_var('day');
528 $search = get_query_var('s');
531 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
533 // If there's a category
534 if ( !empty($cat) ) {
535 // category exclusion
536 if ( !stristr($cat,'-') )
537 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
538 } elseif ( !empty($category_name) ) {
539 if ( stristr($category_name,'/') ) {
540 $category_name = explode('/',$category_name);
541 if ( $category_name[count($category_name)-1] )
542 $category_name = $category_name[count($category_name)-1]; // no trailing slash
544 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
546 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
548 $title = apply_filters('single_cat_title', $cat->name);
551 if ( !empty($tag) ) {
552 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
553 if ( is_wp_error( $tag ) )
555 if ( ! empty($tag->name) )
556 $title = apply_filters('single_tag_title', $tag->name);
559 // If there's an author
560 if ( !empty($author) ) {
561 $title = get_userdata($author);
562 $title = $title->display_name;
564 if ( !empty($author_name) ) {
565 // We do a direct query here because we don't cache by nicename.
566 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
569 // If there's a month
571 $my_year = substr($m, 0, 4);
572 $my_month = $wp_locale->get_month(substr($m, 4, 2));
573 $my_day = intval(substr($m, 6, 2));
574 $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : "");
577 if ( !empty($year) ) {
579 if ( !empty($monthnum) )
580 $title .= $t_sep . $wp_locale->get_month($monthnum);
582 $title .= $t_sep . zeroise($day, 2);
585 // If there is a post
586 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
587 $post = $wp_query->get_queried_object();
588 $title = apply_filters( 'single_post_title', $post->post_title );
591 // If there's a taxonomy
593 $taxonomy = get_query_var( 'taxonomy' );
594 $tax = get_taxonomy( $taxonomy );
595 $term = $wp_query->get_queried_object();
597 $title = $tax->labels->name . $t_sep . $term;
602 /* translators: 1: separator, 2: search phrase */
603 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
607 $title = __('Page not found');
611 if ( !empty($title) )
614 // Determines position of the separator and direction of the breadcrumb
615 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
616 $title_array = explode( $t_sep, $title );
617 $title_array = array_reverse( $title_array );
618 $title = implode( " $sep ", $title_array ) . $prefix;
620 $title_array = explode( $t_sep, $title );
621 $title = $prefix . implode( " $sep ", $title_array );
624 $title = apply_filters('wp_title', $title, $sep, $seplocation);
635 * Display or retrieve page title for post.
637 * This is optimized for single.php template file for displaying the post title.
638 * Only useful for posts, does not support pages for example.
640 * It does not support placing the separator after the title, but by leaving the
641 * prefix parameter empty, you can set the title separator manually. The prefix
642 * does not automatically place a space between the prefix, so if there should
643 * be a space, the parameter value will need to have it at the end.
648 * @param string $prefix Optional. What to display before the title.
649 * @param bool $display Optional, default is true. Whether to display or retrieve title.
650 * @return string|null Title when retrieving, null when displaying or failure.
652 function single_post_title($prefix = '', $display = true) {
653 global $wp_query, $post;
656 $_post = $wp_query->get_queried_object();
660 if ( !isset($_post->post_title) )
663 $title = apply_filters('single_post_title', $_post->post_title, $_post);
665 echo $prefix . $title;
671 * Display or retrieve page title for category archive.
673 * This is useful for category template file or files, because it is optimized
674 * for category page title and with less overhead than {@link wp_title()}.
676 * It does not support placing the separator after the title, but by leaving the
677 * prefix parameter empty, you can set the title separator manually. The prefix
678 * does not automatically place a space between the prefix, so if there should
679 * be a space, the parameter value will need to have it at the end.
683 * @param string $prefix Optional. What to display before the title.
684 * @param bool $display Optional, default is true. Whether to display or retrieve title.
685 * @return string|null Title when retrieving, null when displaying or failure.
687 function single_cat_title($prefix = '', $display = true ) {
691 return single_tag_title($prefix, $display);
693 if ( !is_category() )
696 $cat = $wp_query->get_queried_object();
697 $my_cat_name = apply_filters('single_cat_title', $cat->name);
698 if ( !empty($my_cat_name) ) {
700 echo $prefix . $my_cat_name;
707 * Display or retrieve page title for tag post archive.
709 * Useful for tag template files for displaying the tag page title. It has less
710 * overhead than {@link wp_title()}, because of its limited implementation.
712 * It does not support placing the separator after the title, but by leaving the
713 * prefix parameter empty, you can set the title separator manually. The prefix
714 * does not automatically place a space between the prefix, so if there should
715 * be a space, the parameter value will need to have it at the end.
719 * @param string $prefix Optional. What to display before the title.
720 * @param bool $display Optional, default is true. Whether to display or retrieve title.
721 * @return string|null Title when retrieving, null when displaying or failure.
723 function single_tag_title($prefix = '', $display = true ) {
728 $tag = $wp_query->get_queried_object();
733 $my_tag_name = apply_filters('single_tag_title', $tag->name);
734 if ( !empty($my_tag_name) ) {
736 echo $prefix . $my_tag_name;
743 * Display or retrieve page title for post archive based on date.
745 * Useful for when the template only needs to display the month and year, if
746 * either are available. Optimized for just this purpose, so if it is all that
747 * is needed, should be better than {@link wp_title()}.
749 * It does not support placing the separator after the title, but by leaving the
750 * prefix parameter empty, you can set the title separator manually. The prefix
751 * does not automatically place a space between the prefix, so if there should
752 * be a space, the parameter value will need to have it at the end.
756 * @param string $prefix Optional. What to display before the title.
757 * @param bool $display Optional, default is true. Whether to display or retrieve title.
758 * @return string|null Title when retrieving, null when displaying or failure.
760 function single_month_title($prefix = '', $display = true ) {
763 $m = get_query_var('m');
764 $year = get_query_var('year');
765 $monthnum = get_query_var('monthnum');
767 if ( !empty($monthnum) && !empty($year) ) {
769 $my_month = $wp_locale->get_month($monthnum);
770 } elseif ( !empty($m) ) {
771 $my_year = substr($m, 0, 4);
772 $my_month = $wp_locale->get_month(substr($m, 4, 2));
775 if ( empty($my_month) )
778 $result = $prefix . $my_month . $prefix . $my_year;
786 * Retrieve archive link content based on predefined or custom code.
788 * The format can be one of four styles. The 'link' for head element, 'option'
789 * for use in the select element, 'html' for use in list (either ol or ul HTML
790 * elements). Custom content is also supported using the before and after
793 * The 'link' format uses the link HTML element with the <em>archives</em>
794 * relationship. The before and after parameters are not used. The text
795 * parameter is used to describe the link.
797 * The 'option' format uses the option HTML element for use in select element.
798 * The value is the url parameter and the before and after parameters are used
799 * between the text description.
801 * The 'html' format, which is the default, uses the li HTML element for use in
802 * the list HTML elements. The before parameter is before the link and the after
803 * parameter is after the closing link.
805 * The custom format uses the before parameter before the link ('a' HTML
806 * element) and the after parameter after the closing link tag. If the above
807 * three values for the format are not used, then custom format is assumed.
811 * @param string $url URL to archive.
812 * @param string $text Archive text description.
813 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
814 * @param string $before Optional.
815 * @param string $after Optional.
816 * @return string HTML link content for archive.
818 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
819 $text = wptexturize($text);
820 $title_text = esc_attr($text);
821 $url = esc_url($url);
823 if ('link' == $format)
824 $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
825 elseif ('option' == $format)
826 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
827 elseif ('html' == $format)
828 $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
830 $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
832 $link_html = apply_filters( "get_archives_link", $link_html );
838 * Display archive links based on type and format.
840 * The 'type' argument offers a few choices and by default will display monthly
841 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
842 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
843 * same archive link list, the difference between the two is that 'alpha'
844 * will order by post title and 'postbypost' will order by post date.
846 * The date archives will logically display dates with links to the archive post
847 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
850 * The 'limit' argument will only display a limited amount of links, specified
851 * by the 'limit' integer value. By default, there is no limit. The
852 * 'show_post_count' argument will show how many posts are within the archive.
853 * By default, the 'show_post_count' argument is set to false.
855 * For the 'format', 'before', and 'after' arguments, see {@link
856 * get_archives_link()}. The values of these arguments have to do with that
861 * @param string|array $args Optional. Override defaults.
863 function wp_get_archives($args = '') {
864 global $wpdb, $wp_locale;
867 'type' => 'monthly', 'limit' => '',
868 'format' => 'html', 'before' => '',
869 'after' => '', 'show_post_count' => false,
873 $r = wp_parse_args( $args, $defaults );
874 extract( $r, EXTR_SKIP );
879 if ( '' != $limit ) {
880 $limit = absint($limit);
881 $limit = ' LIMIT '.$limit;
884 // this is what will separate dates on weekly archive links
885 $archive_week_separator = '–';
887 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
888 $archive_date_format_over_ride = 0;
890 // options for daily archive (only if you over-ride the general date format)
891 $archive_day_date_format = 'Y/m/d';
893 // options for weekly archive (only if you over-ride the general date format)
894 $archive_week_start_date_format = 'Y/m/d';
895 $archive_week_end_date_format = 'Y/m/d';
897 if ( !$archive_date_format_over_ride ) {
898 $archive_day_date_format = get_option('date_format');
899 $archive_week_start_date_format = get_option('date_format');
900 $archive_week_end_date_format = get_option('date_format');
904 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
905 $join = apply_filters('getarchives_join', "", $r);
909 if ( 'monthly' == $type ) {
910 $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 DESC $limit";
912 $cache = wp_cache_get( 'wp_get_archives' , 'general');
913 if ( !isset( $cache[ $key ] ) ) {
914 $arcresults = $wpdb->get_results($query);
915 $cache[ $key ] = $arcresults;
916 wp_cache_set( 'wp_get_archives', $cache, 'general' );
918 $arcresults = $cache[ $key ];
921 $afterafter = $after;
922 foreach ( (array) $arcresults as $arcresult ) {
923 $url = get_month_link( $arcresult->year, $arcresult->month );
924 /* translators: 1: month name, 2: 4-digit year */
925 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
926 if ( $show_post_count )
927 $after = ' ('.$arcresult->posts.')' . $afterafter;
928 $output .= get_archives_link($url, $text, $format, $before, $after);
931 } elseif ('yearly' == $type) {
932 $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 DESC $limit";
934 $cache = wp_cache_get( 'wp_get_archives' , 'general');
935 if ( !isset( $cache[ $key ] ) ) {
936 $arcresults = $wpdb->get_results($query);
937 $cache[ $key ] = $arcresults;
938 wp_cache_set( 'wp_get_archives', $cache, 'general' );
940 $arcresults = $cache[ $key ];
943 $afterafter = $after;
944 foreach ( (array) $arcresults as $arcresult) {
945 $url = get_year_link($arcresult->year);
946 $text = sprintf('%d', $arcresult->year);
947 if ($show_post_count)
948 $after = ' ('.$arcresult->posts.')' . $afterafter;
949 $output .= get_archives_link($url, $text, $format, $before, $after);
952 } elseif ( 'daily' == $type ) {
953 $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 DESC $limit";
955 $cache = wp_cache_get( 'wp_get_archives' , 'general');
956 if ( !isset( $cache[ $key ] ) ) {
957 $arcresults = $wpdb->get_results($query);
958 $cache[ $key ] = $arcresults;
959 wp_cache_set( 'wp_get_archives', $cache, 'general' );
961 $arcresults = $cache[ $key ];
964 $afterafter = $after;
965 foreach ( (array) $arcresults as $arcresult ) {
966 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
967 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
968 $text = mysql2date($archive_day_date_format, $date);
969 if ($show_post_count)
970 $after = ' ('.$arcresult->posts.')'.$afterafter;
971 $output .= get_archives_link($url, $text, $format, $before, $after);
974 } elseif ( 'weekly' == $type ) {
975 $week = _wp_mysql_week( '`post_date`' );
976 $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` DESC $limit";
978 $cache = wp_cache_get( 'wp_get_archives' , 'general');
979 if ( !isset( $cache[ $key ] ) ) {
980 $arcresults = $wpdb->get_results($query);
981 $cache[ $key ] = $arcresults;
982 wp_cache_set( 'wp_get_archives', $cache, 'general' );
984 $arcresults = $cache[ $key ];
987 $afterafter = $after;
989 foreach ( (array) $arcresults as $arcresult ) {
990 if ( $arcresult->week != $arc_w_last ) {
991 $arc_year = $arcresult->yr;
992 $arc_w_last = $arcresult->week;
993 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
994 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
995 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
996 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
997 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
998 if ($show_post_count)
999 $after = ' ('.$arcresult->posts.')'.$afterafter;
1000 $output .= get_archives_link($url, $text, $format, $before, $after);
1004 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
1005 $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
1006 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1008 $cache = wp_cache_get( 'wp_get_archives' , 'general');
1009 if ( !isset( $cache[ $key ] ) ) {
1010 $arcresults = $wpdb->get_results($query);
1011 $cache[ $key ] = $arcresults;
1012 wp_cache_set( 'wp_get_archives', $cache, 'general' );
1014 $arcresults = $cache[ $key ];
1016 if ( $arcresults ) {
1017 foreach ( (array) $arcresults as $arcresult ) {
1018 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
1019 $url = get_permalink($arcresult);
1020 $arc_title = $arcresult->post_title;
1022 $text = strip_tags(apply_filters('the_title', $arc_title));
1024 $text = $arcresult->ID;
1025 $output .= get_archives_link($url, $text, $format, $before, $after);
1037 * Get number of days since the start of the week.
1040 * @usedby get_calendar()
1042 * @param int $num Number of day.
1043 * @return int Days since the start of the week.
1045 function calendar_week_mod($num) {
1047 return ($num - $base*floor($num/$base));
1051 * Display calendar with days that have posts as links.
1053 * The calendar is cached, which will be retrieved, if it exists. If there are
1054 * no posts for the month, then it will not be displayed.
1058 * @param bool $initial Optional, default is true. Use initial calendar names.
1059 * @param bool $echo Optional, default is true. Set to false for return.
1061 function get_calendar($initial = true, $echo = true) {
1062 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1065 $key = md5( $m . $monthnum . $year );
1066 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
1067 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
1069 echo apply_filters( 'get_calendar', $cache[$key] );
1072 return apply_filters( 'get_calendar', $cache[$key] );
1077 if ( !is_array($cache) )
1080 // Quick check. If we have no posts at all, abort!
1082 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1084 $cache[ $key ] = '';
1085 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1090 if ( isset($_GET['w']) )
1091 $w = ''.intval($_GET['w']);
1093 // week_begins = 0 stands for Sunday
1094 $week_begins = intval(get_option('start_of_week'));
1096 // Let's figure out when we are
1097 if ( !empty($monthnum) && !empty($year) ) {
1098 $thismonth = ''.zeroise(intval($monthnum), 2);
1099 $thisyear = ''.intval($year);
1100 } elseif ( !empty($w) ) {
1101 // We need to get the month from MySQL
1102 $thisyear = ''.intval(substr($m, 0, 4));
1103 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
1104 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
1105 } elseif ( !empty($m) ) {
1106 $thisyear = ''.intval(substr($m, 0, 4));
1107 if ( strlen($m) < 6 )
1110 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1112 $thisyear = gmdate('Y', current_time('timestamp'));
1113 $thismonth = gmdate('m', current_time('timestamp'));
1116 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1118 // Get the next and previous month and year with at least one post
1119 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1121 WHERE post_date < '$thisyear-$thismonth-01'
1122 AND post_type = 'post' AND post_status = 'publish'
1123 ORDER BY post_date DESC
1125 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1127 WHERE post_date > '$thisyear-$thismonth-01'
1128 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
1129 AND post_type = 'post' AND post_status = 'publish'
1130 ORDER BY post_date ASC
1133 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1134 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1135 $calendar_output = '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
1136 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1142 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1143 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1146 foreach ( $myweek as $wd ) {
1147 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1148 $wd = esc_attr($wd);
1149 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1152 $calendar_output .= '
1160 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . 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>';
1162 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1165 $calendar_output .= "\n\t\t".'<td class="pad"> </td>';
1168 $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>';
1170 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1173 $calendar_output .= '
1180 // Get days with posts
1181 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1182 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
1183 AND YEAR(post_date) = '$thisyear'
1184 AND post_type = 'post' AND post_status = 'publish'
1185 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1186 if ( $dayswithposts ) {
1187 foreach ( (array) $dayswithposts as $daywith ) {
1188 $daywithpost[] = $daywith[0];
1191 $daywithpost = array();
1194 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
1195 $ak_title_separator = "\n";
1197 $ak_title_separator = ', ';
1199 $ak_titles_for_day = array();
1200 $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
1201 ."FROM $wpdb->posts "
1202 ."WHERE YEAR(post_date) = '$thisyear' "
1203 ."AND MONTH(post_date) = '$thismonth' "
1204 ."AND post_date < '".current_time('mysql')."' "
1205 ."AND post_type = 'post' AND post_status = 'publish'"
1207 if ( $ak_post_titles ) {
1208 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1210 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
1212 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1213 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1214 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1215 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1217 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1222 // See how much we should pad in the beginning
1223 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1225 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';
1227 $daysinmonth = intval(date('t', $unixmonth));
1228 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1229 if ( isset($newrow) && $newrow )
1230 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1233 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
1234 $calendar_output .= '<td id="today">';
1236 $calendar_output .= '<td>';
1238 if ( in_array($day, $daywithpost) ) // any posts today?
1239 $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
1241 $calendar_output .= $day;
1242 $calendar_output .= '</td>';
1244 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1248 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1249 if ( $pad != 0 && $pad != 7 )
1250 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';
1252 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1254 $cache[ $key ] = $calendar_output;
1255 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1258 echo apply_filters( 'get_calendar', $calendar_output );
1260 return apply_filters( 'get_calendar', $calendar_output );
1265 * Purge the cached results of get_calendar.
1270 function delete_get_calendar_cache() {
1271 wp_cache_delete( 'get_calendar', 'calendar' );
1273 add_action( 'save_post', 'delete_get_calendar_cache' );
1274 add_action( 'delete_post', 'delete_get_calendar_cache' );
1275 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1276 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1279 * Display all of the allowed tags in HTML format with attributes.
1281 * This is useful for displaying in the comment area, which elements and
1282 * attributes are supported. As well as any plugins which want to display it.
1285 * @uses $allowedtags
1287 * @return string HTML allowed tags entity encoded.
1289 function allowed_tags() {
1290 global $allowedtags;
1292 foreach ( (array) $allowedtags as $tag => $attributes ) {
1293 $allowed .= '<'.$tag;
1294 if ( 0 < count($attributes) ) {
1295 foreach ( $attributes as $attribute => $limits ) {
1296 $allowed .= ' '.$attribute.'=""';
1301 return htmlentities($allowed);
1304 /***** Date/Time tags *****/
1307 * Outputs the date in iso8601 format for xml files.
1311 function the_date_xml() {
1313 echo mysql2date('Y-m-d', $post->post_date, false);
1317 * Display or Retrieve the date the current $post was written (once per date)
1319 * Will only output the date if the current post's date is different from the
1320 * previous one output.
1322 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
1323 * function is called several times for each post.
1325 * HTML output can be filtered with 'the_date'.
1326 * Date string output can be filtered with 'get_the_date'.
1329 * @uses get_the_date()
1330 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1331 * @param string $before Optional. Output before the date.
1332 * @param string $after Optional. Output after the date.
1333 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1334 * @return string|null Null if displaying, string if retrieving.
1336 function the_date( $d = '', $before = '', $after = '', $echo = true ) {
1337 global $day, $previousday;
1339 if ( $day != $previousday ) {
1340 $the_date .= $before;
1341 $the_date .= get_the_date( $d );
1342 $the_date .= $after;
1343 $previousday = $day;
1345 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
1357 * Retrieve the date the current $post was written.
1359 * Unlike the_date() this function will always return the date.
1360 * Modify output with 'get_the_date' filter.
1364 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1365 * @return string|null Null if displaying, string if retrieving.
1367 function get_the_date( $d = '' ) {
1372 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
1374 $the_date .= mysql2date($d, $post->post_date);
1376 return apply_filters('get_the_date', $the_date, $d);
1380 * Display the date on which the post was last modified.
1384 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1385 * @param string $before Optional. Output before the date.
1386 * @param string $after Optional. Output after the date.
1387 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1388 * @return string|null Null if displaying, string if retrieving.
1390 function the_modified_date($d = '', $before='', $after='', $echo = true) {
1392 $the_modified_date = $before . get_the_modified_date($d) . $after;
1393 $the_modified_date = apply_filters('the_modified_date', $the_modified_date, $d, $before, $after);
1396 echo $the_modified_date;
1398 return $the_modified_date;
1403 * Retrieve the date on which the post was last modified.
1407 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1410 function get_the_modified_date($d = '') {
1412 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1414 $the_time = get_post_modified_time($d, null, null, true);
1415 return apply_filters('get_the_modified_date', $the_time, $d);
1419 * Display the time at which the post was written.
1423 * @param string $d Either 'G', 'U', or php date format.
1425 function the_time( $d = '' ) {
1426 echo apply_filters('the_time', get_the_time( $d ), $d);
1430 * Retrieve the time at which the post was written.
1434 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1435 * @param int|object $post Optional post ID or object. Default is global $post object.
1438 function get_the_time( $d = '', $post = null ) {
1439 $post = get_post($post);
1442 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1444 $the_time = get_post_time($d, false, $post, true);
1445 return apply_filters('get_the_time', $the_time, $d, $post);
1449 * Retrieve the time at which the post was written.
1453 * @param string $d Optional Either 'G', 'U', or php date format.
1454 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
1455 * @param int|object $post Optional post ID or object. Default is global $post object.
1456 * @param bool $translate Whether to translate the time string
1459 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
1460 $post = get_post($post);
1463 $time = $post->post_date_gmt;
1465 $time = $post->post_date;
1467 $time = mysql2date($d, $time, $translate);
1468 return apply_filters('get_post_time', $time, $d, $gmt);
1472 * Display the time at which the post was last modified.
1476 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1478 function the_modified_time($d = '') {
1479 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
1483 * Retrieve the time at which the post was last modified.
1487 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1490 function get_the_modified_time($d = '') {
1492 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1494 $the_time = get_post_modified_time($d, null, null, true);
1495 return apply_filters('get_the_modified_time', $the_time, $d);
1499 * Retrieve the time at which the post was last modified.
1503 * @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
1504 * @param bool $gmt Optional, default is false. Whether to return the gmt time.
1505 * @param int|object $post Optional, default is global post object. A post_id or post object
1506 * @param bool $translate Optional, default is false. Whether to translate the result
1507 * @return string Returns timestamp
1509 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1510 $post = get_post($post);
1513 $time = $post->post_modified_gmt;
1515 $time = $post->post_modified;
1516 $time = mysql2date($d, $time, $translate);
1518 return apply_filters('get_post_modified_time', $time, $d, $gmt);
1522 * Display the weekday on which the post was written.
1528 function the_weekday() {
1529 global $wp_locale, $post;
1530 $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1531 $the_weekday = apply_filters('the_weekday', $the_weekday);
1536 * Display the weekday on which the post was written.
1538 * Will only output the weekday if the current post's weekday is different from
1539 * the previous one output.
1543 * @param string $before Optional Output before the date.
1544 * @param string $after Optional Output after the date.
1546 function the_weekday_date($before='',$after='') {
1547 global $wp_locale, $post, $day, $previousweekday;
1548 $the_weekday_date = '';
1549 if ( $day != $previousweekday ) {
1550 $the_weekday_date .= $before;
1551 $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1552 $the_weekday_date .= $after;
1553 $previousweekday = $day;
1555 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
1556 echo $the_weekday_date;
1560 * Fire the wp_head action
1563 * @uses do_action() Calls 'wp_head' hook.
1565 function wp_head() {
1566 do_action('wp_head');
1570 * Fire the wp_footer action
1573 * @uses do_action() Calls 'wp_footer' hook.
1575 function wp_footer() {
1576 do_action('wp_footer');
1580 * Display the links to the general feeds.
1584 * @param array $args Optional arguments.
1586 function feed_links( $args = array() ) {
1587 if ( !current_theme_supports('automatic-feed-links') )
1591 /* translators: Separator between blog name and feed type in feed links */
1592 'separator' => _x('»', 'feed link'),
1593 /* translators: 1: blog title, 2: separator (raquo) */
1594 'feedtitle' => __('%1$s %2$s Feed'),
1595 /* translators: %s: blog title, 2: separator (raquo) */
1596 'comstitle' => __('%1$s %2$s Comments Feed'),
1599 $args = wp_parse_args( $args, $defaults );
1601 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
1602 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
1606 * Display the links to the extra feeds such as category feeds.
1610 * @param array $args Optional arguments.
1612 function feed_links_extra( $args = array() ) {
1614 /* translators: Separator between blog name and feed type in feed links */
1615 'separator' => _x('»', 'feed link'),
1616 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
1617 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
1618 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
1619 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
1620 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
1621 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
1622 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
1623 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
1624 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
1625 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
1628 $args = wp_parse_args( $args, $defaults );
1630 if ( is_single() || is_page() ) {
1631 $post = &get_post( $id = 0 );
1633 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
1634 $title = esc_attr(sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) ));
1635 $href = get_post_comments_feed_link( $post->ID );
1637 } elseif ( is_category() ) {
1638 $cat_id = intval( get_query_var('cat') );
1640 $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], get_cat_name( $cat_id ) ));
1641 $href = get_category_feed_link( $cat_id );
1642 } elseif ( is_tag() ) {
1643 $tag_id = intval( get_query_var('tag_id') );
1644 $tag = get_tag( $tag_id );
1646 $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $tag->name ));
1647 $href = get_tag_feed_link( $tag_id );
1648 } elseif ( is_author() ) {
1649 $author_id = intval( get_query_var('author') );
1651 $title = esc_attr(sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ));
1652 $href = get_author_feed_link( $author_id );
1653 } elseif ( is_search() ) {
1654 $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) ));
1655 $href = get_search_feed_link();
1658 if ( isset($title) && isset($href) )
1659 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . '" />' . "\n";
1663 * Display the link to the Really Simple Discovery service endpoint.
1665 * @link http://archipelago.phrasewise.com/rsd
1668 function rsd_link() {
1669 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
1673 * Display the link to the Windows Live Writer manifest file.
1675 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
1678 function wlwmanifest_link() {
1679 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
1680 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
1684 * Display a noindex meta tag if required by the blog configuration.
1686 * If a blog is marked as not being public then the noindex meta tag will be
1687 * output to tell web robots not to index the page content.
1691 function noindex() {
1692 // If the blog is not public, tell robots to go away.
1693 if ( '0' == get_option('blog_public') )
1694 echo "<meta name='robots' content='noindex,nofollow' />\n";
1698 * Determine if TinyMCE is available.
1700 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
1704 * @return bool Whether TinyMCE exists.
1706 function rich_edit_exists() {
1707 global $wp_rich_edit_exists;
1708 if ( !isset($wp_rich_edit_exists) )
1709 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
1710 return $wp_rich_edit_exists;
1714 * Whether the user should have a WYSIWIG editor.
1716 * Checks that the user requires a WYSIWIG editor and that the editor is
1717 * supported in the users browser.
1723 function user_can_richedit() {
1724 global $wp_rich_edit, $pagenow, $is_iphone;
1726 if ( !isset( $wp_rich_edit) ) {
1727 if ( get_user_option( 'rich_editing' ) == 'true' &&
1728 !$is_iphone && // this includes all Safari mobile browsers
1729 ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
1730 !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
1731 && 'comment.php' != $pagenow ) {
1732 $wp_rich_edit = true;
1734 $wp_rich_edit = false;
1738 return apply_filters('user_can_richedit', $wp_rich_edit);
1742 * Find out which editor should be displayed by default.
1744 * Works out which of the two editors to display as the current editor for a
1749 * @return string Either 'tinymce', or 'html', or 'test'
1751 function wp_default_editor() {
1752 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
1753 if ( $user = wp_get_current_user() ) { // look for cookie
1754 $ed = get_user_setting('editor', 'tinymce');
1755 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
1757 return apply_filters( 'wp_default_editor', $r ); // filter
1761 * Display visual editor forms: TinyMCE, or HTML, or both.
1763 * The amount of rows the text area will have for the content has to be between
1764 * 3 and 100 or will default at 12. There is only one option used for all users,
1765 * named 'default_post_edit_rows'.
1767 * If the user can not use the rich editor (TinyMCE), then the switch button
1768 * will not be displayed.
1772 * @param string $content Textarea content.
1773 * @param string $id Optional, default is 'content'. HTML ID attribute value.
1774 * @param string $prev_id Optional, default is 'title'. HTML ID name for switching back and forth between visual editors.
1775 * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
1776 * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
1778 function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
1779 $rows = get_option('default_post_edit_rows');
1780 if (($rows < 3) || ($rows > 100))
1783 if ( !current_user_can( 'upload_files' ) )
1784 $media_buttons = false;
1786 $richedit = user_can_richedit();
1789 if ( $richedit || $media_buttons ) { ?>
1790 <div id="editor-toolbar">
1793 $wp_default_editor = wp_default_editor(); ?>
1794 <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
1795 <?php if ( 'html' == $wp_default_editor ) {
1796 add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
1797 <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1798 <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1800 $class = " class='theEditor'";
1801 add_filter('the_editor_content', 'wp_richedit_pre'); ?>
1802 <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1803 <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1807 if ( $media_buttons ) { ?>
1808 <div id="media-buttons" class="hide-if-no-js">
1809 <?php do_action( 'media_buttons' ); ?>
1817 <div id="quicktags"><?php
1818 wp_print_scripts( 'quicktags' ); ?>
1819 <script type="text/javascript">edToolbar()</script>
1823 $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
1824 $the_editor_content = apply_filters('the_editor_content', $content);
1826 printf($the_editor, $the_editor_content);
1829 <script type="text/javascript">
1830 edCanvas = document.getElementById('<?php echo $id; ?>');
1836 * Retrieve the contents of the search WordPress query variable.
1838 * The search query string is passed through {@link esc_attr()}
1839 * to ensure that it is safe for placing in an html attribute.
1844 * @param bool $escaped Whether the result is escaped. Default true.
1845 * Only use when you are later escaping it. Do not use unescaped.
1848 function get_search_query( $escaped = true ) {
1849 $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
1851 $query = esc_attr( $query );
1856 * Display the contents of the search query variable.
1858 * The search query string is passed through {@link esc_attr()}
1859 * to ensure that it is safe for placing in an html attribute.
1864 function the_search_query() {
1865 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
1869 * Display the language attributes for the html tag.
1871 * Builds up a set of html attributes containing the text direction and language
1872 * information for the page.
1876 * @param string $doctype The type of html document (xhtml|html).
1878 function language_attributes($doctype = 'html') {
1879 $attributes = array();
1882 if ( function_exists( 'is_rtl' ) )
1883 $attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"';
1885 if ( $lang = get_bloginfo('language') ) {
1886 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
1887 $attributes[] = "lang=\"$lang\"";
1889 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1890 $attributes[] = "xml:lang=\"$lang\"";
1893 $output = implode(' ', $attributes);
1894 $output = apply_filters('language_attributes', $output);
1899 * Retrieve paginated link for archive post pages.
1901 * Technically, the function can be used to create paginated link list for any
1902 * area. The 'base' argument is used to reference the url, which will be used to
1903 * create the paginated links. The 'format' argument is then used for replacing
1904 * the page number. It is however, most likely and by default, to be used on the
1905 * archive post pages.
1907 * The 'type' argument controls format of the returned value. The default is
1908 * 'plain', which is just a string with the links separated by a newline
1909 * character. The other possible values are either 'array' or 'list'. The
1910 * 'array' value will return an array of the paginated link list to offer full
1911 * control of display. The 'list' value will place all of the paginated links in
1912 * an unordered HTML list.
1914 * The 'total' argument is the total amount of pages and is an integer. The
1915 * 'current' argument is the current page number and is also an integer.
1917 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
1918 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
1919 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
1920 * and the '%#%' is also required. The '%#%' will be replaced with the page
1923 * You can include the previous and next links in the list by setting the
1924 * 'prev_next' argument to true, which it is by default. You can set the
1925 * previous text, by using the 'prev_text' argument. You can set the next text
1926 * by setting the 'next_text' argument.
1928 * If the 'show_all' argument is set to true, then it will show all of the pages
1929 * instead of a short list of the pages near the current page. By default, the
1930 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
1931 * arguments. The 'end_size' argument is how many numbers on either the start
1932 * and the end list edges, by default is 1. The 'mid_size' argument is how many
1933 * numbers to either side of current page, but not including current page.
1935 * It is possible to add query vars to the link by using the 'add_args' argument
1936 * and see {@link add_query_arg()} for more information.
1940 * @param string|array $args Optional. Override defaults.
1941 * @return array|string String of page links or array of page links.
1943 function paginate_links( $args = '' ) {
1945 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1946 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1949 'show_all' => false,
1950 'prev_next' => true,
1951 'prev_text' => __('« Previous'),
1952 'next_text' => __('Next »'),
1956 'add_args' => false, // array of query args to add
1957 'add_fragment' => ''
1960 $args = wp_parse_args( $args, $defaults );
1961 extract($args, EXTR_SKIP);
1963 // Who knows what else people pass in $args
1964 $total = (int) $total;
1967 $current = (int) $current;
1968 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
1969 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
1970 $add_args = is_array($add_args) ? $add_args : false;
1972 $page_links = array();
1976 if ( $prev_next && $current && 1 < $current ) :
1977 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
1978 $link = str_replace('%#%', $current - 1, $link);
1980 $link = add_query_arg( $add_args, $link );
1981 $link .= $add_fragment;
1982 $page_links[] = "<a class='prev page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$prev_text</a>";
1984 for ( $n = 1; $n <= $total; $n++ ) :
1985 $n_display = number_format_i18n($n);
1986 if ( $n == $current ) :
1987 $page_links[] = "<span class='page-numbers current'>$n_display</span>";
1990 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
1991 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
1992 $link = str_replace('%#%', $n, $link);
1994 $link = add_query_arg( $add_args, $link );
1995 $link .= $add_fragment;
1996 $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";
1998 elseif ( $dots && !$show_all ) :
1999 $page_links[] = "<span class='page-numbers dots'>...</span>";
2004 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
2005 $link = str_replace('%_%', $format, $base);
2006 $link = str_replace('%#%', $current + 1, $link);
2008 $link = add_query_arg( $add_args, $link );
2009 $link .= $add_fragment;
2010 $page_links[] = "<a class='next page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$next_text</a>";
2017 $r .= "<ul class='page-numbers'>\n\t<li>";
2018 $r .= join("</li>\n\t<li>", $page_links);
2019 $r .= "</li>\n</ul>\n";
2022 $r = join("\n", $page_links);
2029 * Registers an admin colour scheme css file.
2031 * Allows a plugin to register a new admin colour scheme. For example:
2033 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
2034 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
2039 * @param string $key The unique key for this theme.
2040 * @param string $name The name of the theme.
2041 * @param string $url The url of the css file containing the colour scheme.
2042 * @param array @colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
2044 function wp_admin_css_color($key, $name, $url, $colors = array()) {
2045 global $_wp_admin_css_colors;
2047 if ( !isset($_wp_admin_css_colors) )
2048 $_wp_admin_css_colors = array();
2050 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
2054 * Registers the default Admin color schemes
2058 function register_admin_color_schemes() {
2059 wp_admin_css_color('classic', __('Blue'), admin_url("css/colors-classic.css"), array('#073447', '#21759B', '#EAF3FA', '#BBD8E7'));
2060 wp_admin_css_color('fresh', __('Gray'), admin_url("css/colors-fresh.css"), array('#464646', '#6D6D6D', '#F1F1F1', '#DFDFDF'));}
2063 * Display the URL of a WordPress admin CSS file.
2065 * @see WP_Styles::_css_href and its style_loader_src filter.
2069 * @param string $file file relative to wp-admin/ without its ".css" extension.
2071 function wp_admin_css_uri( $file = 'wp-admin' ) {
2072 if ( defined('WP_INSTALLING') ) {
2073 $_file = "./$file.css";
2075 $_file = admin_url("$file.css");
2077 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
2079 return apply_filters( 'wp_admin_css_uri', $_file, $file );
2083 * Enqueues or directly prints a stylesheet link to the specified CSS file.
2085 * "Intelligently" decides to enqueue or to print the CSS file. If the
2086 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
2087 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
2088 * be printed. Printing may be forced by passing TRUE as the $force_echo
2089 * (second) parameter.
2091 * For backward compatibility with WordPress 2.3 calling method: If the $file
2092 * (first) parameter does not correspond to a registered CSS file, we assume
2093 * $file is a file relative to wp-admin/ without its ".css" extension. A
2094 * stylesheet link to that generated URL is printed.
2096 * @package WordPress
2098 * @uses $wp_styles WordPress Styles Object
2100 * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
2101 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
2103 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
2105 if ( !is_a($wp_styles, 'WP_Styles') )
2106 $wp_styles = new WP_Styles();
2108 // For backward compatibility
2109 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
2111 if ( $wp_styles->query( $handle ) ) {
2112 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
2113 wp_print_styles( $handle );
2114 else // Add to style queue
2115 wp_enqueue_style( $handle );
2119 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
2121 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
2125 * Enqueues the default ThickBox js and css.
2127 * If any of the settings need to be changed, this can be done with another js
2128 * file similar to media-upload.js and theme-preview.js. That file should
2129 * require array('thickbox') to ensure it is loaded after.
2133 function add_thickbox() {
2134 wp_enqueue_script( 'thickbox' );
2135 wp_enqueue_style( 'thickbox' );
2139 * Display the XHTML generator that is generated on the wp_head hook.
2143 function wp_generator() {
2144 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
2148 * Display the generator XML or Comment for RSS, ATOM, etc.
2150 * Returns the correct generator type for the requested output format. Allows
2151 * for a plugin to filter generators overall the the_generator filter.
2154 * @uses apply_filters() Calls 'the_generator' hook.
2156 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2158 function the_generator( $type ) {
2159 echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
2163 * Creates the generator XML or Comment for RSS, ATOM, etc.
2165 * Returns the correct generator type for the requested output format. Allows
2166 * for a plugin to filter generators on an individual basis using the
2167 * 'get_the_generator_{$type}' filter.
2170 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
2172 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2173 * @return string The HTML content for the generator.
2175 function get_the_generator( $type = '' ) {
2176 if ( empty( $type ) ) {
2178 $current_filter = current_filter();
2179 if ( empty( $current_filter ) )
2182 switch ( $current_filter ) {
2184 case 'commentsrss2_head' :
2195 case 'comments_atom_head' :
2204 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2207 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2210 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2213 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2216 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2219 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2222 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
2225 return apply_filters( "get_the_generator_{$type}", $gen, $type );
2229 * Outputs the html checked attribute.
2231 * Compares the first two arguments and if identical marks as checked
2235 * @param mixed $checked One of the values to compare
2236 * @param mixed $current (true) The other value to compare if not just true
2237 * @param bool $echo Whether to echo or just return the string
2238 * @return string html attribute or empty string
2240 function checked( $checked, $current = true, $echo = true ) {
2241 return __checked_selected_helper( $checked, $current, $echo, 'checked' );
2245 * Outputs the html selected attribute.
2247 * Compares the first two arguments and if identical marks as selected
2251 * @param mixed selected One of the values to compare
2252 * @param mixed $current (true) The other value to compare if not just true
2253 * @param bool $echo Whether to echo or just return the string
2254 * @return string html attribute or empty string
2256 function selected( $selected, $current = true, $echo = true ) {
2257 return __checked_selected_helper( $selected, $current, $echo, 'selected' );
2261 * Outputs the html disabled attribute.
2263 * Compares the first two arguments and if identical marks as disabled
2267 * @param mixed $disabled One of the values to compare
2268 * @param mixed $current (true) The other value to compare if not just true
2269 * @param bool $echo Whether to echo or just return the string
2270 * @return string html attribute or empty string
2272 function disabled( $disabled, $current = true, $echo = true ) {
2273 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
2277 * Private helper function for checked, selected, and disabled.
2279 * Compares the first two arguments and if identical marks as $type
2284 * @param any $helper One of the values to compare
2285 * @param any $current (true) The other value to compare if not just true
2286 * @param bool $echo Whether to echo or just return the string
2287 * @param string $type The type of checked|selected|disabled we are doing
2288 * @return string html attribute or empty string
2290 function __checked_selected_helper( $helper, $current, $echo, $type ) {
2291 if ( (string) $helper === (string) $current )
2292 $result = " $type='$type'";