X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be15bd505d66a91e2c80062190b13e315a04a9..888fa4ed68091f3314f711c5f6fe75858bf5410b:/wp-includes/post-template.php diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 03302eab..be462587 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -96,7 +96,7 @@ function the_title_attribute( $args = '' ) { * * @since 0.71 * - * @param int|object $post Optional. Post ID or object. + * @param int|WP_Post $post Optional. Post ID or post object. * @return string */ function get_the_title( $post = 0 ) { @@ -107,14 +107,44 @@ function get_the_title( $post = 0 ) { if ( ! is_admin() ) { if ( ! empty( $post->post_password ) ) { + + /** + * Filter the text prepended to the post title for protected posts. + * + * The filter is only applied on the front end. + * + * @since 2.8.0 + * + * @param string $prepend Text displayed before the post title. + * Default 'Protected: %s'. + */ $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); $title = sprintf( $protected_title_format, $title ); } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) { + + /** + * Filter the text prepended to the post title of private posts. + * + * The filter is only applied on the front end. + * + * @since 2.8.0 + * + * @param string $prepend Text displayed before the post title. + * Default 'Private: %s'. + */ $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); $title = sprintf( $private_title_format, $title ); } } + /** + * Filter the post title. + * + * @since 0.71 + * + * @param string $title The post title. + * @param int $id The post ID. + */ return apply_filters( 'the_title', $title, $id ); } @@ -129,7 +159,7 @@ function get_the_title( $post = 0 ) { * * @since 1.5.0 * - * @param int $id Optional. Post ID. + * @param int|WP_Post $id Optional. Post ID or post object. */ function the_guid( $id = 0 ) { echo esc_url( get_the_guid( $id ) ); @@ -144,13 +174,20 @@ function the_guid( $id = 0 ) { * * @since 1.5.0 * - * @param int $id Optional. Post ID. + * @param int|WP_Post $id Optional. Post ID or post object. * @return string */ function get_the_guid( $id = 0 ) { $post = get_post($id); - return apply_filters('get_the_guid', $post->guid); + /** + * Filter the Global Unique Identifier (guid) of the post. + * + * @since 1.5.0 + * + * @param string $post_guid Global Unique Identifier (guid) of the post. + */ + return apply_filters( 'get_the_guid', $post->guid ); } /** @@ -163,6 +200,14 @@ function get_the_guid( $id = 0 ) { */ function the_content( $more_link_text = null, $strip_teaser = false) { $content = get_the_content( $more_link_text, $strip_teaser ); + + /** + * Filter the post content. + * + * @since 0.71 + * + * @param string $content Content of the current post. + */ $content = apply_filters( 'the_content', $content ); $content = str_replace( ']]>', ']]>', $content ); echo $content; @@ -221,6 +266,15 @@ function get_the_content( $more_link_text = null, $strip_teaser = false ) { $output .= '' . $content[1]; } else { if ( ! empty( $more_link_text ) ) + + /** + * Filter the Read More link text. + * + * @since 2.8.0 + * + * @param string $more_link_element Read More link element. + * @param string $more_link_text Read More text. + */ $output .= apply_filters( 'the_content_more_link', ' ID}\" class=\"more-link\">$more_link_text", $more_link_text ); $output = force_balance_tags( $output ); } @@ -248,10 +302,19 @@ function _convert_urlencoded_to_entities( $match ) { * Display the post excerpt. * * @since 0.71 - * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt. */ function the_excerpt() { - echo apply_filters('the_excerpt', get_the_excerpt()); + + /** + * Filter the displayed post excerpt. + * + * @since 0.71 + * + * @see get_the_excerpt() + * + * @param string $post_excerpt The post excerpt. + */ + echo apply_filters( 'the_excerpt', get_the_excerpt() ); } /** @@ -272,6 +335,13 @@ function get_the_excerpt( $deprecated = '' ) { return __( 'There is no excerpt because this is a protected post.' ); } + /** + * Filter the retrieved post excerpt. + * + * @since 1.2.0 + * + * @param string $post_excerpt The post excerpt. + */ return apply_filters( 'get_the_excerpt', $post->post_excerpt ); } @@ -280,7 +350,7 @@ function get_the_excerpt( $deprecated = '' ) { * * @since 2.3.0 * - * @param int $id Optional. Post ID. + * @param int|WP_Post $id Optional. Post ID or post object. * @return bool */ function has_excerpt( $id = 0 ) { @@ -294,7 +364,7 @@ function has_excerpt( $id = 0 ) { * @since 2.7.0 * * @param string|array $class One or more classes to add to the class list. - * @param int $post_id An optional post ID. + * @param int|WP_Post $post_id Optional. Post ID or post object. */ function post_class( $class = '', $post_id = null ) { // Separates classes with a single space, collates classes for post DIV @@ -304,8 +374,9 @@ function post_class( $class = '', $post_id = null ) { /** * Retrieve the classes for the post div as an array. * - * The class names are add are many. If the post is a sticky, then the 'sticky' - * class name. The class 'hentry' is always added to each post. For each + * The class names are many. If the post is a sticky, then the 'sticky' + * class name. The class 'hentry' is always added to each post. If the post has a + * post thumbnail, 'has-post-thumbnail' is added as a class. For each * category, the class will be added with 'category-' with category slug is * added. The tags are the same way as the categories with 'tag-' before the tag * slug. All classes are passed through the filter, 'post_class' with the list @@ -315,7 +386,7 @@ function post_class( $class = '', $post_id = null ) { * @since 2.7.0 * * @param string|array $class One or more classes to add to the class list. - * @param int $post_id An optional post ID. + * @param int|WP_Post $post_id Optional. Post ID or post object. * @return array Array of classes. */ function get_post_class( $class = '', $post_id = null ) { @@ -342,9 +413,13 @@ function get_post_class( $class = '', $post_id = null ) { $classes[] = 'format-standard'; } - // post requires password - if ( post_password_required($post->ID) ) + // Post requires password + if ( post_password_required( $post->ID ) ) { $classes[] = 'post-password-required'; + // Post thumbnails + } elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { + $classes[] = 'has-post-thumbnail'; + } // sticky for Sticky Posts if ( is_sticky($post->ID) && is_home() && !is_paged() ) @@ -379,7 +454,16 @@ function get_post_class( $class = '', $post_id = null ) { $classes = array_map('esc_attr', $classes); - return apply_filters('post_class', $classes, $class, $post->ID); + /** + * Filter the list of CSS classes for the current post. + * + * @since 2.7.0 + * + * @param array $classes An array of post classes. + * @param string $class A comma-separated list of additional classes added to the post. + * @param int $post_id The post ID. + */ + return apply_filters( 'post_class', $classes, $class, $post->ID ); } /** @@ -458,7 +542,10 @@ function get_body_class( $class = '' ) { } elseif ( is_archive() ) { if ( is_post_type_archive() ) { $classes[] = 'post-type-archive'; - $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) ); + $post_type = get_query_var( 'post_type' ); + if ( is_array( $post_type ) ) + $post_type = reset( $post_type ); + $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); } else if ( is_author() ) { $author = $wp_query->get_queried_object(); $classes[] = 'author'; @@ -560,6 +647,14 @@ function get_body_class( $class = '' ) { $classes = array_map( 'esc_attr', $classes ); + /** + * Filter the list of CSS body classes for the current post or page. + * + * @since 2.8.0 + * + * @param array $classes An array of body classes. + * @param string $class A comma-separated list of additional classes added to the body. + */ return apply_filters( 'body_class', $classes, $class ); } @@ -590,12 +685,9 @@ function post_password_required( $post = null ) { return ! $hasher->CheckPassword( $post->post_password, $hash ); } -/** - * Page Template Functions for usage in Themes - * - * @package WordPress - * @subpackage Template - */ +// +// Page Template Functions for usage in Themes +// /** * The formatted output of a list of pages. @@ -647,10 +739,18 @@ function wp_link_pages( $args = '' ) { ); $r = wp_parse_args( $args, $defaults ); + + /** + * Filter the arguments used in retrieving page links for paginated posts. + * + * @since 3.0.0 + * + * @param array $r An array of arguments for page links for paginated posts. + */ $r = apply_filters( 'wp_link_pages_args', $r ); extract( $r, EXTR_SKIP ); - global $page, $numpages, $multipage, $more, $pagenow; + global $page, $numpages, $multipage, $more; $output = ''; if ( $multipage ) { @@ -660,6 +760,15 @@ function wp_link_pages( $args = '' ) { $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after; if ( $i != $page || ! $more && 1 == $page ) $link = _wp_link_page( $i ) . $link . ''; + + /** + * Filter the HTML output of individual page number links. + * + * @since 3.6.0 + * + * @param string $link The page number HTML output. + * @param int $i Page number for paginated posts' page links. + */ $link = apply_filters( 'wp_link_pages_link', $link, $i ); $output .= $separator . $link; } @@ -669,12 +778,16 @@ function wp_link_pages( $args = '' ) { $i = $page - 1; if ( $i ) { $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . ''; + + /** This filter is documented in wp-includes/post-template.php */ $link = apply_filters( 'wp_link_pages_link', $link, $i ); $output .= $separator . $link; } $i = $page + 1; if ( $i <= $numpages ) { $link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . ''; + + /** This filter is documented in wp-includes/post-template.php */ $link = apply_filters( 'wp_link_pages_link', $link, $i ); $output .= $separator . $link; } @@ -682,6 +795,14 @@ function wp_link_pages( $args = '' ) { } } + /** + * Filter the HTML output of page links for paginated posts. + * + * @since 3.6.0 + * + * @param string $output HTML output of paginated posts' page links. + * @param array $args An array of arguments. + */ $output = apply_filters( 'wp_link_pages', $output, $args ); if ( $echo ) @@ -714,6 +835,19 @@ function _wp_link_page( $i ) { $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); } + if ( is_preview() ) { + $url = add_query_arg( array( + 'preview' => 'true' + ), $url ); + + if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { + $url = add_query_arg( array( + 'preview_id' => wp_unslash( $_GET['preview_id'] ), + 'preview_nonce' => wp_unslash( $_GET['preview_nonce'] ) + ), $url ); + } + } + return ''; } @@ -756,7 +890,17 @@ function the_meta() { continue; $values = array_map('trim', get_post_custom_values($key)); $value = implode($values,', '); - echo apply_filters('the_meta_key', "
  • $value
  • \n", $key, $value); + + /** + * Filter the HTML output of the li element in the post custom fields list. + * + * @since 2.2.0 + * + * @param string $html The HTML output for the li element. + * @param string $key Meta key. + * @param string $value Meta value. + */ + echo apply_filters( 'the_meta_key', "
  • $value
  • \n", $key, $value ); } echo "\n"; } @@ -802,7 +946,14 @@ function wp_dropdown_pages($args = '') { $output .= "\n"; } - $output = apply_filters('wp_dropdown_pages', $output); + /** + * Filter the HTML output of a list of pages as a drop down. + * + * @since 2.1.0 + * + * @param string $output HTML output for drop down list of pages. + */ + $output = apply_filters( 'wp_dropdown_pages', $output ); if ( $echo ) echo $output; @@ -839,7 +990,15 @@ function wp_list_pages($args = '') { // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); - $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) ); + + /** + * Filter the array of pages to exclude from the pages list. + * + * @since 2.1.0 + * + * @param array $exclude_array An array of page IDs to exclude. + */ + $r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) ); // Query pages. $r['hierarchical'] = 0; @@ -850,15 +1009,32 @@ function wp_list_pages($args = '') { $output .= ''; } - $output = apply_filters('wp_list_pages', $output, $r); + /** + * Filter the HTML output of the pages to list. + * + * @since 1.5.1 + * + * @see wp_list_pages() + * + * @param string $output HTML output of the pages list. + * @param array $r An array of page-listing arguments. + */ + $output = apply_filters( 'wp_list_pages', $output, $r ); if ( $r['echo'] ) echo $output; @@ -875,7 +1051,7 @@ function wp_list_pages($args = '') { * *