diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/post-template.php
--- a/wp/wp-includes/post-template.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/post-template.php Tue Dec 15 13:49:49 2020 +0100
@@ -13,7 +13,7 @@
*
* @since 0.71
*/
-function the_ID() {
+function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
echo get_the_ID();
}
@@ -24,7 +24,7 @@
*
* @return int|false The ID of the current item in the WordPress Loop. False if $post is not set.
*/
-function get_the_ID() {
+function get_the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
$post = get_post();
return ! empty( $post ) ? $post->ID : false;
}
@@ -37,7 +37,7 @@
* @param string $before Optional. Markup to prepend to the title. Default empty.
* @param string $after Optional. Markup to append to the title. Default empty.
* @param bool $echo Optional. Whether to echo or return the title. Default true for echo.
- * @return string|void Current post title if $echo is false.
+ * @return void|string Void if `$echo` argument is true, current post title if `$echo` is false.
*/
function the_title( $before = '', $after = '', $echo = true ) {
$title = get_the_title();
@@ -75,27 +75,27 @@
* @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|void String when echo is false.
+ * @return void|string Void if 'echo' argument is true, the title attribute if 'echo' is false.
*/
function the_title_attribute( $args = '' ) {
- $defaults = array(
+ $defaults = array(
'before' => '',
'after' => '',
'echo' => true,
'post' => get_post(),
);
- $r = wp_parse_args( $args, $defaults );
+ $parsed_args = wp_parse_args( $args, $defaults );
- $title = get_the_title( $r['post'] );
+ $title = get_the_title( $parsed_args['post'] );
if ( strlen( $title ) == 0 ) {
return;
}
- $title = $r['before'] . $title . $r['after'];
+ $title = $parsed_args['before'] . $title . $parsed_args['after'];
$title = esc_attr( strip_tags( $title ) );
- if ( $r['echo'] ) {
+ if ( $parsed_args['echo'] ) {
echo $title;
} else {
return $title;
@@ -123,6 +123,9 @@
if ( ! is_admin() ) {
if ( ! empty( $post->post_password ) ) {
+ /* translators: %s: Protected post title. */
+ $prepend = __( 'Protected: %s' );
+
/**
* Filters the text prepended to the post title for protected posts.
*
@@ -134,9 +137,12 @@
* Default 'Protected: %s'.
* @param WP_Post $post Current post object.
*/
- $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
+ $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
$title = sprintf( $protected_title_format, $title );
- } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
+ } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
+
+ /* translators: %s: Private post title. */
+ $prepend = __( 'Private: %s' );
/**
* Filters the text prepended to the post title of private posts.
@@ -149,7 +155,7 @@
* Default 'Private: %s'.
* @param WP_Post $post Current post object.
*/
- $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
+ $private_title_format = apply_filters( 'private_title_format', $prepend, $post );
$title = sprintf( $private_title_format, $title );
}
}
@@ -232,7 +238,7 @@
* @since 0.71
*
* @param string $more_link_text Optional. Content for when there is more text.
- * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false.
*/
function the_content( $more_link_text = null, $strip_teaser = false ) {
$content = get_the_content( $more_link_text, $strip_teaser );
@@ -263,8 +269,8 @@
* @global int $multipage Boolean indicator for whether multiple pages are in play.
*
* @param string $more_link_text Optional. Content for when there is more text.
- * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
- * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default is null.
+ * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false.
+ * @param WP_Post|object|int $post Optional. WP_Post instance or Post ID/object. Default null.
* @return string
*/
function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
@@ -276,7 +282,9 @@
return '';
}
- if ( null === $post ) {
+ // Use the globals if the $post parameter was not specified,
+ // but only after they have been set up in setup_postdata().
+ if ( null === $post && did_action( 'the_post' ) ) {
$elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
} else {
$elements = generate_postdata( $_post );
@@ -286,7 +294,7 @@
$more_link_text = sprintf(
'%2$s',
sprintf(
- /* translators: %s: Name of current post */
+ /* translators: %s: Post title. */
__( 'Continue reading %s' ),
the_title_attribute(
array(
@@ -307,8 +315,10 @@
return get_the_password_form( $_post );
}
- if ( $elements['page'] > count( $elements['pages'] ) ) { // if the requested page doesn't exist
- $elements['page'] = count( $elements['pages'] ); // give them the highest numbered page that DOES exist
+ // If the requested page doesn't exist.
+ if ( $elements['page'] > count( $elements['pages'] ) ) {
+ // Give them the highest numbered page that DOES exist.
+ $elements['page'] = count( $elements['pages'] );
}
$page_no = $elements['page'];
@@ -330,7 +340,7 @@
$content = array( $content );
}
- if ( false !== strpos( $_post->post_content, '' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
+ if ( false !== strpos( $_post->post_content, '' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) {
$strip_teaser = true;
}
@@ -413,8 +423,8 @@
* @since 1.2.0
* @since 4.5.0 Introduced the `$post` parameter.
*
- * @param string $post_excerpt The post excerpt.
- * @param WP_Post $post Post object.
+ * @param string $post_excerpt The post excerpt.
+ * @param WP_Post $post Post object.
*/
return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
}
@@ -445,8 +455,8 @@
* @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`.
*/
function post_class( $class = '', $post_id = null ) {
- // Separates classes with a single space, collates classes for post DIV
- echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
+ // Separates classes with a single space, collates classes for post DIV.
+ echo 'class="' . esc_attr( join( ' ', get_post_class( $class, $post_id ) ) ) . '"';
}
/**
@@ -496,7 +506,7 @@
$classes[] = 'type-' . $post->post_type;
$classes[] = 'status-' . $post->post_status;
- // Post Format
+ // Post Format.
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
$post_format = get_post_format( $post->ID );
@@ -521,7 +531,7 @@
$classes[] = 'has-post-thumbnail';
}
- // sticky for Sticky Posts
+ // Sticky for Sticky Posts.
if ( is_sticky( $post->ID ) ) {
if ( is_home() && ! is_paged() ) {
$classes[] = 'sticky';
@@ -530,10 +540,10 @@
}
}
- // hentry for hAtom compliance
+ // hentry for hAtom compliance.
$classes[] = 'hentry';
- // All public taxonomies
+ // All public taxonomies.
$taxonomies = get_taxonomies( array( 'public' => true ) );
foreach ( (array) $taxonomies as $taxonomy ) {
if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
@@ -548,7 +558,7 @@
}
// 'post_tag' uses the 'tag' prefix for backward compatibility.
- if ( 'post_tag' == $taxonomy ) {
+ if ( 'post_tag' === $taxonomy ) {
$classes[] = 'tag-' . $term_class;
} else {
$classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id );
@@ -581,8 +591,8 @@
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
*/
function body_class( $class = '' ) {
- // Separates class names with a single space, collates class names for body element
- echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
+ // Separates class names with a single space, collates class names for body element.
+ echo 'class="' . esc_attr( join( ' ', get_body_class( $class ) ) ) . '"';
}
/**
@@ -590,7 +600,7 @@
*
* @since 2.8.0
*
- * @global WP_Query $wp_query
+ * @global WP_Query $wp_query WordPress Query object.
*
* @param string|string[] $class Space-separated string or array of class names to add to the class list.
* @return string[] Array of class names.
@@ -658,7 +668,7 @@
$classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
$classes[] = 'postid-' . $post_id;
- // Post Format
+ // Post Format.
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
$post_format = get_post_format( $post->ID );
@@ -872,7 +882,7 @@
}
//
-// Page Template Functions for usage in Themes
+// Page Template Functions for usage in Themes.
//
/**
@@ -929,27 +939,27 @@
'echo' => 1,
);
- $params = wp_parse_args( $args, $defaults );
+ $parsed_args = wp_parse_args( $args, $defaults );
/**
* Filters the arguments used in retrieving page links for paginated posts.
*
* @since 3.0.0
*
- * @param array $params An array of arguments for page links for paginated posts.
+ * @param array $parsed_args An array of arguments for page links for paginated posts.
*/
- $r = apply_filters( 'wp_link_pages_args', $params );
+ $parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
$output = '';
if ( $multipage ) {
- if ( 'number' == $r['next_or_number'] ) {
- $output .= $r['before'];
+ if ( 'number' === $parsed_args['next_or_number'] ) {
+ $output .= $parsed_args['before'];
for ( $i = 1; $i <= $numpages; $i++ ) {
- $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
+ $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after'];
if ( $i != $page || ! $more && 1 == $page ) {
$link = _wp_link_page( $i ) . $link . '';
} elseif ( $i === $page ) {
- $link = '' . $link . '';
+ $link = '' . $link . '';
}
/**
* Filters the HTML output of individual page number links.
@@ -962,15 +972,15 @@
$link = apply_filters( 'wp_link_pages_link', $link, $i );
// Use the custom links separator beginning with the second link.
- $output .= ( 1 === $i ) ? ' ' : $r['separator'];
+ $output .= ( 1 === $i ) ? ' ' : $parsed_args['separator'];
$output .= $link;
}
- $output .= $r['after'];
+ $output .= $parsed_args['after'];
} elseif ( $more ) {
- $output .= $r['before'];
+ $output .= $parsed_args['before'];
$prev = $page - 1;
if ( $prev > 0 ) {
- $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '';
+ $link = _wp_link_page( $prev ) . $parsed_args['link_before'] . $parsed_args['previouspagelink'] . $parsed_args['link_after'] . '';
/** This filter is documented in wp-includes/post-template.php */
$output .= apply_filters( 'wp_link_pages_link', $link, $prev );
@@ -978,14 +988,14 @@
$next = $page + 1;
if ( $next <= $numpages ) {
if ( $prev ) {
- $output .= $r['separator'];
+ $output .= $parsed_args['separator'];
}
- $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '';
+ $link = _wp_link_page( $next ) . $parsed_args['link_before'] . $parsed_args['nextpagelink'] . $parsed_args['link_after'] . '';
/** This filter is documented in wp-includes/post-template.php */
$output .= apply_filters( 'wp_link_pages_link', $link, $next );
}
- $output .= $r['after'];
+ $output .= $parsed_args['after'];
}
}
@@ -999,7 +1009,7 @@
*/
$html = apply_filters( 'wp_link_pages', $output, $args );
- if ( $r['echo'] ) {
+ if ( $parsed_args['echo'] ) {
echo $html;
}
return $html;
@@ -1011,7 +1021,7 @@
* @since 3.1.0
* @access private
*
- * @global WP_Rewrite $wp_rewrite
+ * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @param int $i Page number.
* @return string Link.
@@ -1024,9 +1034,9 @@
if ( 1 == $i ) {
$url = get_permalink();
} else {
- if ( '' == get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ) ) ) {
+ if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
$url = add_query_arg( 'page', $i, get_permalink() );
- } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
+ } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
} else {
$url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' );
@@ -1056,14 +1066,15 @@
* @since 1.5.0
*
* @param string $key Meta data key name.
- * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
+ * @return array|string|false Array of values, or single value if only one element exists.
+ * False if the key does not exist.
*/
function post_custom( $key = '' ) {
$custom = get_post_custom();
if ( ! isset( $custom[ $key ] ) ) {
return false;
- } elseif ( 1 == count( $custom[ $key ] ) ) {
+ } elseif ( 1 === count( $custom[ $key ] ) ) {
return $custom[ $key ][0];
} else {
return $custom[ $key ];
@@ -1078,7 +1089,8 @@
* @internal This will probably change at some point...
*/
function the_meta() {
- if ( $keys = get_post_custom_keys() ) {
+ $keys = get_post_custom_keys();
+ if ( $keys ) {
$li_html = '';
foreach ( (array) $keys as $key ) {
$keyt = trim( $key );
@@ -1087,11 +1099,11 @@
}
$values = array_map( 'trim', get_post_custom_values( $key ) );
- $value = implode( $values, ', ' );
+ $value = implode( ', ', $values );
$html = sprintf(
"
%s %s\n",
- /* translators: %s: Post custom field name */
+ /* translators: %s: Post custom field name. */
sprintf( _x( '%s:', 'Post custom field name' ), $key ),
$value
);
@@ -1115,7 +1127,7 @@
}
//
-// Pages
+// Pages.
//
/**
@@ -1146,7 +1158,7 @@
* @type string $value_field Post field used to populate the 'value' attribute of the option
* elements. Accepts any valid post field. Default 'ID'.
* }
- * @return string HTML content, if not displaying.
+ * @return string HTML dropdown list of pages.
*/
function wp_dropdown_pages( $args = '' ) {
$defaults = array(
@@ -1163,29 +1175,29 @@
'value_field' => 'ID',
);
- $r = wp_parse_args( $args, $defaults );
+ $parsed_args = wp_parse_args( $args, $defaults );
- $pages = get_pages( $r );
+ $pages = get_pages( $parsed_args );
$output = '';
- // Back-compat with old system where both id and name were based on $name argument
- if ( empty( $r['id'] ) ) {
- $r['id'] = $r['name'];
+ // Back-compat with old system where both id and name were based on $name argument.
+ if ( empty( $parsed_args['id'] ) ) {
+ $parsed_args['id'] = $parsed_args['name'];
}
if ( ! empty( $pages ) ) {
$class = '';
- if ( ! empty( $r['class'] ) ) {
- $class = " class='" . esc_attr( $r['class'] ) . "'";
+ if ( ! empty( $parsed_args['class'] ) ) {
+ $class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
}
- $output = "