PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/post-template.php

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