]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/post-template.php
Wordpress 3.5.2
[autoinstalls/wordpress.git] / wp-includes / post-template.php
1 <?php
2 /**
3  * WordPress Post Template Functions.
4  *
5  * Gets content for the current post in the loop.
6  *
7  * @package WordPress
8  * @subpackage Template
9  */
10
11 /**
12  * Display the ID of the current item in the WordPress Loop.
13  *
14  * @since 0.71
15  */
16 function the_ID() {
17         echo get_the_ID();
18 }
19
20 /**
21  * Retrieve the ID of the current item in the WordPress Loop.
22  *
23  * @since 2.1.0
24  * @uses $post
25  *
26  * @return int
27  */
28 function get_the_ID() {
29         return get_post()->ID;
30 }
31
32 /**
33  * Display or retrieve the current post title with optional content.
34  *
35  * @since 0.71
36  *
37  * @param string $before Optional. Content to prepend to the title.
38  * @param string $after Optional. Content to append to the title.
39  * @param bool $echo Optional, default to true.Whether to display or return.
40  * @return null|string Null on no title. String if $echo parameter is false.
41  */
42 function the_title($before = '', $after = '', $echo = true) {
43         $title = get_the_title();
44
45         if ( strlen($title) == 0 )
46                 return;
47
48         $title = $before . $title . $after;
49
50         if ( $echo )
51                 echo $title;
52         else
53                 return $title;
54 }
55
56 /**
57  * Sanitize the current title when retrieving or displaying.
58  *
59  * Works like {@link the_title()}, except the parameters can be in a string or
60  * an array. See the function for what can be override in the $args parameter.
61  *
62  * The title before it is displayed will have the tags stripped and {@link
63  * esc_attr()} before it is passed to the user or displayed. The default
64  * as with {@link the_title()}, is to display the title.
65  *
66  * @since 2.3.0
67  *
68  * @param string|array $args Optional. Override the defaults.
69  * @return string|null Null on failure or display. String when echo is false.
70  */
71 function the_title_attribute( $args = '' ) {
72         $title = get_the_title();
73
74         if ( strlen($title) == 0 )
75                 return;
76
77         $defaults = array('before' => '', 'after' =>  '', 'echo' => true);
78         $r = wp_parse_args($args, $defaults);
79         extract( $r, EXTR_SKIP );
80
81         $title = $before . $title . $after;
82         $title = esc_attr(strip_tags($title));
83
84         if ( $echo )
85                 echo $title;
86         else
87                 return $title;
88 }
89
90 /**
91  * Retrieve post title.
92  *
93  * If the post is protected and the visitor is not an admin, then "Protected"
94  * will be displayed before the post title. If the post is private, then
95  * "Private" will be located before the post title.
96  *
97  * @since 0.71
98  *
99  * @param mixed $post Optional. Post ID or object.
100  * @return string
101  */
102 function get_the_title( $post = 0 ) {
103         $post = get_post( $post );
104
105         $title = isset( $post->post_title ) ? $post->post_title : '';
106         $id = isset( $post->ID ) ? $post->ID : 0;
107
108         if ( ! is_admin() ) {
109                 if ( ! empty( $post->post_password ) ) {
110                         $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) );
111                         $title = sprintf( $protected_title_format, $title );
112                 } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) {
113                         $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) );
114                         $title = sprintf( $private_title_format, $title );
115                 }
116         }
117
118         return apply_filters( 'the_title', $title, $id );
119 }
120
121 /**
122  * Display the Post Global Unique Identifier (guid).
123  *
124  * The guid will appear to be a link, but should not be used as an link to the
125  * post. The reason you should not use it as a link, is because of moving the
126  * blog across domains.
127  *
128  * Url is escaped to make it xml safe
129  *
130  * @since 1.5.0
131  *
132  * @param int $id Optional. Post ID.
133  */
134 function the_guid( $id = 0 ) {
135         echo esc_url( get_the_guid( $id ) );
136 }
137
138 /**
139  * Retrieve the Post Global Unique Identifier (guid).
140  *
141  * The guid will appear to be a link, but should not be used as an link to the
142  * post. The reason you should not use it as a link, is because of moving the
143  * blog across domains.
144  *
145  * @since 1.5.0
146  *
147  * @param int $id Optional. Post ID.
148  * @return string
149  */
150 function get_the_guid( $id = 0 ) {
151         $post = get_post($id);
152
153         return apply_filters('get_the_guid', $post->guid);
154 }
155
156 /**
157  * Display the post content.
158  *
159  * @since 0.71
160  *
161  * @param string $more_link_text Optional. Content for when there is more text.
162  * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
163  */
164 function the_content($more_link_text = null, $stripteaser = false) {
165         $content = get_the_content($more_link_text, $stripteaser);
166         $content = apply_filters('the_content', $content);
167         $content = str_replace(']]>', ']]&gt;', $content);
168         echo $content;
169 }
170
171 /**
172  * Retrieve the post content.
173  *
174  * @since 0.71
175  *
176  * @param string $more_link_text Optional. Content for when there is more text.
177  * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
178  * @return string
179  */
180 function get_the_content( $more_link_text = null, $stripteaser = false ) {
181         global $more, $page, $pages, $multipage, $preview;
182
183         $post = get_post();
184
185         if ( null === $more_link_text )
186                 $more_link_text = __( '(more...)' );
187
188         $output = '';
189         $hasTeaser = false;
190
191         // If post password required and it doesn't match the cookie.
192         if ( post_password_required() )
193                 return get_the_password_form();
194
195         if ( $page > count($pages) ) // if the requested page doesn't exist
196                 $page = count($pages); // give them the highest numbered page that DOES exist
197
198         $content = $pages[$page-1];
199         if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
200                 $content = explode($matches[0], $content, 2);
201                 if ( !empty($matches[1]) && !empty($more_link_text) )
202                         $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
203
204                 $hasTeaser = true;
205         } else {
206                 $content = array($content);
207         }
208         if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
209                 $stripteaser = true;
210         $teaser = $content[0];
211         if ( $more && $stripteaser && $hasTeaser )
212                 $teaser = '';
213         $output .= $teaser;
214         if ( count($content) > 1 ) {
215                 if ( $more ) {
216                         $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
217                 } else {
218                         if ( ! empty($more_link_text) )
219                                 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
220                         $output = force_balance_tags($output);
221                 }
222
223         }
224         if ( $preview ) // preview fix for javascript bug with foreign languages
225                 $output =       preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
226
227         return $output;
228 }
229
230 /**
231  * Preview fix for javascript bug with foreign languages
232  *
233  * @since 3.1.0
234  * @access private
235  * @param array $match Match array from preg_replace_callback
236  * @return string
237  */
238 function _convert_urlencoded_to_entities( $match ) {
239         return '&#' . base_convert( $match[1], 16, 10 ) . ';';
240 }
241
242 /**
243  * Display the post excerpt.
244  *
245  * @since 0.71
246  * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
247  */
248 function the_excerpt() {
249         echo apply_filters('the_excerpt', get_the_excerpt());
250 }
251
252 /**
253  * Retrieve the post excerpt.
254  *
255  * @since 0.71
256  *
257  * @param mixed $deprecated Not used.
258  * @return string
259  */
260 function get_the_excerpt( $deprecated = '' ) {
261         if ( !empty( $deprecated ) )
262                 _deprecated_argument( __FUNCTION__, '2.3' );
263
264         $post = get_post();
265
266         if ( post_password_required() ) {
267                 return __( 'There is no excerpt because this is a protected post.' );
268         }
269
270         return apply_filters( 'get_the_excerpt', $post->post_excerpt );
271 }
272
273 /**
274  * Whether post has excerpt.
275  *
276  * @since 2.3.0
277  *
278  * @param int $id Optional. Post ID.
279  * @return bool
280  */
281 function has_excerpt( $id = 0 ) {
282         $post = get_post( $id );
283         return ( !empty( $post->post_excerpt ) );
284 }
285
286 /**
287  * Display the classes for the post div.
288  *
289  * @since 2.7.0
290  *
291  * @param string|array $class One or more classes to add to the class list.
292  * @param int $post_id An optional post ID.
293  */
294 function post_class( $class = '', $post_id = null ) {
295         // Separates classes with a single space, collates classes for post DIV
296         echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
297 }
298
299 /**
300  * Retrieve the classes for the post div as an array.
301  *
302  * The class names are add are many. If the post is a sticky, then the 'sticky'
303  * class name. The class 'hentry' is always added to each post. For each
304  * category, the class will be added with 'category-' with category slug is
305  * added. The tags are the same way as the categories with 'tag-' before the tag
306  * slug. All classes are passed through the filter, 'post_class' with the list
307  * of classes, followed by $class parameter value, with the post ID as the last
308  * parameter.
309  *
310  * @since 2.7.0
311  *
312  * @param string|array $class One or more classes to add to the class list.
313  * @param int $post_id An optional post ID.
314  * @return array Array of classes.
315  */
316 function get_post_class( $class = '', $post_id = null ) {
317         $post = get_post($post_id);
318
319         $classes = array();
320
321         if ( empty($post) )
322                 return $classes;
323
324         $classes[] = 'post-' . $post->ID;
325         if ( ! is_admin() )
326                 $classes[] = $post->post_type;
327         $classes[] = 'type-' . $post->post_type;
328         $classes[] = 'status-' . $post->post_status;
329
330         // Post Format
331         if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
332                 $post_format = get_post_format( $post->ID );
333
334                 if ( $post_format && !is_wp_error($post_format) )
335                         $classes[] = 'format-' . sanitize_html_class( $post_format );
336                 else
337                         $classes[] = 'format-standard';
338         }
339
340         // post requires password
341         if ( post_password_required($post->ID) )
342                 $classes[] = 'post-password-required';
343
344         // sticky for Sticky Posts
345         if ( is_sticky($post->ID) && is_home() && !is_paged() )
346                 $classes[] = 'sticky';
347
348         // hentry for hAtom compliance
349         $classes[] = 'hentry';
350
351         // Categories
352         if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
353                 foreach ( (array) get_the_category($post->ID) as $cat ) {
354                         if ( empty($cat->slug ) )
355                                 continue;
356                         $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
357                 }
358         }
359
360         // Tags
361         if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
362                 foreach ( (array) get_the_tags($post->ID) as $tag ) {
363                         if ( empty($tag->slug ) )
364                                 continue;
365                         $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
366                 }
367         }
368
369         if ( !empty($class) ) {
370                 if ( !is_array( $class ) )
371                         $class = preg_split('#\s+#', $class);
372                 $classes = array_merge($classes, $class);
373         }
374
375         $classes = array_map('esc_attr', $classes);
376
377         return apply_filters('post_class', $classes, $class, $post->ID);
378 }
379
380 /**
381  * Display the classes for the body element.
382  *
383  * @since 2.8.0
384  *
385  * @param string|array $class One or more classes to add to the class list.
386  */
387 function body_class( $class = '' ) {
388         // Separates classes with a single space, collates classes for body element
389         echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
390 }
391
392 /**
393  * Retrieve the classes for the body element as an array.
394  *
395  * @since 2.8.0
396  *
397  * @param string|array $class One or more classes to add to the class list.
398  * @return array Array of classes.
399  */
400 function get_body_class( $class = '' ) {
401         global $wp_query, $wpdb;
402
403         $classes = array();
404
405         if ( is_rtl() )
406                 $classes[] = 'rtl';
407
408         if ( is_front_page() )
409                 $classes[] = 'home';
410         if ( is_home() )
411                 $classes[] = 'blog';
412         if ( is_archive() )
413                 $classes[] = 'archive';
414         if ( is_date() )
415                 $classes[] = 'date';
416         if ( is_search() ) {
417                 $classes[] = 'search';
418                 $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
419         }
420         if ( is_paged() )
421                 $classes[] = 'paged';
422         if ( is_attachment() )
423                 $classes[] = 'attachment';
424         if ( is_404() )
425                 $classes[] = 'error404';
426
427         if ( is_single() ) {
428                 $post_id = $wp_query->get_queried_object_id();
429                 $post = $wp_query->get_queried_object();
430
431                 $classes[] = 'single';
432                 if ( isset( $post->post_type ) ) {
433                         $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
434                         $classes[] = 'postid-' . $post_id;
435
436                         // Post Format
437                         if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
438                                 $post_format = get_post_format( $post->ID );
439
440                                 if ( $post_format && !is_wp_error($post_format) )
441                                         $classes[] = 'single-format-' . sanitize_html_class( $post_format );
442                                 else
443                                         $classes[] = 'single-format-standard';
444                         }
445                 }
446
447                 if ( is_attachment() ) {
448                         $mime_type = get_post_mime_type($post_id);
449                         $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
450                         $classes[] = 'attachmentid-' . $post_id;
451                         $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
452                 }
453         } elseif ( is_archive() ) {
454                 if ( is_post_type_archive() ) {
455                         $classes[] = 'post-type-archive';
456                         $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );
457                 } else if ( is_author() ) {
458                         $author = $wp_query->get_queried_object();
459                         $classes[] = 'author';
460                         if ( isset( $author->user_nicename ) ) {
461                                 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
462                                 $classes[] = 'author-' . $author->ID;
463                         }
464                 } elseif ( is_category() ) {
465                         $cat = $wp_query->get_queried_object();
466                         $classes[] = 'category';
467                         if ( isset( $cat->term_id ) ) {
468                                 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
469                                 $classes[] = 'category-' . $cat->term_id;
470                         }
471                 } elseif ( is_tag() ) {
472                         $tags = $wp_query->get_queried_object();
473                         $classes[] = 'tag';
474                         if ( isset( $tags->term_id ) ) {
475                                 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
476                                 $classes[] = 'tag-' . $tags->term_id;
477                         }
478                 } elseif ( is_tax() ) {
479                         $term = $wp_query->get_queried_object();
480                         if ( isset( $term->term_id ) ) {
481                                 $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
482                                 $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
483                                 $classes[] = 'term-' . $term->term_id;
484                         }
485                 }
486         } elseif ( is_page() ) {
487                 $classes[] = 'page';
488
489                 $page_id = $wp_query->get_queried_object_id();
490
491                 $post = get_post($page_id);
492
493                 $classes[] = 'page-id-' . $page_id;
494
495                 if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) )
496                         $classes[] = 'page-parent';
497
498                 if ( $post->post_parent ) {
499                         $classes[] = 'page-child';
500                         $classes[] = 'parent-pageid-' . $post->post_parent;
501                 }
502                 if ( is_page_template() ) {
503                         $classes[] = 'page-template';
504                         $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) );
505                 } else {
506                         $classes[] = 'page-template-default';
507                 }
508         }
509
510         if ( is_user_logged_in() )
511                 $classes[] = 'logged-in';
512
513         if ( is_admin_bar_showing() ) {
514                 $classes[] = 'admin-bar';
515                 $classes[] = 'no-customize-support';
516         }
517
518         if ( get_theme_mod( 'background_color' ) || get_background_image() )
519                 $classes[] = 'custom-background';
520
521         $page = $wp_query->get( 'page' );
522
523         if ( !$page || $page < 2)
524                 $page = $wp_query->get( 'paged' );
525
526         if ( $page && $page > 1 ) {
527                 $classes[] = 'paged-' . $page;
528
529                 if ( is_single() )
530                         $classes[] = 'single-paged-' . $page;
531                 elseif ( is_page() )
532                         $classes[] = 'page-paged-' . $page;
533                 elseif ( is_category() )
534                         $classes[] = 'category-paged-' . $page;
535                 elseif ( is_tag() )
536                         $classes[] = 'tag-paged-' . $page;
537                 elseif ( is_date() )
538                         $classes[] = 'date-paged-' . $page;
539                 elseif ( is_author() )
540                         $classes[] = 'author-paged-' . $page;
541                 elseif ( is_search() )
542                         $classes[] = 'search-paged-' . $page;
543                 elseif ( is_post_type_archive() )
544                         $classes[] = 'post-type-paged-' . $page;
545         }
546
547         if ( ! empty( $class ) ) {
548                 if ( !is_array( $class ) )
549                         $class = preg_split( '#\s+#', $class );
550                 $classes = array_merge( $classes, $class );
551         } else {
552                 // Ensure that we always coerce class to being an array.
553                 $class = array();
554         }
555
556         $classes = array_map( 'esc_attr', $classes );
557
558         return apply_filters( 'body_class', $classes, $class );
559 }
560
561 /**
562  * Whether post requires password and correct password has been provided.
563  *
564  * @since 2.7.0
565  *
566  * @param int|object $post An optional post. Global $post used if not provided.
567  * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
568  */
569 function post_password_required( $post = null ) {
570         $post = get_post($post);
571
572         if ( empty( $post->post_password ) )
573                 return false;
574
575         if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
576                 return true;
577
578         require_once ABSPATH . 'wp-includes/class-phpass.php';
579         $hasher = new PasswordHash( 8, true );
580
581         $hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
582         if ( 0 !== strpos( $hash, '$P$B' ) )
583                 return true;
584
585         return ! $hasher->CheckPassword( $post->post_password, $hash );
586 }
587
588 /**
589  * Page Template Functions for usage in Themes
590  *
591  * @package WordPress
592  * @subpackage Template
593  */
594
595 /**
596  * The formatted output of a list of pages.
597  *
598  * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
599  * Quicktag one or more times). This tag must be within The Loop.
600  *
601  * The defaults for overwriting are:
602  * 'next_or_number' - Default is 'number' (string). Indicates whether page
603  *      numbers should be used. Valid values are number and next.
604  * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
605  *      of the bookmark.
606  * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
607  *      previous page, if available.
608  * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
609  *      the parameter string will be replaced with the page number, so Page %
610  *      generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
611  * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
612  *      each bookmarks.
613  * 'after' - Default is '</p>' (string). The html or text to append to each
614  *      bookmarks.
615  * 'link_before' - Default is '' (string). The html or text to prepend to each
616  *      Pages link inside the <a> tag. Also prepended to the current item, which
617  *      is not linked.
618  * 'link_after' - Default is '' (string). The html or text to append to each
619  *      Pages link inside the <a> tag. Also appended to the current item, which
620  *      is not linked.
621  *
622  * @since 1.2.0
623  * @access private
624  *
625  * @param string|array $args Optional. Overwrite the defaults.
626  * @return string Formatted output in HTML.
627  */
628 function wp_link_pages($args = '') {
629         $defaults = array(
630                 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
631                 'link_before' => '', 'link_after' => '',
632                 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
633                 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
634                 'echo' => 1
635         );
636
637         $r = wp_parse_args( $args, $defaults );
638         $r = apply_filters( 'wp_link_pages_args', $r );
639         extract( $r, EXTR_SKIP );
640
641         global $page, $numpages, $multipage, $more, $pagenow;
642
643         $output = '';
644         if ( $multipage ) {
645                 if ( 'number' == $next_or_number ) {
646                         $output .= $before;
647                         for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
648                                 $j = str_replace('%',$i,$pagelink);
649                                 $output .= ' ';
650                                 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
651                                         $output .= _wp_link_page($i);
652                                 }
653                                 $output .= $link_before . $j . $link_after;
654                                 if ( ($i != $page) || ((!$more) && ($page==1)) )
655                                         $output .= '</a>';
656                         }
657                         $output .= $after;
658                 } else {
659                         if ( $more ) {
660                                 $output .= $before;
661                                 $i = $page - 1;
662                                 if ( $i && $more ) {
663                                         $output .= _wp_link_page($i);
664                                         $output .= $link_before. $previouspagelink . $link_after . '</a>';
665                                 }
666                                 $i = $page + 1;
667                                 if ( $i <= $numpages && $more ) {
668                                         $output .= _wp_link_page($i);
669                                         $output .= $link_before. $nextpagelink . $link_after . '</a>';
670                                 }
671                                 $output .= $after;
672                         }
673                 }
674         }
675
676         if ( $echo )
677                 echo $output;
678
679         return $output;
680 }
681
682 /**
683  * Helper function for wp_link_pages().
684  *
685  * @since 3.1.0
686  * @access private
687  *
688  * @param int $i Page number.
689  * @return string Link.
690  */
691 function _wp_link_page( $i ) {
692         global $wp_rewrite;
693         $post = get_post();
694
695         if ( 1 == $i ) {
696                 $url = get_permalink();
697         } else {
698                 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
699                         $url = add_query_arg( 'page', $i, get_permalink() );
700                 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
701                         $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
702                 else
703                         $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
704         }
705
706         return '<a href="' . esc_url( $url ) . '">';
707 }
708
709 //
710 // Post-meta: Custom per-post fields.
711 //
712
713 /**
714  * Retrieve post custom meta data field.
715  *
716  * @since 1.5.0
717  *
718  * @param string $key Meta data key name.
719  * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
720  */
721 function post_custom( $key = '' ) {
722         $custom = get_post_custom();
723
724         if ( !isset( $custom[$key] ) )
725                 return false;
726         elseif ( 1 == count($custom[$key]) )
727                 return $custom[$key][0];
728         else
729                 return $custom[$key];
730 }
731
732 /**
733  * Display list of post custom fields.
734  *
735  * @internal This will probably change at some point...
736  * @since 1.2.0
737  * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
738  */
739 function the_meta() {
740         if ( $keys = get_post_custom_keys() ) {
741                 echo "<ul class='post-meta'>\n";
742                 foreach ( (array) $keys as $key ) {
743                         $keyt = trim($key);
744                         if ( is_protected_meta( $keyt, 'post' ) )
745                                 continue;
746                         $values = array_map('trim', get_post_custom_values($key));
747                         $value = implode($values,', ');
748                         echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
749                 }
750                 echo "</ul>\n";
751         }
752 }
753
754 //
755 // Pages
756 //
757
758 /**
759  * Retrieve or display list of pages as a dropdown (select list).
760  *
761  * @since 2.1.0
762  *
763  * @param array|string $args Optional. Override default arguments.
764  * @return string HTML content, if not displaying.
765  */
766 function wp_dropdown_pages($args = '') {
767         $defaults = array(
768                 'depth' => 0, 'child_of' => 0,
769                 'selected' => 0, 'echo' => 1,
770                 'name' => 'page_id', 'id' => '',
771                 'show_option_none' => '', 'show_option_no_change' => '',
772                 'option_none_value' => ''
773         );
774
775         $r = wp_parse_args( $args, $defaults );
776         extract( $r, EXTR_SKIP );
777
778         $pages = get_pages($r);
779         $output = '';
780         // Back-compat with old system where both id and name were based on $name argument
781         if ( empty($id) )
782                 $id = $name;
783
784         if ( ! empty($pages) ) {
785                 $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n";
786                 if ( $show_option_no_change )
787                         $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
788                 if ( $show_option_none )
789                         $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
790                 $output .= walk_page_dropdown_tree($pages, $depth, $r);
791                 $output .= "</select>\n";
792         }
793
794         $output = apply_filters('wp_dropdown_pages', $output);
795
796         if ( $echo )
797                 echo $output;
798
799         return $output;
800 }
801
802 /**
803  * Retrieve or display list of pages in list (li) format.
804  *
805  * @since 1.5.0
806  *
807  * @param array|string $args Optional. Override default arguments.
808  * @return string HTML content, if not displaying.
809  */
810 function wp_list_pages($args = '') {
811         $defaults = array(
812                 'depth' => 0, 'show_date' => '',
813                 'date_format' => get_option('date_format'),
814                 'child_of' => 0, 'exclude' => '',
815                 'title_li' => __('Pages'), 'echo' => 1,
816                 'authors' => '', 'sort_column' => 'menu_order, post_title',
817                 'link_before' => '', 'link_after' => '', 'walker' => '',
818         );
819
820         $r = wp_parse_args( $args, $defaults );
821         extract( $r, EXTR_SKIP );
822
823         $output = '';
824         $current_page = 0;
825
826         // sanitize, mostly to keep spaces out
827         $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
828
829         // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
830         $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
831         $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
832
833         // Query pages.
834         $r['hierarchical'] = 0;
835         $pages = get_pages($r);
836
837         if ( !empty($pages) ) {
838                 if ( $r['title_li'] )
839                         $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
840
841                 global $wp_query;
842                 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
843                         $current_page = $wp_query->get_queried_object_id();
844                 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
845
846                 if ( $r['title_li'] )
847                         $output .= '</ul></li>';
848         }
849
850         $output = apply_filters('wp_list_pages', $output, $r);
851
852         if ( $r['echo'] )
853                 echo $output;
854         else
855                 return $output;
856 }
857
858 /**
859  * Display or retrieve list of pages with optional home link.
860  *
861  * The arguments are listed below and part of the arguments are for {@link
862  * wp_list_pages()} function. Check that function for more info on those
863  * arguments.
864  *
865  * <ul>
866  * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
867  * to page title. Use column for posts table.</li>
868  * <li><strong>menu_class</strong> - Class to use for the div ID which contains
869  * the page list. Defaults to 'menu'.</li>
870  * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
871  * echo.</li>
872  * <li><strong>link_before</strong> - Text before show_home argument text.</li>
873  * <li><strong>link_after</strong> - Text after show_home argument text.</li>
874  * <li><strong>show_home</strong> - If you set this argument, then it will
875  * display the link to the home page. The show_home argument really just needs
876  * to be set to the value of the text of the link.</li>
877  * </ul>
878  *
879  * @since 2.7.0
880  *
881  * @param array|string $args
882  * @return string html menu
883  */
884 function wp_page_menu( $args = array() ) {
885         $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
886         $args = wp_parse_args( $args, $defaults );
887         $args = apply_filters( 'wp_page_menu_args', $args );
888
889         $menu = '';
890
891         $list_args = $args;
892
893         // Show Home in the menu
894         if ( ! empty($args['show_home']) ) {
895                 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
896                         $text = __('Home');
897                 else
898                         $text = $args['show_home'];
899                 $class = '';
900                 if ( is_front_page() && !is_paged() )
901                         $class = 'class="current_page_item"';
902                 $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
903                 // If the front page is a page, add it to the exclude list
904                 if (get_option('show_on_front') == 'page') {
905                         if ( !empty( $list_args['exclude'] ) ) {
906                                 $list_args['exclude'] .= ',';
907                         } else {
908                                 $list_args['exclude'] = '';
909                         }
910                         $list_args['exclude'] .= get_option('page_on_front');
911                 }
912         }
913
914         $list_args['echo'] = false;
915         $list_args['title_li'] = '';
916         $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
917
918         if ( $menu )
919                 $menu = '<ul>' . $menu . '</ul>';
920
921         $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
922         $menu = apply_filters( 'wp_page_menu', $menu, $args );
923         if ( $args['echo'] )
924                 echo $menu;
925         else
926                 return $menu;
927 }
928
929 //
930 // Page helpers
931 //
932
933 /**
934  * Retrieve HTML list content for page list.
935  *
936  * @uses Walker_Page to create HTML list content.
937  * @since 2.1.0
938  * @see Walker_Page::walk() for parameters and return description.
939  */
940 function walk_page_tree($pages, $depth, $current_page, $r) {
941         if ( empty($r['walker']) )
942                 $walker = new Walker_Page;
943         else
944                 $walker = $r['walker'];
945
946         $args = array($pages, $depth, $r, $current_page);
947         return call_user_func_array(array($walker, 'walk'), $args);
948 }
949
950 /**
951  * Retrieve HTML dropdown (select) content for page list.
952  *
953  * @uses Walker_PageDropdown to create HTML dropdown content.
954  * @since 2.1.0
955  * @see Walker_PageDropdown::walk() for parameters and return description.
956  */
957 function walk_page_dropdown_tree() {
958         $args = func_get_args();
959         if ( empty($args[2]['walker']) ) // the user's options are the third parameter
960                 $walker = new Walker_PageDropdown;
961         else
962                 $walker = $args[2]['walker'];
963
964         return call_user_func_array(array($walker, 'walk'), $args);
965 }
966
967 /**
968  * Create HTML list of pages.
969  *
970  * @package WordPress
971  * @since 2.1.0
972  * @uses Walker
973  */
974 class Walker_Page extends Walker {
975         /**
976          * @see Walker::$tree_type
977          * @since 2.1.0
978          * @var string
979          */
980         var $tree_type = 'page';
981
982         /**
983          * @see Walker::$db_fields
984          * @since 2.1.0
985          * @todo Decouple this.
986          * @var array
987          */
988         var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
989
990         /**
991          * @see Walker::start_lvl()
992          * @since 2.1.0
993          *
994          * @param string $output Passed by reference. Used to append additional content.
995          * @param int $depth Depth of page. Used for padding.
996          * @param array $args
997          */
998         function start_lvl( &$output, $depth = 0, $args = array() ) {
999                 $indent = str_repeat("\t", $depth);
1000                 $output .= "\n$indent<ul class='children'>\n";
1001         }
1002
1003         /**
1004          * @see Walker::end_lvl()
1005          * @since 2.1.0
1006          *
1007          * @param string $output Passed by reference. Used to append additional content.
1008          * @param int $depth Depth of page. Used for padding.
1009          * @param array $args
1010          */
1011         function end_lvl( &$output, $depth = 0, $args = array() ) {
1012                 $indent = str_repeat("\t", $depth);
1013                 $output .= "$indent</ul>\n";
1014         }
1015
1016         /**
1017          * @see Walker::start_el()
1018          * @since 2.1.0
1019          *
1020          * @param string $output Passed by reference. Used to append additional content.
1021          * @param object $page Page data object.
1022          * @param int $depth Depth of page. Used for padding.
1023          * @param int $current_page Page ID.
1024          * @param array $args
1025          */
1026         function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
1027                 if ( $depth )
1028                         $indent = str_repeat("\t", $depth);
1029                 else
1030                         $indent = '';
1031
1032                 extract($args, EXTR_SKIP);
1033                 $css_class = array('page_item', 'page-item-'.$page->ID);
1034                 if ( !empty($current_page) ) {
1035                         $_current_page = get_post( $current_page );
1036                         if ( in_array( $page->ID, $_current_page->ancestors ) )
1037                                 $css_class[] = 'current_page_ancestor';
1038                         if ( $page->ID == $current_page )
1039                                 $css_class[] = 'current_page_item';
1040                         elseif ( $_current_page && $page->ID == $_current_page->post_parent )
1041                                 $css_class[] = 'current_page_parent';
1042                 } elseif ( $page->ID == get_option('page_for_posts') ) {
1043                         $css_class[] = 'current_page_parent';
1044                 }
1045
1046                 $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
1047
1048                 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
1049
1050                 if ( !empty($show_date) ) {
1051                         if ( 'modified' == $show_date )
1052                                 $time = $page->post_modified;
1053                         else
1054                                 $time = $page->post_date;
1055
1056                         $output .= " " . mysql2date($date_format, $time);
1057                 }
1058         }
1059
1060         /**
1061          * @see Walker::end_el()
1062          * @since 2.1.0
1063          *
1064          * @param string $output Passed by reference. Used to append additional content.
1065          * @param object $page Page data object. Not used.
1066          * @param int $depth Depth of page. Not Used.
1067          * @param array $args
1068          */
1069         function end_el( &$output, $page, $depth = 0, $args = array() ) {
1070                 $output .= "</li>\n";
1071         }
1072
1073 }
1074
1075 /**
1076  * Create HTML dropdown list of pages.
1077  *
1078  * @package WordPress
1079  * @since 2.1.0
1080  * @uses Walker
1081  */
1082 class Walker_PageDropdown extends Walker {
1083         /**
1084          * @see Walker::$tree_type
1085          * @since 2.1.0
1086          * @var string
1087          */
1088         var $tree_type = 'page';
1089
1090         /**
1091          * @see Walker::$db_fields
1092          * @since 2.1.0
1093          * @todo Decouple this
1094          * @var array
1095          */
1096         var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
1097
1098         /**
1099          * @see Walker::start_el()
1100          * @since 2.1.0
1101          *
1102          * @param string $output Passed by reference. Used to append additional content.
1103          * @param object $page Page data object.
1104          * @param int $depth Depth of page in reference to parent pages. Used for padding.
1105          * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
1106          * @param int $id
1107          */
1108         function start_el(&$output, $page, $depth, $args, $id = 0) {
1109                 $pad = str_repeat('&nbsp;', $depth * 3);
1110
1111                 $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
1112                 if ( $page->ID == $args['selected'] )
1113                         $output .= ' selected="selected"';
1114                 $output .= '>';
1115                 $title = apply_filters( 'list_pages', $page->post_title, $page );
1116                 $output .= $pad . esc_html( $title );
1117                 $output .= "</option>\n";
1118         }
1119 }
1120
1121 //
1122 // Attachments
1123 //
1124
1125 /**
1126  * Display an attachment page link using an image or icon.
1127  *
1128  * @since 2.0.0
1129  *
1130  * @param int $id Optional. Post ID.
1131  * @param bool $fullsize Optional, default is false. Whether to use full size.
1132  * @param bool $deprecated Deprecated. Not used.
1133  * @param bool $permalink Optional, default is false. Whether to include permalink.
1134  */
1135 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
1136         if ( !empty( $deprecated ) )
1137                 _deprecated_argument( __FUNCTION__, '2.5' );
1138
1139         if ( $fullsize )
1140                 echo wp_get_attachment_link($id, 'full', $permalink);
1141         else
1142                 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
1143 }
1144
1145 /**
1146  * Retrieve an attachment page link using an image or icon, if possible.
1147  *
1148  * @since 2.5.0
1149  * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
1150  *
1151  * @param int $id Optional. Post ID.
1152  * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
1153  * @param bool $permalink Optional, default is false. Whether to add permalink to image.
1154  * @param bool $icon Optional, default is false. Whether to include icon.
1155  * @param string|bool $text Optional, default is false. If string, then will be link text.
1156  * @return string HTML content.
1157  */
1158 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
1159         $id = intval( $id );
1160         $_post = get_post( $id );
1161
1162         if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
1163                 return __( 'Missing Attachment' );
1164
1165         if ( $permalink )
1166                 $url = get_attachment_link( $_post->ID );
1167
1168         $post_title = esc_attr( $_post->post_title );
1169
1170         if ( $text )
1171                 $link_text = $text;
1172         elseif ( $size && 'none' != $size )
1173                 $link_text = wp_get_attachment_image( $id, $size, $icon );
1174         else
1175                 $link_text = '';
1176
1177         if ( trim( $link_text ) == '' )
1178                 $link_text = $_post->post_title;
1179
1180         return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
1181 }
1182
1183 /**
1184  * Wrap attachment in <<p>> element before content.
1185  *
1186  * @since 2.0.0
1187  * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
1188  *
1189  * @param string $content
1190  * @return string
1191  */
1192 function prepend_attachment($content) {
1193         $post = get_post();
1194
1195         if ( empty($post->post_type) || $post->post_type != 'attachment' )
1196                 return $content;
1197
1198         $p = '<p class="attachment">';
1199         // show the medium sized image representation of the attachment if available, and link to the raw file
1200         $p .= wp_get_attachment_link(0, 'medium', false);
1201         $p .= '</p>';
1202         $p = apply_filters('prepend_attachment', $p);
1203
1204         return "$p\n$content";
1205 }
1206
1207 //
1208 // Misc
1209 //
1210
1211 /**
1212  * Retrieve protected post password form content.
1213  *
1214  * @since 1.0.0
1215  * @uses apply_filters() Calls 'the_password_form' filter on output.
1216  *
1217  * @return string HTML content for password form for password protected post.
1218  */
1219 function get_the_password_form() {
1220         $post = get_post();
1221         $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
1222         $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
1223         <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
1224         <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
1225 </form>
1226         ';
1227         return apply_filters('the_password_form', $output);
1228 }
1229
1230 /**
1231  * Whether currently in a page template.
1232  *
1233  * This template tag allows you to determine if you are in a page template.
1234  * You can optionally provide a template name and then the check will be
1235  * specific to that template.
1236  *
1237  * @since 2.5.0
1238  * @uses $wp_query
1239  *
1240  * @param string $template The specific template name if specific matching is required.
1241  * @return bool False on failure, true if success.
1242  */
1243 function is_page_template( $template = '' ) {
1244         if ( ! is_page() )
1245                 return false;
1246
1247         $page_template = get_page_template_slug( get_queried_object_id() );
1248
1249         if ( empty( $template ) )
1250                 return (bool) $page_template;
1251
1252         if ( $template == $page_template )
1253                 return true;
1254
1255         if ( 'default' == $template && ! $page_template )
1256                 return true;
1257
1258         return false;
1259 }
1260
1261 /**
1262  * Get the specific template name for a page.
1263  *
1264  * @since 3.4.0
1265  *
1266  * @param int $post_id The page ID to check. Defaults to the current post, when used in the loop.
1267  * @return string|bool Page template filename. Returns an empty string when the default page template
1268  *      is in use. Returns false if the post is not a page.
1269  */
1270 function get_page_template_slug( $post_id = null ) {
1271         $post = get_post( $post_id );
1272         if ( 'page' != $post->post_type )
1273                 return false;
1274         $template = get_post_meta( $post->ID, '_wp_page_template', true );
1275         if ( ! $template || 'default' == $template )
1276                 return '';
1277         return $template;
1278 }
1279
1280 /**
1281  * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1282  *
1283  * @package WordPress
1284  * @subpackage Post_Revisions
1285  * @since 2.6.0
1286  *
1287  * @uses date_i18n()
1288  *
1289  * @param int|object $revision Revision ID or revision object.
1290  * @param bool $link Optional, default is true. Link to revisions's page?
1291  * @return string i18n formatted datetimestamp or localized 'Current Revision'.
1292  */
1293 function wp_post_revision_title( $revision, $link = true ) {
1294         if ( !$revision = get_post( $revision ) )
1295                 return $revision;
1296
1297         if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1298                 return false;
1299
1300         /* translators: revision date format, see http://php.net/date */
1301         $datef = _x( 'j F, Y @ G:i', 'revision date format');
1302         /* translators: 1: date */
1303         $autosavef = __( '%1$s [Autosave]' );
1304         /* translators: 1: date */
1305         $currentf  = __( '%1$s [Current Revision]' );
1306
1307         $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
1308         if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1309                 $date = "<a href='$link'>$date</a>";
1310
1311         if ( !wp_is_post_revision( $revision ) )
1312                 $date = sprintf( $currentf, $date );
1313         elseif ( wp_is_post_autosave( $revision ) )
1314                 $date = sprintf( $autosavef, $date );
1315
1316         return $date;
1317 }
1318
1319 /**
1320  * Display list of a post's revisions.
1321  *
1322  * Can output either a UL with edit links or a TABLE with diff interface, and
1323  * restore action links.
1324  *
1325  * Second argument controls parameters:
1326  *   (bool)   parent : include the parent (the "Current Revision") in the list.
1327  *   (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
1328  *                     outputs TABLE with UI.
1329  *   (int)    right  : what revision is currently being viewed - used in
1330  *                     form-table format.
1331  *   (int)    left   : what revision is currently being diffed against right -
1332  *                     used in form-table format.
1333  *
1334  * @package WordPress
1335  * @subpackage Post_Revisions
1336  * @since 2.6.0
1337  *
1338  * @uses wp_get_post_revisions()
1339  * @uses wp_post_revision_title()
1340  * @uses get_edit_post_link()
1341  * @uses get_the_author_meta()
1342  *
1343  * @todo split into two functions (list, form-table) ?
1344  *
1345  * @param int|object $post_id Post ID or post object.
1346  * @param string|array $args See description {@link wp_parse_args()}.
1347  * @return null
1348  */
1349 function wp_list_post_revisions( $post_id = 0, $args = null ) {
1350         if ( !$post = get_post( $post_id ) )
1351                 return;
1352
1353         $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
1354         extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1355
1356         switch ( $type ) {
1357                 case 'autosave' :
1358                         if ( !$autosave = wp_get_post_autosave( $post->ID ) )
1359                                 return;
1360                         $revisions = array( $autosave );
1361                         break;
1362                 case 'revision' : // just revisions - remove autosave later
1363                 case 'all' :
1364                 default :
1365                         if ( !$revisions = wp_get_post_revisions( $post->ID ) )
1366                                 return;
1367                         break;
1368         }
1369
1370         /* translators: post revision: 1: when, 2: author name */
1371         $titlef = _x( '%1$s by %2$s', 'post revision' );
1372
1373         if ( $parent )
1374                 array_unshift( $revisions, $post );
1375
1376         $rows = $right_checked = '';
1377         $class = false;
1378         $can_edit_post = current_user_can( 'edit_post', $post->ID );
1379         foreach ( $revisions as $revision ) {
1380                 if ( !current_user_can( 'read_post', $revision->ID ) )
1381                         continue;
1382                 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
1383                         continue;
1384
1385                 $date = wp_post_revision_title( $revision );
1386                 $name = get_the_author_meta( 'display_name', $revision->post_author );
1387
1388                 if ( 'form-table' == $format ) {
1389                         if ( $left )
1390                                 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
1391                         else
1392                                 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
1393                         $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
1394
1395                         $class = $class ? '' : " class='alternate'";
1396
1397                         if ( $post->ID != $revision->ID && $can_edit_post )
1398                                 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
1399                         else
1400                                 $actions = '';
1401
1402                         $rows .= "<tr$class>\n";
1403                         $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
1404                         $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
1405                         $rows .= "\t<td>$date</td>\n";
1406                         $rows .= "\t<td>$name</td>\n";
1407                         $rows .= "\t<td class='action-links'>$actions</td>\n";
1408                         $rows .= "</tr>\n";
1409                 } else {
1410                         $title = sprintf( $titlef, $date, $name );
1411                         $rows .= "\t<li>$title</li>\n";
1412                 }
1413         }
1414
1415         if ( 'form-table' == $format ) : ?>
1416
1417 <form action="revision.php" method="get">
1418
1419 <div class="tablenav">
1420         <div class="alignleft">
1421                 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
1422                 <input type="hidden" name="action" value="diff" />
1423                 <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
1424         </div>
1425 </div>
1426
1427 <br class="clear" />
1428
1429 <table class="widefat post-revisions" cellspacing="0" id="post-revisions">
1430         <col />
1431         <col />
1432         <col style="width: 33%" />
1433         <col style="width: 33%" />
1434         <col style="width: 33%" />
1435 <thead>
1436 <tr>
1437         <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Old', 'revisions column name' ); ?></th>
1438         <th scope="col"><?php /* translators: column name in revisions */ _ex( 'New', 'revisions column name' ); ?></th>
1439         <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Date Created', 'revisions column name' ); ?></th>
1440         <th scope="col"><?php _e( 'Author' ); ?></th>
1441         <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
1442 </tr>
1443 </thead>
1444 <tbody>
1445
1446 <?php echo $rows; ?>
1447
1448 </tbody>
1449 </table>
1450
1451 </form>
1452
1453 <?php
1454         else :
1455                 echo "<ul class='post-revisions'>\n";
1456                 echo $rows;
1457                 echo "</ul>";
1458         endif;
1459
1460 }