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 = "