X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-includes/post-template.php diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index be462587..c736e316 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -23,10 +23,11 @@ function the_ID() { * @since 2.1.0 * @uses $post * - * @return int + * @return int|bool The ID of the current item in the WordPress Loop. False if $post is not set. */ function get_the_ID() { - return get_post()->ID; + $post = get_post(); + return ! empty( $post ) ? $post->ID : false; } /** @@ -65,26 +66,34 @@ function the_title($before = '', $after = '', $echo = true) { * * @since 2.3.0 * - * @param string|array $args Optional. Override the defaults. + * @param string|array $args { + * Title attribute arguments. Optional. + * + * @type string $before Markup to prepend to the title. Default empty. + * @type string $after Markup to append to the title. Default empty. + * @type bool $echo Whether to echo or return the title. Default true for echo. + * @type WP_Post $post Current post object to retrieve the title for. + * } * @return string|null Null on failure or display. String when echo is false. */ function the_title_attribute( $args = '' ) { - $defaults = array('before' => '', 'after' => '', 'echo' => true, 'post' => get_post() ); - $r = wp_parse_args($args, $defaults); - extract( $r, EXTR_SKIP ); + $defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() ); + $r = wp_parse_args( $args, $defaults ); - $title = get_the_title( $post ); + $title = get_the_title( $r['post'] ); - if ( strlen($title) == 0 ) + if ( strlen( $title ) == 0 ) { return; + } - $title = $before . $title . $after; - $title = esc_attr(strip_tags($title)); + $title = $r['before'] . $title . $r['after']; + $title = esc_attr( strip_tags( $title ) ); - if ( $echo ) + if ( $r['echo'] ) { echo $title; - else + } else { return $title; + } } /** @@ -96,7 +105,7 @@ function the_title_attribute( $args = '' ) { * * @since 0.71 * - * @param int|WP_Post $post Optional. Post ID or post object. + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. * @return string */ function get_the_title( $post = 0 ) { @@ -115,10 +124,11 @@ function get_the_title( $post = 0 ) { * * @since 2.8.0 * - * @param string $prepend Text displayed before the post title. - * Default 'Protected: %s'. + * @param string $prepend Text displayed before the post title. + * Default 'Protected: %s'. + * @param WP_Post $post Current post object. */ - $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); + $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); $title = sprintf( $protected_title_format, $title ); } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) { @@ -129,10 +139,11 @@ function get_the_title( $post = 0 ) { * * @since 2.8.0 * - * @param string $prepend Text displayed before the post title. - * Default 'Private: %s'. + * @param string $prepend Text displayed before the post title. + * Default 'Private: %s'. + * @param WP_Post $post Current post object. */ - $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); + $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); $title = sprintf( $private_title_format, $title ); } } @@ -330,6 +341,9 @@ function get_the_excerpt( $deprecated = '' ) { _deprecated_argument( __FUNCTION__, '2.3' ); $post = get_post(); + if ( empty( $post ) ) { + return ''; + } if ( post_password_required() ) { return __( 'There is no excerpt because this is a protected post.' ); @@ -422,8 +436,13 @@ function get_post_class( $class = '', $post_id = null ) { } // sticky for Sticky Posts - if ( is_sticky($post->ID) && is_home() && !is_paged() ) - $classes[] = 'sticky'; + if ( is_sticky( $post->ID ) ) { + if ( is_home() && ! is_paged() ) { + $classes[] = 'sticky'; + } elseif ( is_admin() ) { + $classes[] = 'status-sticky'; + } + } // hentry for hAtom compliance $classes[] = 'hentry'; @@ -463,7 +482,9 @@ function get_post_class( $class = '', $post_id = null ) { * @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 ); + $classes = apply_filters( 'post_class', $classes, $class, $post->ID ); + + return array_unique( $classes ); } /** @@ -584,8 +605,9 @@ function get_body_class( $class = '' ) { $classes[] = 'page-id-' . $page_id; - 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) ) ) + if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { $classes[] = 'page-parent'; + } if ( $post->post_parent ) { $classes[] = 'page-child'; @@ -612,10 +634,10 @@ function get_body_class( $class = '' ) { $page = $wp_query->get( 'page' ); - if ( !$page || $page < 2) + if ( ! $page || $page < 2 ) $page = $wp_query->get( 'paged' ); - if ( $page && $page > 1 ) { + if ( $page && $page > 1 && ! is_404() ) { $classes[] = 'paged-' . $page; if ( is_single() ) @@ -655,7 +677,9 @@ function get_body_class( $class = '' ) { * @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 ); + $classes = apply_filters( 'body_class', $classes, $class ); + + return array_unique( $classes ); } /** @@ -675,7 +699,7 @@ function post_password_required( $post = null ) { if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) return true; - require_once ABSPATH . 'wp-includes/class-phpass.php'; + require_once ABSPATH . WPINC . '/class-phpass.php'; $hasher = new PasswordHash( 8, true ); $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); @@ -695,33 +719,27 @@ function post_password_required( $post = null ) { * Displays page links for paginated posts (i.e. includes the . * Quicktag one or more times). This tag must be within The Loop. * - * The defaults for overwriting are: - * 'before' - Default is '

Pages:' (string). The html or text to prepend to - * each bookmarks. - * 'after' - Default is '

' (string). The html or text to append to each - * bookmarks. - * 'link_before' - Default is '' (string). The html or text to prepend to each - * Pages link inside the tag. Also prepended to the current item, which - * is not linked. - * 'link_after' - Default is '' (string). The html or text to append to each - * Pages link inside the tag. Also appended to the current item, which - * is not linked. - * 'next_or_number' - Default is 'number' (string). Indicates whether page - * numbers should be used. Valid values are number and next. - * 'separator' - Default is ' ' (string). Text used between pagination links. - * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page. - * of the bookmark. - * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to - * previous page, if available. - * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in - * the parameter string will be replaced with the page number, so Page % - * generates "Page 1", "Page 2", etc. Defaults to %, just the page number. - * 'echo' - Default is 1 (integer). When not 0, this triggers the HTML to be - * echoed and then returned. - * * @since 1.2.0 * - * @param string|array $args Optional. Overwrite the defaults. + * @param string|array $args { + * Optional. Array or string of default arguments. + * + * @type string $before HTML or text to prepend to each link. Default is '

Pages:'. + * @type string $after HTML or text to append to each link. Default is '

'. + * @type string $link_before HTML or text to prepend to each link, inside the
tag. + * Also prepended to the current item, which is not linked. Default empty. + * @type string $link_after HTML or text to append to each Pages link inside the tag. + * Also appended to the current item, which is not linked. Default empty. + * @type string $next_or_number Indicates whether page numbers should be used. Valid values are number + * and next. Default is 'number'. + * @type string $separator Text between pagination links. Default is ' '. + * @type string $nextpagelink Link text for the next page link, if available. Default is 'Next Page'. + * @type string $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'. + * @type string $pagelink Format string for page numbers. The % in the parameter string will be + * replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc. + * Defaults to '%', just the page number. + * @type int|bool $echo Whether to echo or not. Accepts 1|true or 0|false. Default 1|true. + * } * @return string Formatted output in HTML. */ function wp_link_pages( $args = '' ) { @@ -738,29 +756,28 @@ function wp_link_pages( $args = '' ) { 'echo' => 1 ); - $r = wp_parse_args( $args, $defaults ); + $params = 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. + * @param array $params An array of arguments for page links for paginated posts. */ - $r = apply_filters( 'wp_link_pages_args', $r ); - extract( $r, EXTR_SKIP ); + $r = apply_filters( 'wp_link_pages_args', $params ); global $page, $numpages, $multipage, $more; $output = ''; if ( $multipage ) { - if ( 'number' == $next_or_number ) { - $output .= $before; + if ( 'number' == $r['next_or_number'] ) { + $output .= $r['before']; for ( $i = 1; $i <= $numpages; $i++ ) { - $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after; - if ( $i != $page || ! $more && 1 == $page ) + $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after']; + if ( $i != $page || ! $more && 1 == $page ) { $link = _wp_link_page( $i ) . $link . ''; - + } /** * Filter the HTML output of individual page number links. * @@ -770,28 +787,28 @@ function wp_link_pages( $args = '' ) { * @param int $i Page number for paginated posts' page links. */ $link = apply_filters( 'wp_link_pages_link', $link, $i ); - $output .= $separator . $link; + $output .= $r['separator'] . $link; } - $output .= $after; + $output .= $r['after']; } elseif ( $more ) { - $output .= $before; - $i = $page - 1; - if ( $i ) { - $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . ''; + $output .= $r['before']; + $prev = $page - 1; + if ( $prev ) { + $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . ''; /** This filter is documented in wp-includes/post-template.php */ - $link = apply_filters( 'wp_link_pages_link', $link, $i ); - $output .= $separator . $link; + $link = apply_filters( 'wp_link_pages_link', $link, $prev ); + $output .= $r['separator'] . $link; } - $i = $page + 1; - if ( $i <= $numpages ) { - $link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . ''; + $next = $page + 1; + if ( $next <= $numpages ) { + $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . ''; /** This filter is documented in wp-includes/post-template.php */ - $link = apply_filters( 'wp_link_pages_link', $link, $i ); - $output .= $separator . $link; + $link = apply_filters( 'wp_link_pages_link', $link, $next ); + $output .= $r['separator'] . $link; } - $output .= $after; + $output .= $r['after']; } } @@ -803,12 +820,12 @@ function wp_link_pages( $args = '' ) { * @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 ); + $html = apply_filters( 'wp_link_pages', $output, $args ); - if ( $echo ) - echo $output; - - return $output; + if ( $r['echo'] ) { + echo $html; + } + return $html; } /** @@ -918,7 +935,7 @@ function the_meta() { * @param array|string $args Optional. Override default arguments. * @return string HTML content, if not displaying. */ -function wp_dropdown_pages($args = '') { +function wp_dropdown_pages( $args = '' ) { $defaults = array( 'depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, @@ -928,21 +945,23 @@ function wp_dropdown_pages($args = '') { ); $r = wp_parse_args( $args, $defaults ); - extract( $r, EXTR_SKIP ); - $pages = get_pages($r); + $pages = get_pages( $r ); $output = ''; // Back-compat with old system where both id and name were based on $name argument - if ( empty($id) ) - $id = $name; - - if ( ! empty($pages) ) { - $output = "\n"; + if ( $r['show_option_no_change'] ) { + $output .= "\t\n"; + } + if ( $r['show_option_none'] ) { + $output .= "\t\n"; + } + $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r ); $output .= "\n"; } @@ -953,12 +972,12 @@ function wp_dropdown_pages($args = '') { * * @param string $output HTML output for drop down list of pages. */ - $output = apply_filters( 'wp_dropdown_pages', $output ); - - if ( $echo ) - echo $output; + $html = apply_filters( 'wp_dropdown_pages', $output ); - return $output; + if ( $r['echo'] ) { + echo $html; + } + return $html; } /** @@ -966,30 +985,56 @@ function wp_dropdown_pages($args = '') { * * @since 1.5.0 * - * @param array|string $args Optional. Override default arguments. - * @return string HTML content, if not displaying. + * @see get_pages() + * + * @param array|string $args { + * Array or string of arguments. Optional. + * + * @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). + * @type string $authors Comma-separated list of author IDs. Default empty (all authors). + * @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. + * Default is the value of 'date_format' option. + * @type int $depth Number of levels in the hierarchy of pages to include in the generated list. + * Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to + * the given n depth). Default 0. + * @type bool $echo Whether or not to echo the list of pages. Default true. + * @type string $exclude Comma-separated list of page IDs to exclude. Default empty. + * @type array $include Comma-separated list of page IDs to include. Default empty. + * @type string $link_after Text or HTML to follow the page link label. Default null. + * @type string $link_before Text or HTML to precede the page link label. Default null. + * @type string $post_type Post type to query for. Default 'page'. + * @type string $post_status Comma-separated list of post statuses to include. Default 'publish'. + * @type string $show_date Whether to display the page publish or modified date for each page. Accepts + * 'modified' or any other value. An empty value hides the date. Default empty. + * @type string $sort_column Comma-separated list of column names to sort the pages by. Accepts 'post_author', + * 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', + * 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. + * @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list + * will not be wrapped with unordered list `