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

/wp-includes/post-template.php

https://github.com/dedavidd/piratenpartij.nl
PHP | 1780 lines | 1262 code | 120 blank | 398 comment | 131 complexity | 19e9ef17148f38d5ea2ace8995297f2a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0

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

Large files files are truncated, but you can click here to view the full file