PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/post-template.php

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