PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/post-template.php

https://bitbucket.org/cisash/fananeen
PHP | 1458 lines | 742 code | 193 blank | 523 comment | 208 complexity | d3019526bb2c6ee7b7760495d8629756 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. global $post;
  28. return $post->ID;
  29. }
  30. /**
  31. * Display or retrieve the current post title with optional content.
  32. *
  33. * @since 0.71
  34. *
  35. * @param string $before Optional. Content to prepend to the title.
  36. * @param string $after Optional. Content to append to the title.
  37. * @param bool $echo Optional, default to true.Whether to display or return.
  38. * @return null|string Null on no title. String if $echo parameter is false.
  39. */
  40. function the_title($before = '', $after = '', $echo = true) {
  41. $title = get_the_title();
  42. if ( strlen($title) == 0 )
  43. return;
  44. $title = $before . $title . $after;
  45. if ( $echo )
  46. echo $title;
  47. else
  48. return $title;
  49. }
  50. /**
  51. * Sanitize the current title when retrieving or displaying.
  52. *
  53. * Works like {@link the_title()}, except the parameters can be in a string or
  54. * an array. See the function for what can be override in the $args parameter.
  55. *
  56. * The title before it is displayed will have the tags stripped and {@link
  57. * esc_attr()} before it is passed to the user or displayed. The default
  58. * as with {@link the_title()}, is to display the title.
  59. *
  60. * @since 2.3.0
  61. *
  62. * @param string|array $args Optional. Override the defaults.
  63. * @return string|null Null on failure or display. String when echo is false.
  64. */
  65. function the_title_attribute( $args = '' ) {
  66. $title = get_the_title();
  67. if ( strlen($title) == 0 )
  68. return;
  69. $defaults = array('before' => '', 'after' => '', 'echo' => true);
  70. $r = wp_parse_args($args, $defaults);
  71. extract( $r, EXTR_SKIP );
  72. $title = $before . $title . $after;
  73. $title = esc_attr(strip_tags($title));
  74. if ( $echo )
  75. echo $title;
  76. else
  77. return $title;
  78. }
  79. /**
  80. * Retrieve post title.
  81. *
  82. * If the post is protected and the visitor is not an admin, then "Protected"
  83. * will be displayed before the post title. If the post is private, then
  84. * "Private" will be located before the post title.
  85. *
  86. * @since 0.71
  87. *
  88. * @param int $id Optional. Post ID.
  89. * @return string
  90. */
  91. function get_the_title( $id = 0 ) {
  92. $post = &get_post($id);
  93. $title = isset($post->post_title) ? $post->post_title : '';
  94. $id = isset($post->ID) ? $post->ID : (int) $id;
  95. if ( !is_admin() ) {
  96. if ( !empty($post->post_password) ) {
  97. $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
  98. $title = sprintf($protected_title_format, $title);
  99. } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
  100. $private_title_format = apply_filters('private_title_format', __('Private: %s'));
  101. $title = sprintf($private_title_format, $title);
  102. }
  103. }
  104. return apply_filters( 'the_title', $title, $id );
  105. }
  106. /**
  107. * Display the Post Global Unique Identifier (guid).
  108. *
  109. * The guid will appear to be a link, but should not be used as an link to the
  110. * post. The reason you should not use it as a link, is because of moving the
  111. * blog across domains.
  112. *
  113. * Url is escaped to make it xml safe
  114. *
  115. * @since 1.5.0
  116. *
  117. * @param int $id Optional. Post ID.
  118. */
  119. function the_guid( $id = 0 ) {
  120. echo esc_url( get_the_guid( $id ) );
  121. }
  122. /**
  123. * Retrieve the Post Global Unique Identifier (guid).
  124. *
  125. * The guid will appear to be a link, but should not be used as an link to the
  126. * post. The reason you should not use it as a link, is because of moving the
  127. * blog across domains.
  128. *
  129. * @since 1.5.0
  130. *
  131. * @param int $id Optional. Post ID.
  132. * @return string
  133. */
  134. function get_the_guid( $id = 0 ) {
  135. $post = &get_post($id);
  136. return apply_filters('get_the_guid', $post->guid);
  137. }
  138. /**
  139. * Display the post content.
  140. *
  141. * @since 0.71
  142. *
  143. * @param string $more_link_text Optional. Content for when there is more text.
  144. * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
  145. */
  146. function the_content($more_link_text = null, $stripteaser = false) {
  147. $content = get_the_content($more_link_text, $stripteaser);
  148. $content = apply_filters('the_content', $content);
  149. $content = str_replace(']]>', ']]&gt;', $content);
  150. echo $content;
  151. }
  152. /**
  153. * Retrieve the post content.
  154. *
  155. * @since 0.71
  156. *
  157. * @param string $more_link_text Optional. Content for when there is more text.
  158. * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
  159. * @return string
  160. */
  161. function get_the_content($more_link_text = null, $stripteaser = false) {
  162. global $post, $more, $page, $pages, $multipage, $preview;
  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($post) )
  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. * @returns 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. global $post;
  232. $output = $post->post_excerpt;
  233. if ( post_password_required($post) ) {
  234. $output = __('There is no excerpt because this is a protected post.');
  235. return $output;
  236. }
  237. return apply_filters('get_the_excerpt', $output);
  238. }
  239. /**
  240. * Whether post has excerpt.
  241. *
  242. * @since 2.3.0
  243. *
  244. * @param int $id Optional. Post ID.
  245. * @return bool
  246. */
  247. function has_excerpt( $id = 0 ) {
  248. $post = &get_post( $id );
  249. return ( !empty( $post->post_excerpt ) );
  250. }
  251. /**
  252. * Display the classes for the post div.
  253. *
  254. * @since 2.7.0
  255. *
  256. * @param string|array $class One or more classes to add to the class list.
  257. * @param int $post_id An optional post ID.
  258. */
  259. function post_class( $class = '', $post_id = null ) {
  260. // Separates classes with a single space, collates classes for post DIV
  261. echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
  262. }
  263. /**
  264. * Retrieve the classes for the post div as an array.
  265. *
  266. * The class names are add are many. If the post is a sticky, then the 'sticky'
  267. * class name. The class 'hentry' is always added to each post. For each
  268. * category, the class will be added with 'category-' with category slug is
  269. * added. The tags are the same way as the categories with 'tag-' before the tag
  270. * slug. All classes are passed through the filter, 'post_class' with the list
  271. * of classes, followed by $class parameter value, with the post ID as the last
  272. * parameter.
  273. *
  274. * @since 2.7.0
  275. *
  276. * @param string|array $class One or more classes to add to the class list.
  277. * @param int $post_id An optional post ID.
  278. * @return array Array of classes.
  279. */
  280. function get_post_class( $class = '', $post_id = null ) {
  281. $post = get_post($post_id);
  282. $classes = array();
  283. if ( empty($post) )
  284. return $classes;
  285. $classes[] = 'post-' . $post->ID;
  286. $classes[] = $post->post_type;
  287. $classes[] = 'type-' . $post->post_type;
  288. $classes[] = 'status-' . $post->post_status;
  289. // Post Format
  290. if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
  291. $post_format = get_post_format( $post->ID );
  292. if ( $post_format && !is_wp_error($post_format) )
  293. $classes[] = 'format-' . sanitize_html_class( $post_format );
  294. else
  295. $classes[] = 'format-standard';
  296. }
  297. // post requires password
  298. if ( post_password_required($post->ID) )
  299. $classes[] = 'post-password-required';
  300. // sticky for Sticky Posts
  301. if ( is_sticky($post->ID) && is_home() && !is_paged() )
  302. $classes[] = 'sticky';
  303. // hentry for hAtom compliance
  304. $classes[] = 'hentry';
  305. // Categories
  306. if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
  307. foreach ( (array) get_the_category($post->ID) as $cat ) {
  308. if ( empty($cat->slug ) )
  309. continue;
  310. $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
  311. }
  312. }
  313. // Tags
  314. if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
  315. foreach ( (array) get_the_tags($post->ID) as $tag ) {
  316. if ( empty($tag->slug ) )
  317. continue;
  318. $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
  319. }
  320. }
  321. if ( !empty($class) ) {
  322. if ( !is_array( $class ) )
  323. $class = preg_split('#\s+#', $class);
  324. $classes = array_merge($classes, $class);
  325. }
  326. $classes = array_map('esc_attr', $classes);
  327. return apply_filters('post_class', $classes, $class, $post->ID);
  328. }
  329. /**
  330. * Display the classes for the body element.
  331. *
  332. * @since 2.8.0
  333. *
  334. * @param string|array $class One or more classes to add to the class list.
  335. */
  336. function body_class( $class = '' ) {
  337. // Separates classes with a single space, collates classes for body element
  338. echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
  339. }
  340. /**
  341. * Retrieve the classes for the body element as an array.
  342. *
  343. * @since 2.8.0
  344. *
  345. * @param string|array $class One or more classes to add to the class list.
  346. * @return array Array of classes.
  347. */
  348. function get_body_class( $class = '' ) {
  349. global $wp_query, $wpdb;
  350. $classes = array();
  351. if ( is_rtl() )
  352. $classes[] = 'rtl';
  353. if ( is_front_page() )
  354. $classes[] = 'home';
  355. if ( is_home() )
  356. $classes[] = 'blog';
  357. if ( is_archive() )
  358. $classes[] = 'archive';
  359. if ( is_date() )
  360. $classes[] = 'date';
  361. if ( is_search() ) {
  362. $classes[] = 'search';
  363. $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
  364. }
  365. if ( is_paged() )
  366. $classes[] = 'paged';
  367. if ( is_attachment() )
  368. $classes[] = 'attachment';
  369. if ( is_404() )
  370. $classes[] = 'error404';
  371. if ( is_single() ) {
  372. $post_id = $wp_query->get_queried_object_id();
  373. $post = $wp_query->get_queried_object();
  374. $classes[] = 'single';
  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. if ( is_attachment() ) {
  386. $mime_type = get_post_mime_type($post_id);
  387. $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
  388. $classes[] = 'attachmentid-' . $post_id;
  389. $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
  390. }
  391. } elseif ( is_archive() ) {
  392. if ( is_post_type_archive() ) {
  393. $classes[] = 'post-type-archive';
  394. $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );
  395. } else if ( is_author() ) {
  396. $author = $wp_query->get_queried_object();
  397. $classes[] = 'author';
  398. $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
  399. $classes[] = 'author-' . $author->ID;
  400. } elseif ( is_category() ) {
  401. $cat = $wp_query->get_queried_object();
  402. $classes[] = 'category';
  403. $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
  404. $classes[] = 'category-' . $cat->term_id;
  405. } elseif ( is_tag() ) {
  406. $tags = $wp_query->get_queried_object();
  407. $classes[] = 'tag';
  408. $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
  409. $classes[] = 'tag-' . $tags->term_id;
  410. } elseif ( is_tax() ) {
  411. $term = $wp_query->get_queried_object();
  412. $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
  413. $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
  414. $classes[] = 'term-' . $term->term_id;
  415. }
  416. } elseif ( is_page() ) {
  417. $classes[] = 'page';
  418. $page_id = $wp_query->get_queried_object_id();
  419. $post = get_page($page_id);
  420. $classes[] = 'page-id-' . $page_id;
  421. 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) ) )
  422. $classes[] = 'page-parent';
  423. if ( $post->post_parent ) {
  424. $classes[] = 'page-child';
  425. $classes[] = 'parent-pageid-' . $post->post_parent;
  426. }
  427. if ( is_page_template() ) {
  428. $classes[] = 'page-template';
  429. $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) );
  430. } else {
  431. $classes[] = 'page-template-default';
  432. }
  433. }
  434. if ( is_user_logged_in() )
  435. $classes[] = 'logged-in';
  436. if ( is_admin_bar_showing() )
  437. $classes[] = 'admin-bar';
  438. if ( get_theme_mod( 'background_color' ) || get_background_image() )
  439. $classes[] = 'custom-background';
  440. $page = $wp_query->get( 'page' );
  441. if ( !$page || $page < 2)
  442. $page = $wp_query->get( 'paged' );
  443. if ( $page && $page > 1 ) {
  444. $classes[] = 'paged-' . $page;
  445. if ( is_single() )
  446. $classes[] = 'single-paged-' . $page;
  447. elseif ( is_page() )
  448. $classes[] = 'page-paged-' . $page;
  449. elseif ( is_category() )
  450. $classes[] = 'category-paged-' . $page;
  451. elseif ( is_tag() )
  452. $classes[] = 'tag-paged-' . $page;
  453. elseif ( is_date() )
  454. $classes[] = 'date-paged-' . $page;
  455. elseif ( is_author() )
  456. $classes[] = 'author-paged-' . $page;
  457. elseif ( is_search() )
  458. $classes[] = 'search-paged-' . $page;
  459. elseif ( is_post_type_archive() )
  460. $classes[] = 'post-type-paged-' . $page;
  461. }
  462. if ( ! empty( $class ) ) {
  463. if ( !is_array( $class ) )
  464. $class = preg_split( '#\s+#', $class );
  465. $classes = array_merge( $classes, $class );
  466. } else {
  467. // Ensure that we always coerce class to being an array.
  468. $class = array();
  469. }
  470. $classes = array_map( 'esc_attr', $classes );
  471. return apply_filters( 'body_class', $classes, $class );
  472. }
  473. /**
  474. * Whether post requires password and correct password has been provided.
  475. *
  476. * @since 2.7.0
  477. *
  478. * @param int|object $post An optional post. Global $post used if not provided.
  479. * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
  480. */
  481. function post_password_required( $post = null ) {
  482. global $wp_hasher;
  483. $post = get_post($post);
  484. if ( empty( $post->post_password ) )
  485. return false;
  486. if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
  487. return true;
  488. if ( empty( $wp_hasher ) ) {
  489. require_once( ABSPATH . 'wp-includes/class-phpass.php');
  490. // By default, use the portable hash from phpass
  491. $wp_hasher = new PasswordHash(8, true);
  492. }
  493. $hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
  494. return ! $wp_hasher->CheckPassword( $post->post_password, $hash );
  495. }
  496. /**
  497. * Display "sticky" CSS class, if a post is sticky.
  498. *
  499. * @since 2.7.0
  500. *
  501. * @param int $post_id An optional post ID.
  502. */
  503. function sticky_class( $post_id = null ) {
  504. if ( !is_sticky($post_id) )
  505. return;
  506. echo " sticky";
  507. }
  508. /**
  509. * Page Template Functions for usage in Themes
  510. *
  511. * @package WordPress
  512. * @subpackage Template
  513. */
  514. /**
  515. * The formatted output of a list of pages.
  516. *
  517. * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
  518. * Quicktag one or more times). This tag must be within The Loop.
  519. *
  520. * The defaults for overwriting are:
  521. * 'next_or_number' - Default is 'number' (string). Indicates whether page
  522. * numbers should be used. Valid values are number and next.
  523. * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
  524. * of the bookmark.
  525. * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
  526. * previous page, if available.
  527. * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
  528. * the parameter string will be replaced with the page number, so Page %
  529. * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
  530. * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
  531. * each bookmarks.
  532. * 'after' - Default is '</p>' (string). The html or text to append to each
  533. * bookmarks.
  534. * 'link_before' - Default is '' (string). The html or text to prepend to each
  535. * Pages link inside the <a> tag. Also prepended to the current item, which
  536. * is not linked.
  537. * 'link_after' - Default is '' (string). The html or text to append to each
  538. * Pages link inside the <a> tag. Also appended to the current item, which
  539. * is not linked.
  540. *
  541. * @since 1.2.0
  542. * @access private
  543. *
  544. * @param string|array $args Optional. Overwrite the defaults.
  545. * @return string Formatted output in HTML.
  546. */
  547. function wp_link_pages($args = '') {
  548. $defaults = array(
  549. 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
  550. 'link_before' => '', 'link_after' => '',
  551. 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
  552. 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
  553. 'echo' => 1
  554. );
  555. $r = wp_parse_args( $args, $defaults );
  556. $r = apply_filters( 'wp_link_pages_args', $r );
  557. extract( $r, EXTR_SKIP );
  558. global $page, $numpages, $multipage, $more, $pagenow;
  559. $output = '';
  560. if ( $multipage ) {
  561. if ( 'number' == $next_or_number ) {
  562. $output .= $before;
  563. for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
  564. $j = str_replace('%',$i,$pagelink);
  565. $output .= ' ';
  566. if ( ($i != $page) || ((!$more) && ($page==1)) ) {
  567. $output .= _wp_link_page($i);
  568. }
  569. $output .= $link_before . $j . $link_after;
  570. if ( ($i != $page) || ((!$more) && ($page==1)) )
  571. $output .= '</a>';
  572. }
  573. $output .= $after;
  574. } else {
  575. if ( $more ) {
  576. $output .= $before;
  577. $i = $page - 1;
  578. if ( $i && $more ) {
  579. $output .= _wp_link_page($i);
  580. $output .= $link_before. $previouspagelink . $link_after . '</a>';
  581. }
  582. $i = $page + 1;
  583. if ( $i <= $numpages && $more ) {
  584. $output .= _wp_link_page($i);
  585. $output .= $link_before. $nextpagelink . $link_after . '</a>';
  586. }
  587. $output .= $after;
  588. }
  589. }
  590. }
  591. if ( $echo )
  592. echo $output;
  593. return $output;
  594. }
  595. /**
  596. * Helper function for wp_link_pages().
  597. *
  598. * @since 3.1.0
  599. * @access private
  600. *
  601. * @param int $i Page number.
  602. * @return string Link.
  603. */
  604. function _wp_link_page( $i ) {
  605. global $post, $wp_rewrite;
  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. */
  769. function wp_page_menu( $args = array() ) {
  770. $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
  771. $args = wp_parse_args( $args, $defaults );
  772. $args = apply_filters( 'wp_page_menu_args', $args );
  773. $menu = '';
  774. $list_args = $args;
  775. // Show Home in the menu
  776. if ( ! empty($args['show_home']) ) {
  777. if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
  778. $text = __('Home');
  779. else
  780. $text = $args['show_home'];
  781. $class = '';
  782. if ( is_front_page() && !is_paged() )
  783. $class = 'class="current_page_item"';
  784. $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
  785. // If the front page is a page, add it to the exclude list
  786. if (get_option('show_on_front') == 'page') {
  787. if ( !empty( $list_args['exclude'] ) ) {
  788. $list_args['exclude'] .= ',';
  789. } else {
  790. $list_args['exclude'] = '';
  791. }
  792. $list_args['exclude'] .= get_option('page_on_front');
  793. }
  794. }
  795. $list_args['echo'] = false;
  796. $list_args['title_li'] = '';
  797. $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
  798. if ( $menu )
  799. $menu = '<ul>' . $menu . '</ul>';
  800. $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
  801. $menu = apply_filters( 'wp_page_menu', $menu, $args );
  802. if ( $args['echo'] )
  803. echo $menu;
  804. else
  805. return $menu;
  806. }
  807. //
  808. // Page helpers
  809. //
  810. /**
  811. * Retrieve HTML list content for page list.
  812. *
  813. * @uses Walker_Page to create HTML list content.
  814. * @since 2.1.0
  815. * @see Walker_Page::walk() for parameters and return description.
  816. */
  817. function walk_page_tree($pages, $depth, $current_page, $r) {
  818. if ( empty($r['walker']) )
  819. $walker = new Walker_Page;
  820. else
  821. $walker = $r['walker'];
  822. $args = array($pages, $depth, $r, $current_page);
  823. return call_user_func_array(array(&$walker, 'walk'), $args);
  824. }
  825. /**
  826. * Retrieve HTML dropdown (select) content for page list.
  827. *
  828. * @uses Walker_PageDropdown to create HTML dropdown content.
  829. * @since 2.1.0
  830. * @see Walker_PageDropdown::walk() for parameters and return description.
  831. */
  832. function walk_page_dropdown_tree() {
  833. $args = func_get_args();
  834. if ( empty($args[2]['walker']) ) // the user's options are the third parameter
  835. $walker = new Walker_PageDropdown;
  836. else
  837. $walker = $args[2]['walker'];
  838. return call_user_func_array(array(&$walker, 'walk'), $args);
  839. }
  840. /**
  841. * Create HTML list of pages.
  842. *
  843. * @package WordPress
  844. * @since 2.1.0
  845. * @uses Walker
  846. */
  847. class Walker_Page extends Walker {
  848. /**
  849. * @see Walker::$tree_type
  850. * @since 2.1.0
  851. * @var string
  852. */
  853. var $tree_type = 'page';
  854. /**
  855. * @see Walker::$db_fields
  856. * @since 2.1.0
  857. * @todo Decouple this.
  858. * @var array
  859. */
  860. var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
  861. /**
  862. * @see Walker::start_lvl()
  863. * @since 2.1.0
  864. *
  865. * @param string $output Passed by reference. Used to append additional content.
  866. * @param int $depth Depth of page. Used for padding.
  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. */
  879. function end_lvl( &$output, $depth = 0, $args = array() ) {
  880. $indent = str_repeat("\t", $depth);
  881. $output .= "$indent</ul>\n";
  882. }
  883. /**
  884. * @see Walker::start_el()
  885. * @since 2.1.0
  886. *
  887. * @param string $output Passed by reference. Used to append additional content.
  888. * @param object $page Page data object.
  889. * @param int $depth Depth of page. Used for padding.
  890. * @param int $current_page Page ID.
  891. * @param array $args
  892. */
  893. function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
  894. if ( $depth )
  895. $indent = str_repeat("\t", $depth);
  896. else
  897. $indent = '';
  898. extract($args, EXTR_SKIP);
  899. $css_class = array('page_item', 'page-item-'.$page->ID);
  900. if ( !empty($current_page) ) {
  901. $_current_page = get_page( $current_page );
  902. _get_post_ancestors($_current_page);
  903. if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_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. */
  930. function end_el( &$output, $page, $depth = 0, $args = array() ) {
  931. $output .= "</li>\n";
  932. }
  933. }
  934. /**
  935. * Create HTML dropdown list of pages.
  936. *
  937. * @package WordPress
  938. * @since 2.1.0
  939. * @uses Walker
  940. */
  941. class Walker_PageDropdown extends Walker {
  942. /**
  943. * @see Walker::$tree_type
  944. * @since 2.1.0
  945. * @var string
  946. */
  947. var $tree_type = 'page';
  948. /**
  949. * @see Walker::$db_fields
  950. * @since 2.1.0
  951. * @todo Decouple this
  952. * @var array
  953. */
  954. var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
  955. /**
  956. * @see Walker::start_el()
  957. * @since 2.1.0
  958. *
  959. * @param string $output Passed by reference. Used to append additional content.
  960. * @param object $page Page data object.
  961. * @param int $depth Depth of page in reference to parent pages. Used for padding.
  962. * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
  963. */
  964. function start_el(&$output, $page, $depth, $args, $id = 0) {
  965. $pad = str_repeat('&nbsp;', $depth * 3);
  966. $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
  967. if ( $page->ID == $args['selected'] )
  968. $output .= ' selected="selected"';
  969. $output .= '>';
  970. $title = apply_filters( 'list_pages', $page->post_title, $page );
  971. $output .= $pad . esc_html( $title );
  972. $output .= "</option>\n";
  973. }
  974. }
  975. //
  976. // Attachments
  977. //
  978. /**
  979. * Display an attachment page link using an image or icon.
  980. *
  981. * @since 2.0.0
  982. *
  983. * @param int $id Optional. Post ID.
  984. * @param bool $fullsize Optional, default is false. Whether to use full size.
  985. * @param bool $deprecated Deprecated. Not used.
  986. * @param bool $permalink Optional, default is false. Whether to include permalink.
  987. */
  988. function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
  989. if ( !empty( $deprecated ) )
  990. _deprecated_argument( __FUNCTION__, '2.5' );
  991. if ( $fullsize )
  992. echo wp_get_attachment_link($id, 'full', $permalink);
  993. else
  994. echo wp_get_attachment_link($id, 'thumbnail', $permalink);
  995. }
  996. /**
  997. * Retrieve an attachment page link using an image or icon, if possible.
  998. *
  999. * @since 2.5.0
  1000. * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
  1001. *
  1002. * @param int $id Optional. Post ID.
  1003. * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
  1004. * @param bool $permalink Optional, default is false. Whether to add permalink to image.
  1005. * @param bool $icon Optional, default is false. Whether to include icon.
  1006. * @param string $text Optional, default is false. If string, then will be link text.
  1007. * @return string HTML content.
  1008. */
  1009. function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
  1010. $id = intval( $id );
  1011. $_post = & get_post( $id );
  1012. if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
  1013. return __( 'Missing Attachment' );
  1014. if ( $permalink )
  1015. $url = get_attachment_link( $_post->ID );
  1016. $post_title = esc_attr( $_post->post_title );
  1017. if ( $text )
  1018. $link_text = $text;
  1019. elseif ( $size && 'none' != $size )
  1020. $link_text = wp_get_attachment_image( $id, $size, $icon );
  1021. else
  1022. $link_text = '';
  1023. if ( trim( $link_text ) == '' )
  1024. $link_text = $_post->post_title;
  1025. return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
  1026. }
  1027. /**
  1028. * Wrap attachment in <<p>> element before content.
  1029. *
  1030. * @since 2.0.0
  1031. * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
  1032. *
  1033. * @param string $content
  1034. * @return string
  1035. */
  1036. function prepend_attachment($content) {
  1037. global $post;
  1038. if ( empty($post->post_type) || $post->post_type != 'attachment' )
  1039. return $content;
  1040. $p = '<p class="attachment">';
  1041. // show the medium sized image representation of the attachment if available, and link to the raw file
  1042. $p .= wp_get_attachment_link(0, 'medium', false);
  1043. $p .= '</p>';
  1044. $p = apply_filters('prepend_attachment', $p);
  1045. return "$p\n$content";
  1046. }
  1047. //
  1048. // Misc
  1049. //
  1050. /**
  1051. * Retrieve protected post password form content.
  1052. *
  1053. * @since 1.0.0
  1054. * @uses apply_filters() Calls 'the_password_form' filter on output.
  1055. *
  1056. * @return string HTML content for password form for password protected post.
  1057. */
  1058. function get_the_password_form() {
  1059. global $post;
  1060. $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
  1061. $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
  1062. <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
  1063. <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>
  1064. </form>
  1065. ';
  1066. return apply_filters('the_password_form', $output);
  1067. }
  1068. /**
  1069. * Whether currently in a page template.
  1070. *
  1071. * This template tag allows you to determine if you are in a page template.
  1072. * You can optionally provide a template name and then the check will be
  1073. * specific to that template.
  1074. *
  1075. * @since 2.5.0
  1076. * @uses $wp_query
  1077. *
  1078. * @param string $template The specific template name if specific matching is required.
  1079. * @return bool False on failure, true if success.
  1080. */
  1081. function is_page_template( $template = '' ) {
  1082. if ( ! is_page() )
  1083. return false;
  1084. $page_template = get_page_template_slug( get_queried_object_id() );
  1085. if ( empty( $template ) )
  1086. return (bool) $page_template;
  1087. if ( $template == $page_template )
  1088. return true;
  1089. if ( 'default' == $template && ! $page_template )
  1090. return true;
  1091. return false;
  1092. }
  1093. /**
  1094. * Get the specific template name for a page.
  1095. *
  1096. * @since 3.4.0
  1097. *
  1098. * @param int $id The page ID to check. Defaults to the current post, when used in the loop.
  1099. * @return string|bool Page template filename. Returns an empty string when the default page template
  1100. * is in use. Returns false if the post is not a page.
  1101. */
  1102. function get_page_template_slug( $post_id = null ) {
  1103. $post = get_post( $post_id );
  1104. if ( 'page' != $post->post_type )
  1105. return false;
  1106. $template = get_post_meta( $post->ID, '_wp_page_template', true );
  1107. if ( ! $template || 'default' == $template )
  1108. return '';
  1109. return $template;
  1110. }
  1111. /**
  1112. * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
  1113. *
  1114. * @package WordPress
  1115. * @subpackage Post_Revisions
  1116. * @since 2.6.0
  1117. *
  1118. * @uses date_i18n()
  1119. *
  1120. * @param int|object $revision Revision ID or revision object.
  1121. * @param bool $link Optional, default is true. Link to revisions's page?
  1122. * @return string i18n formatted datetimestamp or localized 'Current Revision'.
  1123. */
  1124. function wp_post_revision_title( $revision, $link = true ) {
  1125. if ( !$revision = get_post( $revision ) )
  1126. return $revision;
  1127. if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
  1128. return false;
  1129. /* translators: revision date format, see http://php.net/date */
  1130. $datef = _x( 'j F, Y @ G:i', 'revision date format');
  1131. /* translators: 1: date */
  1132. $autosavef = __( '%1$s [Autosave]' );
  1133. /* translators: 1: date */
  1134. $currentf = __( '%1$s [Current Revision]' );
  1135. $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
  1136. if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
  1137. $date = "<a href='$link'>$date</a>";
  1138. if ( !wp_is_post_revision( $revision ) )
  1139. $date = sprintf( $currentf, $date );
  1140. elseif ( wp_is_post_autosave( $revision ) )
  1141. $date = sprintf( $autosavef, $date );
  1142. return $date;
  1143. }
  1144. /**
  1145. * Display list of a post's revisions.
  1146. *
  1147. * Can output either a UL with edit links or a TABLE with diff interface, and
  1148. * restore action links.
  1149. *
  1150. * Second argument controls parameters:
  1151. * (bool) parent : include the parent (the "Current Revision") in the list.
  1152. * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
  1153. * outputs TABLE with UI.
  1154. * (int) right : what revision is currently being viewed - used in
  1155. * form-table format.
  1156. * (int) left : what revision is currently being diffed against right -
  1157. * used in form-table format.
  1158. *
  1159. * @package WordPress
  1160. * @subpackage Post_Revisions
  1161. * @since 2.6.0
  1162. *
  1163. * @uses wp_get_post_revisions()
  1164. * @uses wp_post_revision_title()
  1165. * @uses get_edit_post_link()
  1166. * @uses get_the_author_meta()
  1167. *
  1168. * @todo split into two functions (list, form-table) ?
  1169. *
  1170. * @param int|object $post_id Post ID or post object.
  1171. * @param string|array $args See description {@link wp_parse_args()}.
  1172. * @return null
  1173. */
  1174. function wp_list_post_revisions( $post_id = 0, $args = null ) {
  1175. if ( !$post = get_post( $post_id ) )
  1176. return;
  1177. $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
  1178. extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
  1179. switch ( $type ) {
  1180. case 'autosave' :
  1181. if ( !$autosave = wp_get_post_autosave( $post->ID ) )
  1182. return;
  1183. $revisions = array( $autosave );
  1184. break;
  1185. case 'revision' : // just revisions - remove autosave later
  1186. case 'all' :
  1187. default :
  1188. if ( !$revisions = wp_get_post_revisions( $post->ID ) )
  1189. return;
  1190. break;
  1191. }
  1192. /* translators: post revision: 1: when, 2: author name */
  1193. $titlef = _x( '%1$s by %2$s', 'post revision' );
  1194. if ( $parent )
  1195. array_unshift( $revisions, $post );
  1196. $rows = $right_checked = '';
  1197. $class = false;
  1198. $can_edit_post = current_user_can( 'edit_post', $post->ID );
  1199. foreach ( $revisions as $revision ) {
  1200. if ( !current_user_can( 'read_post', $revision->ID ) )
  1201. continue;
  1202. if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
  1203. continue;
  1204. $date = wp_post_revision_title( $revision );
  1205. $name = get_the_author_meta( 'display_name', $revision->post_author );
  1206. if ( 'form-table' == $format ) {
  1207. if ( $left )
  1208. $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
  1209. else
  1210. $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
  1211. $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
  1212. $class = $class ? '' : " class='alternate'";
  1213. if ( $post->ID != $revision->ID && $can_edit_post )
  1214. $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
  1215. else
  1216. $actions = '';
  1217. $rows .= "<tr$class>\n";
  1218. $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
  1219. $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
  1220. $rows .= "\t<td>$date</td>\n";
  1221. $rows .= "\t<td>$name</td>\n";
  1222. $rows .= "\t<td class='action-links'>$actions</td>\n";
  1223. $rows .= "</tr>\n";
  1224. } else {
  1225. $title = sprintf( $titlef, $date, $name );
  1226. $rows .= "\t<li>$title</li>\n";
  1227. }
  1228. }
  1229. if ( 'form-table' == $format ) : ?>
  1230. <form action="revision.php" method="get">
  1231. <div class="tablenav">
  1232. <div class="alignleft">
  1233. <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
  1234. <input type="hidden" name="action" value="diff" />
  1235. <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
  1236. </div>
  1237. </div>
  1238. <br class="clear" />
  1239. <table class="widefat post-revisions" cellspacing="0" id="post-revisions">
  1240. <col />
  1241. <col />
  1242. <col style="width: 33%" />
  1243. <col style="width: 33%" />
  1244. <col style="width: 33%" />
  1245. <thead>
  1246. <tr>
  1247. <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Old', 'revisions column name' ); ?></th>
  1248. <th scope="col"><?php /* translators: column name in revisons */ _ex( 'New', 'revisions column name' ); ?></th>
  1249. <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Date Created', 'revisions column name' ); ?></th>
  1250. <th scope="col"><?php _e( 'Author' ); ?></th>
  1251. <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
  1252. </tr>
  1253. </thead>
  1254. <tbody>
  1255. <?php echo $rows; ?>
  1256. </tbody>
  1257. </table>
  1258. </form>
  1259. <?php
  1260. else :
  1261. echo "<ul class='post-revisions'>\n";
  1262. echo $rows;
  1263. echo "</ul>";
  1264. endif;
  1265. }