PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-includes/post-template.php

https://bitbucket.org/dkrzos/phc
PHP | 1460 lines | 747 code | 193 blank | 520 comment | 212 complexity | f0b3a8b1c5a034b6f301ae639ff39097 MD5 | raw file
Possible License(s): GPL-2.0
  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. $post = get_post($post);
  494. if ( empty( $post->post_password ) )
  495. return false;
  496. if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
  497. return true;
  498. require_once ABSPATH . 'wp-includes/class-phpass.php';
  499. $hasher = new PasswordHash( 8, true );
  500. $hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
  501. if ( 0 !== strpos( $hash, '$P$B' ) )
  502. return true;
  503. return ! $hasher->CheckPassword( $post->post_password, $hash );
  504. }
  505. /**
  506. * Page Template Functions for usage in Themes
  507. *
  508. * @package WordPress
  509. * @subpackage Template
  510. */
  511. /**
  512. * The formatted output of a list of pages.
  513. *
  514. * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
  515. * Quicktag one or more times). This tag must be within The Loop.
  516. *
  517. * The defaults for overwriting are:
  518. * 'next_or_number' - Default is 'number' (string). Indicates whether page
  519. * numbers should be used. Valid values are number and next.
  520. * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
  521. * of the bookmark.
  522. * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
  523. * previous page, if available.
  524. * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
  525. * the parameter string will be replaced with the page number, so Page %
  526. * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
  527. * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
  528. * each bookmarks.
  529. * 'after' - Default is '</p>' (string). The html or text to append to each
  530. * bookmarks.
  531. * 'link_before' - Default is '' (string). The html or text to prepend to each
  532. * Pages link inside the <a> tag. Also prepended to the current item, which
  533. * is not linked.
  534. * 'link_after' - Default is '' (string). The html or text to append to each
  535. * Pages link inside the <a> tag. Also appended to the current item, which
  536. * is not linked.
  537. *
  538. * @since 1.2.0
  539. * @access private
  540. *
  541. * @param string|array $args Optional. Overwrite the defaults.
  542. * @return string Formatted output in HTML.
  543. */
  544. function wp_link_pages($args = '') {
  545. $defaults = array(
  546. 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
  547. 'link_before' => '', 'link_after' => '',
  548. 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
  549. 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
  550. 'echo' => 1
  551. );
  552. $r = wp_parse_args( $args, $defaults );
  553. $r = apply_filters( 'wp_link_pages_args', $r );
  554. extract( $r, EXTR_SKIP );
  555. global $page, $numpages, $multipage, $more, $pagenow;
  556. $output = '';
  557. if ( $multipage ) {
  558. if ( 'number' == $next_or_number ) {
  559. $output .= $before;
  560. for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
  561. $j = str_replace('%',$i,$pagelink);
  562. $output .= ' ';
  563. if ( ($i != $page) || ((!$more) && ($page==1)) ) {
  564. $output .= _wp_link_page($i);
  565. }
  566. $output .= $link_before . $j . $link_after;
  567. if ( ($i != $page) || ((!$more) && ($page==1)) )
  568. $output .= '</a>';
  569. }
  570. $output .= $after;
  571. } else {
  572. if ( $more ) {
  573. $output .= $before;
  574. $i = $page - 1;
  575. if ( $i && $more ) {
  576. $output .= _wp_link_page($i);
  577. $output .= $link_before. $previouspagelink . $link_after . '</a>';
  578. }
  579. $i = $page + 1;
  580. if ( $i <= $numpages && $more ) {
  581. $output .= _wp_link_page($i);
  582. $output .= $link_before. $nextpagelink . $link_after . '</a>';
  583. }
  584. $output .= $after;
  585. }
  586. }
  587. }
  588. if ( $echo )
  589. echo $output;
  590. return $output;
  591. }
  592. /**
  593. * Helper function for wp_link_pages().
  594. *
  595. * @since 3.1.0
  596. * @access private
  597. *
  598. * @param int $i Page number.
  599. * @return string Link.
  600. */
  601. function _wp_link_page( $i ) {
  602. global $wp_rewrite;
  603. $post = get_post();
  604. if ( 1 == $i ) {
  605. $url = get_permalink();
  606. } else {
  607. if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
  608. $url = add_query_arg( 'page', $i, get_permalink() );
  609. elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
  610. $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
  611. else
  612. $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
  613. }
  614. return '<a href="' . esc_url( $url ) . '">';
  615. }
  616. //
  617. // Post-meta: Custom per-post fields.
  618. //
  619. /**
  620. * Retrieve post custom meta data field.
  621. *
  622. * @since 1.5.0
  623. *
  624. * @param string $key Meta data key name.
  625. * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
  626. */
  627. function post_custom( $key = '' ) {
  628. $custom = get_post_custom();
  629. if ( !isset( $custom[$key] ) )
  630. return false;
  631. elseif ( 1 == count($custom[$key]) )
  632. return $custom[$key][0];
  633. else
  634. return $custom[$key];
  635. }
  636. /**
  637. * Display list of post custom fields.
  638. *
  639. * @internal This will probably change at some point...
  640. * @since 1.2.0
  641. * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
  642. */
  643. function the_meta() {
  644. if ( $keys = get_post_custom_keys() ) {
  645. echo "<ul class='post-meta'>\n";
  646. foreach ( (array) $keys as $key ) {
  647. $keyt = trim($key);
  648. if ( is_protected_meta( $keyt, 'post' ) )
  649. continue;
  650. $values = array_map('trim', get_post_custom_values($key));
  651. $value = implode($values,', ');
  652. echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
  653. }
  654. echo "</ul>\n";
  655. }
  656. }
  657. //
  658. // Pages
  659. //
  660. /**
  661. * Retrieve or display list of pages as a dropdown (select list).
  662. *
  663. * @since 2.1.0
  664. *
  665. * @param array|string $args Optional. Override default arguments.
  666. * @return string HTML content, if not displaying.
  667. */
  668. function wp_dropdown_pages($args = '') {
  669. $defaults = array(
  670. 'depth' => 0, 'child_of' => 0,
  671. 'selected' => 0, 'echo' => 1,
  672. 'name' => 'page_id', 'id' => '',
  673. 'show_option_none' => '', 'show_option_no_change' => '',
  674. 'option_none_value' => ''
  675. );
  676. $r = wp_parse_args( $args, $defaults );
  677. extract( $r, EXTR_SKIP );
  678. $pages = get_pages($r);
  679. $output = '';
  680. // Back-compat with old system where both id and name were based on $name argument
  681. if ( empty($id) )
  682. $id = $name;
  683. if ( ! empty($pages) ) {
  684. $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n";
  685. if ( $show_option_no_change )
  686. $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
  687. if ( $show_option_none )
  688. $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
  689. $output .= walk_page_dropdown_tree($pages, $depth, $r);
  690. $output .= "</select>\n";
  691. }
  692. $output = apply_filters('wp_dropdown_pages', $output);
  693. if ( $echo )
  694. echo $output;
  695. return $output;
  696. }
  697. /**
  698. * Retrieve or display list of pages in list (li) format.
  699. *
  700. * @since 1.5.0
  701. *
  702. * @param array|string $args Optional. Override default arguments.
  703. * @return string HTML content, if not displaying.
  704. */
  705. function wp_list_pages($args = '') {
  706. $defaults = array(
  707. 'depth' => 0, 'show_date' => '',
  708. 'date_format' => get_option('date_format'),
  709. 'child_of' => 0, 'exclude' => '',
  710. 'title_li' => __('Pages'), 'echo' => 1,
  711. 'authors' => '', 'sort_column' => 'menu_order, post_title',
  712. 'link_before' => '', 'link_after' => '', 'walker' => '',
  713. );
  714. $r = wp_parse_args( $args, $defaults );
  715. extract( $r, EXTR_SKIP );
  716. $output = '';
  717. $current_page = 0;
  718. // sanitize, mostly to keep spaces out
  719. $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
  720. // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
  721. $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
  722. $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
  723. // Query pages.
  724. $r['hierarchical'] = 0;
  725. $pages = get_pages($r);
  726. if ( !empty($pages) ) {
  727. if ( $r['title_li'] )
  728. $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
  729. global $wp_query;
  730. if ( is_page() || is_attachment() || $wp_query->is_posts_page )
  731. $current_page = $wp_query->get_queried_object_id();
  732. $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
  733. if ( $r['title_li'] )
  734. $output .= '</ul></li>';
  735. }
  736. $output = apply_filters('wp_list_pages', $output, $r);
  737. if ( $r['echo'] )
  738. echo $output;
  739. else
  740. return $output;
  741. }
  742. /**
  743. * Display or retrieve list of pages with optional home link.
  744. *
  745. * The arguments are listed below and part of the arguments are for {@link
  746. * wp_list_pages()} function. Check that function for more info on those
  747. * arguments.
  748. *
  749. * <ul>
  750. * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
  751. * to page title. Use column for posts table.</li>
  752. * <li><strong>menu_class</strong> - Class to use for the div ID which contains
  753. * the page list. Defaults to 'menu'.</li>
  754. * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
  755. * echo.</li>
  756. * <li><strong>link_before</strong> - Text before show_home argument text.</li>
  757. * <li><strong>link_after</strong> - Text after show_home argument text.</li>
  758. * <li><strong>show_home</strong> - If you set this argument, then it will
  759. * display the link to the home page. The show_home argument really just needs
  760. * to be set to the value of the text of the link.</li>
  761. * </ul>
  762. *
  763. * @since 2.7.0
  764. *
  765. * @param array|string $args
  766. * @return string html menu
  767. */
  768. function wp_page_menu( $args = array() ) {
  769. $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
  770. $args = wp_parse_args( $args, $defaults );
  771. $args = apply_filters( 'wp_page_menu_args', $args );
  772. $menu = '';
  773. $list_args = $args;
  774. // Show Home in the menu
  775. if ( ! empty($args['show_home']) ) {
  776. if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
  777. $text = __('Home');
  778. else
  779. $text = $args['show_home'];
  780. $class = '';
  781. if ( is_front_page() && !is_paged() )
  782. $class = 'class="current_page_item"';
  783. $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  784. // If the front page is a page, add it to the exclude list
  785. if (get_option('show_on_front') == 'page') {
  786. if ( !empty( $list_args['exclude'] ) ) {
  787. $list_args['exclude'] .= ',';
  788. } else {
  789. $list_args['exclude'] = '';
  790. }
  791. $list_args['exclude'] .= get_option('page_on_front');
  792. }
  793. }
  794. $list_args['echo'] = false;
  795. $list_args['title_li'] = '';
  796. $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
  797. if ( $menu )
  798. $menu = '<ul>' . $menu . '</ul>';
  799. $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
  800. $menu = apply_filters( 'wp_page_menu', $menu, $args );
  801. if ( $args['echo'] )
  802. echo $menu;
  803. else
  804. return $menu;
  805. }
  806. //
  807. // Page helpers
  808. //
  809. /**
  810. * Retrieve HTML list content for page list.
  811. *
  812. * @uses Walker_Page to create HTML list content.
  813. * @since 2.1.0
  814. * @see Walker_Page::walk() for parameters and return description.
  815. */
  816. function walk_page_tree($pages, $depth, $current_page, $r) {
  817. if ( empty($r['walker']) )
  818. $walker = new Walker_Page;
  819. else
  820. $walker = $r['walker'];
  821. $args = array($pages, $depth, $r, $current_page);
  822. return call_user_func_array(array($walker, 'walk'), $args);
  823. }
  824. /**
  825. * Retrieve HTML dropdown (select) content for page list.
  826. *
  827. * @uses Walker_PageDropdown to create HTML dropdown content.
  828. * @since 2.1.0
  829. * @see Walker_PageDropdown::walk() for parameters and return description.
  830. */
  831. function walk_page_dropdown_tree() {
  832. $args = func_get_args();
  833. if ( empty($args[2]['walker']) ) // the user's options are the third parameter
  834. $walker = new Walker_PageDropdown;
  835. else
  836. $walker = $args[2]['walker'];
  837. return call_user_func_array(array($walker, 'walk'), $args);
  838. }
  839. /**
  840. * Create HTML list of pages.
  841. *
  842. * @package WordPress
  843. * @since 2.1.0
  844. * @uses Walker
  845. */
  846. class Walker_Page extends Walker {
  847. /**
  848. * @see Walker::$tree_type
  849. * @since 2.1.0
  850. * @var string
  851. */
  852. var $tree_type = 'page';
  853. /**
  854. * @see Walker::$db_fields
  855. * @since 2.1.0
  856. * @todo Decouple this.
  857. * @var array
  858. */
  859. var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
  860. /**
  861. * @see Walker::start_lvl()
  862. * @since 2.1.0
  863. *
  864. * @param string $output Passed by reference. Used to append additional content.
  865. * @param int $depth Depth of page. Used for padding.
  866. * @param array $args
  867. */
  868. function start_lvl( &$output, $depth = 0, $args = array() ) {
  869. $indent = str_repeat("\t", $depth);
  870. $output .= "\n$indent<ul class='children'>\n";
  871. }
  872. /**
  873. * @see Walker::end_lvl()
  874. * @since 2.1.0
  875. *
  876. * @param string $output Passed by reference. Used to append additional content.
  877. * @param int $depth Depth of page. Used for padding.
  878. * @param array $args
  879. */
  880. function end_lvl( &$output, $depth = 0, $args = array() ) {
  881. $indent = str_repeat("\t", $depth);
  882. $output .= "$indent</ul>\n";
  883. }
  884. /**
  885. * @see Walker::start_el()
  886. * @since 2.1.0
  887. *
  888. * @param string $output Passed by reference. Used to append additional content.
  889. * @param object $page Page data object.
  890. * @param int $depth Depth of page. Used for padding.
  891. * @param int $current_page Page ID.
  892. * @param array $args
  893. */
  894. function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
  895. if ( $depth )
  896. $indent = str_repeat("\t", $depth);
  897. else
  898. $indent = '';
  899. extract($args, EXTR_SKIP);
  900. $css_class = array('page_item', 'page-item-'.$page->ID);
  901. if ( !empty($current_page) ) {
  902. $_current_page = get_post( $current_page );
  903. if ( in_array( $page->ID, $_current_page->ancestors ) )
  904. $css_class[] = 'current_page_ancestor';
  905. if ( $page->ID == $current_page )
  906. $css_class[] = 'current_page_item';
  907. elseif ( $_current_page && $page->ID == $_current_page->post_parent )
  908. $css_class[] = 'current_page_parent';
  909. } elseif ( $page->ID == get_option('page_for_posts') ) {
  910. $css_class[] = 'current_page_parent';
  911. }
  912. $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
  913. $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>';
  914. if ( !empty($show_date) ) {
  915. if ( 'modified' == $show_date )
  916. $time = $page->post_modified;
  917. else
  918. $time = $page->post_date;
  919. $output .= " " . mysql2date($date_format, $time);
  920. }
  921. }
  922. /**
  923. * @see Walker::end_el()
  924. * @since 2.1.0
  925. *
  926. * @param string $output Passed by reference. Used to append additional content.
  927. * @param object $page Page data object. Not used.
  928. * @param int $depth Depth of page. Not Used.
  929. * @param array $args
  930. */
  931. function end_el( &$output, $page, $depth = 0, $args = array() ) {
  932. $output .= "</li>\n";
  933. }
  934. }
  935. /**
  936. * Create HTML dropdown list of pages.
  937. *
  938. * @package WordPress
  939. * @since 2.1.0
  940. * @uses Walker
  941. */
  942. class Walker_PageDropdown extends Walker {
  943. /**
  944. * @see Walker::$tree_type
  945. * @since 2.1.0
  946. * @var string
  947. */
  948. var $tree_type = 'page';
  949. /**
  950. * @see Walker::$db_fields
  951. * @since 2.1.0
  952. * @todo Decouple this
  953. * @var array
  954. */
  955. var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
  956. /**
  957. * @see Walker::start_el()
  958. * @since 2.1.0
  959. *
  960. * @param string $output Passed by reference. Used to append additional content.
  961. * @param object $page Page data object.
  962. * @param int $depth Depth of page in reference to parent pages. Used for padding.
  963. * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
  964. * @param int $id
  965. */
  966. function start_el(&$output, $page, $depth, $args, $id = 0) {
  967. $pad = str_repeat('&nbsp;', $depth * 3);
  968. $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
  969. if ( $page->ID == $args['selected'] )
  970. $output .= ' selected="selected"';
  971. $output .= '>';
  972. $title = apply_filters( 'list_pages', $page->post_title, $page );
  973. $output .= $pad . esc_html( $title );
  974. $output .= "</option>\n";
  975. }
  976. }
  977. //
  978. // Attachments
  979. //
  980. /**
  981. * Display an attachment page link using an image or icon.
  982. *
  983. * @since 2.0.0
  984. *
  985. * @param int $id Optional. Post ID.
  986. * @param bool $fullsize Optional, default is false. Whether to use full size.
  987. * @param bool $deprecated Deprecated. Not used.
  988. * @param bool $permalink Optional, default is false. Whether to include permalink.
  989. */
  990. function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  991. if ( !empty( $deprecated ) )
  992. _deprecated_argument( __FUNCTION__, '2.5' );
  993. if ( $fullsize )
  994. echo wp_get_attachment_link($id, 'full', $permalink);
  995. else
  996. echo wp_get_attachment_link($id, 'thumbnail', $permalink);
  997. }
  998. /**
  999. * Retrieve an attachment page link using an image or icon, if possible.
  1000. *
  1001. * @since 2.5.0
  1002. * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
  1003. *
  1004. * @param int $id Optional. Post ID.
  1005. * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
  1006. * @param bool $permalink Optional, default is false. Whether to add permalink to image.
  1007. * @param bool $icon Optional, default is false. Whether to include icon.
  1008. * @param string|bool $text Optional, default is false. If string, then will be link text.
  1009. * @return string HTML content.
  1010. */
  1011. function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
  1012. $id = intval( $id );
  1013. $_post = get_post( $id );
  1014. if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
  1015. return __( 'Missing Attachment' );
  1016. if ( $permalink )
  1017. $url = get_attachment_link( $_post->ID );
  1018. $post_title = esc_attr( $_post->post_title );
  1019. if ( $text )
  1020. $link_text = $text;
  1021. elseif ( $size && 'none' != $size )
  1022. $link_text = wp_get_attachment_image( $id, $size, $icon );
  1023. else
  1024. $link_text = '';
  1025. if ( trim( $link_text ) == '' )
  1026. $link_text = $_post->post_title;
  1027. return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
  1028. }
  1029. /**
  1030. * Wrap attachment in <<p>> element before content.
  1031. *
  1032. * @since 2.0.0
  1033. * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
  1034. *
  1035. * @param string $content
  1036. * @return string
  1037. */
  1038. function prepend_attachment($content) {
  1039. $post = get_post();
  1040. if ( empty($post->post_type) || $post->post_type != 'attachment' )
  1041. return $content;
  1042. $p = '<p class="attachment">';
  1043. // show the medium sized image representation of the attachment if available, and link to the raw file
  1044. $p .= wp_get_attachment_link(0, 'medium', false);
  1045. $p .= '</p>';
  1046. $p = apply_filters('prepend_attachment', $p);
  1047. return "$p\n$content";
  1048. }
  1049. //
  1050. // Misc
  1051. //
  1052. /**
  1053. * Retrieve protected post password form content.
  1054. *
  1055. * @since 1.0.0
  1056. * @uses apply_filters() Calls 'the_password_form' filter on output.
  1057. *
  1058. * @return string HTML content for password form for password protected post.
  1059. */
  1060. function get_the_password_form() {
  1061. $post = get_post();
  1062. $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
  1063. $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
  1064. <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
  1065. <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>
  1066. </form>
  1067. ';
  1068. return apply_filters('the_password_form', $output);
  1069. }
  1070. /**
  1071. * Whether currently in a page template.
  1072. *
  1073. * This template tag allows you to determine if you are in a page template.
  1074. * You can optionally provide a template name and then the check will be
  1075. * specific to that template.
  1076. *
  1077. * @since 2.5.0
  1078. * @uses $wp_query
  1079. *
  1080. * @param string $template The specific template name if specific matching is required.
  1081. * @return bool False on failure, true if success.
  1082. */
  1083. function is_page_template( $template = '' ) {
  1084. if ( ! is_page() )
  1085. return false;
  1086. $page_template = get_page_template_slug( get_queried_object_id() );
  1087. if ( empty( $template ) )
  1088. return (bool) $page_template;
  1089. if ( $template == $page_template )
  1090. return true;
  1091. if ( 'default' == $template && ! $page_template )
  1092. return true;
  1093. return false;
  1094. }
  1095. /**
  1096. * Get the specific template name for a page.
  1097. *
  1098. * @since 3.4.0
  1099. *
  1100. * @param int $post_id The page ID to check. Defaults to the current post, when used in the loop.
  1101. * @return string|bool Page template filename. Returns an empty string when the default page template
  1102. * is in use. Returns false if the post is not a page.
  1103. */
  1104. function get_page_template_slug( $post_id = null ) {
  1105. $post = get_post( $post_id );
  1106. if ( 'page' != $post->post_type )
  1107. return false;
  1108. $template = get_post_meta( $post->ID, '_wp_page_template', true );
  1109. if ( ! $template || 'default' == $template )
  1110. return '';
  1111. return $template;
  1112. }
  1113. /**
  1114. * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1115. *
  1116. * @package WordPress
  1117. * @subpackage Post_Revisions
  1118. * @since 2.6.0
  1119. *
  1120. * @uses date_i18n()
  1121. *
  1122. * @param int|object $revision Revision ID or revision object.
  1123. * @param bool $link Optional, default is true. Link to revisions's page?
  1124. * @return string i18n formatted datetimestamp or localized 'Current Revision'.
  1125. */
  1126. function wp_post_revision_title( $revision, $link = true ) {
  1127. if ( !$revision = get_post( $revision ) )
  1128. return $revision;
  1129. if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
  1130. return false;
  1131. /* translators: revision date format, see http://php.net/date */
  1132. $datef = _x( 'j F, Y @ G:i', 'revision date format');
  1133. /* translators: 1: date */
  1134. $autosavef = __( '%1$s [Autosave]' );
  1135. /* translators: 1: date */
  1136. $currentf = __( '%1$s [Current Revision]' );
  1137. $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1138. if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
  1139. $date = "<a href='$link'>$date</a>";
  1140. if ( !wp_is_post_revision( $revision ) )
  1141. $date = sprintf( $currentf, $date );
  1142. elseif ( wp_is_post_autosave( $revision ) )
  1143. $date = sprintf( $autosavef, $date );
  1144. return $date;
  1145. }
  1146. /**
  1147. * Display list of a post's revisions.
  1148. *
  1149. * Can output either a UL with edit links or a TABLE with diff interface, and
  1150. * restore action links.
  1151. *
  1152. * Second argument controls parameters:
  1153. * (bool) parent : include the parent (the "Current Revision") in the list.
  1154. * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
  1155. * outputs TABLE with UI.
  1156. * (int) right : what revision is currently being viewed - used in
  1157. * form-table format.
  1158. * (int) left : what revision is currently being diffed against right -
  1159. * used in form-table format.
  1160. *
  1161. * @package WordPress
  1162. * @subpackage Post_Revisions
  1163. * @since 2.6.0
  1164. *
  1165. * @uses wp_get_post_revisions()
  1166. * @uses wp_post_revision_title()
  1167. * @uses get_edit_post_link()
  1168. * @uses get_the_author_meta()
  1169. *
  1170. * @todo split into two functions (list, form-table) ?
  1171. *
  1172. * @param int|object $post_id Post ID or post object.
  1173. * @param string|array $args See description {@link wp_parse_args()}.
  1174. * @return null
  1175. */
  1176. function wp_list_post_revisions( $post_id = 0, $args = null ) {
  1177. if ( !$post = get_post( $post_id ) )
  1178. return;
  1179. $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
  1180. extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
  1181. switch ( $type ) {
  1182. case 'autosave' :
  1183. if ( !$autosave = wp_get_post_autosave( $post->ID ) )
  1184. return;
  1185. $revisions = array( $autosave );
  1186. break;
  1187. case 'revision' : // just revisions - remove autosave later
  1188. case 'all' :
  1189. default :
  1190. if ( !$revisions = wp_get_post_revisions( $post->ID ) )
  1191. return;
  1192. break;
  1193. }
  1194. /* translators: post revision: 1: when, 2: author name */
  1195. $titlef = _x( '%1$s by %2$s', 'post revision' );
  1196. if ( $parent )
  1197. array_unshift( $revisions, $post );
  1198. $rows = $right_checked = '';
  1199. $class = false;
  1200. $can_edit_post = current_user_can( 'edit_post', $post->ID );
  1201. foreach ( $revisions as $revision ) {
  1202. if ( !current_user_can( 'read_post', $revision->ID ) )
  1203. continue;
  1204. if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
  1205. continue;
  1206. $date = wp_post_revision_title( $revision );
  1207. $name = get_the_author_meta( 'display_name', $revision->post_author );
  1208. if ( 'form-table' == $format ) {
  1209. if ( $left )
  1210. $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
  1211. else
  1212. $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
  1213. $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
  1214. $class = $class ? '' : " class='alternate'";
  1215. if ( $post->ID != $revision->ID && $can_edit_post )
  1216. $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
  1217. else
  1218. $actions = '';
  1219. $rows .= "<tr$class>\n";
  1220. $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
  1221. $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
  1222. $rows .= "\t<td>$date</td>\n";
  1223. $rows .= "\t<td>$name</td>\n";
  1224. $rows .= "\t<td class='action-links'>$actions</td>\n";
  1225. $rows .= "</tr>\n";
  1226. } else {
  1227. $title = sprintf( $titlef, $date, $name );
  1228. $rows .= "\t<li>$title</li>\n";
  1229. }
  1230. }
  1231. if ( 'form-table' == $format ) : ?>
  1232. <form action="revision.php" method="get">
  1233. <div class="tablenav">
  1234. <div class="alignleft">
  1235. <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
  1236. <input type="hidden" name="action" value="diff" />
  1237. <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
  1238. </div>
  1239. </div>
  1240. <br class="clear" />
  1241. <table class="widefat post-revisions" cellspacing="0" id="post-revisions">
  1242. <col />
  1243. <col />
  1244. <col style="width: 33%" />
  1245. <col style="width: 33%" />
  1246. <col style="width: 33%" />
  1247. <thead>
  1248. <tr>
  1249. <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Old', 'revisions column name' ); ?></th>
  1250. <th scope="col"><?php /* translators: column name in revisions */ _ex( 'New', 'revisions column name' ); ?></th>
  1251. <th scope="col"><?php /* translators: column name in revisions */ _ex( 'Date Created', 'revisions column name' ); ?></th>
  1252. <th scope="col"><?php _e( 'Author' ); ?></th>
  1253. <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
  1254. </tr>
  1255. </thead>
  1256. <tbody>
  1257. <?php echo $rows; ?>
  1258. </tbody>
  1259. </table>
  1260. </form>
  1261. <?php
  1262. else :
  1263. echo "<ul class='post-revisions'>\n";
  1264. echo $rows;
  1265. echo "</ul>";
  1266. endif;
  1267. }