--- a/wp/wp-includes/post-template.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/post-template.php Mon Oct 14 18:28:13 2019 +0200
@@ -42,15 +42,17 @@
function the_title( $before = '', $after = '', $echo = true ) {
$title = get_the_title();
- if ( strlen($title) == 0 )
+ if ( strlen( $title ) == 0 ) {
return;
+ }
$title = $before . $title . $after;
- if ( $echo )
+ if ( $echo ) {
echo $title;
- else
+ } else {
return $title;
+ }
}
/**
@@ -76,8 +78,13 @@
* @return string|void 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 );
+ $defaults = array(
+ 'before' => '',
+ 'after' => '',
+ 'echo' => true,
+ 'post' => get_post(),
+ );
+ $r = wp_parse_args( $args, $defaults );
$title = get_the_title( $r['post'] );
@@ -111,7 +118,7 @@
$post = get_post( $post );
$title = isset( $post->post_title ) ? $post->post_title : '';
- $id = isset( $post->ID ) ? $post->ID : 0;
+ $id = isset( $post->ID ) ? $post->ID : 0;
if ( ! is_admin() ) {
if ( ! empty( $post->post_password ) ) {
@@ -128,7 +135,7 @@
* @param WP_Post $post Current post object.
*/
$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );
- $title = sprintf( $protected_title_format, $title );
+ $title = sprintf( $protected_title_format, $title );
} elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) {
/**
@@ -143,7 +150,7 @@
* @param WP_Post $post Current post object.
*/
$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );
- $title = sprintf( $private_title_format, $title );
+ $title = sprintf( $private_title_format, $title );
}
}
@@ -227,7 +234,7 @@
* @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.
*/
-function the_content( $more_link_text = null, $strip_teaser = false) {
+function the_content( $more_link_text = null, $strip_teaser = false ) {
$content = get_the_content( $more_link_text, $strip_teaser );
/**
@@ -246,21 +253,34 @@
* Retrieve the post content.
*
* @since 0.71
+ * @since 5.2.0 Added the `$post` parameter.
*
* @global int $page Page number of a single post/page.
* @global int $more Boolean indicator for whether single post/page is being viewed.
* @global bool $preview Whether post/page is in preview mode.
- * @global array $pages Array of all pages in post/page. Each array element contains part of the content separated by the <!--nextpage--> tag.
+ * @global array $pages Array of all pages in post/page. Each array element contains
+ * part of the content separated by the `<!--nextpage-->` tag.
* @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 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.
* @return string
*/
-function get_the_content( $more_link_text = null, $strip_teaser = false ) {
+function get_the_content( $more_link_text = null, $strip_teaser = false, $post = null ) {
global $page, $more, $preview, $pages, $multipage;
- $post = get_post();
+ $_post = get_post( $post );
+
+ if ( ! ( $_post instanceof WP_Post ) ) {
+ return '';
+ }
+
+ if ( null === $post ) {
+ $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
+ } else {
+ $elements = generate_postdata( $_post );
+ }
if ( null === $more_link_text ) {
$more_link_text = sprintf(
@@ -268,48 +288,65 @@
sprintf(
/* translators: %s: Name of current post */
__( 'Continue reading %s' ),
- the_title_attribute( array( 'echo' => false ) )
+ the_title_attribute(
+ array(
+ 'echo' => false,
+ 'post' => $_post,
+ )
+ )
),
__( '(more…)' )
);
}
- $output = '';
+ $output = '';
$has_teaser = false;
// If post password required and it doesn't match the cookie.
- if ( post_password_required( $post ) )
- return get_the_password_form( $post );
+ if ( post_password_required( $_post ) ) {
+ return get_the_password_form( $_post );
+ }
- if ( $page > count( $pages ) ) // if the requested page doesn't exist
- $page = count( $pages ); // give them the highest numbered page that DOES exist
+ 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
+ }
- $content = $pages[$page - 1];
+ $page_no = $elements['page'];
+ $content = $elements['pages'][ $page_no - 1 ];
if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
+ if ( has_block( 'more', $content ) ) {
+ // Remove the core/more block delimiters. They will be left over after $content is split up.
+ $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
+ }
+
$content = explode( $matches[0], $content, 2 );
- if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
+
+ if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
$more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
+ }
$has_teaser = true;
} else {
$content = array( $content );
}
- if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) )
+ if ( false !== strpos( $_post->post_content, '<!--noteaser-->' ) && ( ! $elements['multipage'] || $elements['page'] == 1 ) ) {
$strip_teaser = true;
+ }
$teaser = $content[0];
- if ( $more && $strip_teaser && $has_teaser )
+ if ( $elements['more'] && $strip_teaser && $has_teaser ) {
$teaser = '';
+ }
$output .= $teaser;
if ( count( $content ) > 1 ) {
- if ( $more ) {
- $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
+ if ( $elements['more'] ) {
+ $output .= '<span id="more-' . $_post->ID . '"></span>' . $content[1];
} else {
- if ( ! empty( $more_link_text ) )
+ if ( ! empty( $more_link_text ) ) {
/**
* Filters the Read More link text.
@@ -319,31 +356,16 @@
* @param string $more_link_element Read More link element.
* @param string $more_link_text Read More text.
*/
- $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
+ $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink( $_post ) . "#more-{$_post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
+ }
$output = force_balance_tags( $output );
}
}
- if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
- $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
-
return $output;
}
/**
- * Preview fix for JavaScript bug with foreign languages.
- *
- * @since 3.1.0
- * @access private
- *
- * @param array $match Match array from preg_replace_callback.
- * @return string
- */
-function _convert_urlencoded_to_entities( $match ) {
- return '&#' . base_convert( $match[1], 16, 10 ) . ';';
-}
-
-/**
* Display the post excerpt.
*
* @since 0.71
@@ -398,7 +420,11 @@
}
/**
- * Whether the post has a custom excerpt.
+ * Determines whether the post has a custom excerpt.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.3.0
*
@@ -407,11 +433,11 @@
*/
function has_excerpt( $post = 0 ) {
$post = get_post( $post );
- return ( !empty( $post->post_excerpt ) );
+ return ( ! empty( $post->post_excerpt ) );
}
/**
- * Display the classes for the post div.
+ * Displays the classes for the post container element.
*
* @since 2.7.0
*
@@ -424,7 +450,7 @@
}
/**
- * Retrieves the classes for the post div as an array.
+ * Retrieves an array of the class names for the post container element.
*
* 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
@@ -433,16 +459,16 @@
* eg 'category-foo' or 'my_custom_taxonomy-bar'.
*
* The 'post_tag' taxonomy is a special
- * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are
- * passed through the filter, {@see 'post_class'}, with the list of classes, followed by
+ * case; the class has the 'tag-' prefix instead of 'post_tag-'. All class names are
+ * passed through the filter, {@see 'post_class'}, with the list of class names, followed by
* $class parameter value, with the post ID as the last parameter.
*
* @since 2.7.0
- * @since 4.2.0 Custom taxonomy classes were added.
+ * @since 4.2.0 Custom taxonomy class names were added.
*
- * @param string|array $class One or more classes to add to the class list.
- * @param int|WP_Post $post_id Optional. Post ID or post object.
- * @return array Array of classes.
+ * @param string|string[] $class Space-separated string or array of class names to add to the class list.
+ * @param int|WP_Post $post_id Optional. Post ID or post object.
+ * @return string[] Array of class names.
*/
function get_post_class( $class = '', $post_id = null ) {
$post = get_post( $post_id );
@@ -464,8 +490,9 @@
}
$classes[] = 'post-' . $post->ID;
- if ( ! is_admin() )
+ if ( ! is_admin() ) {
$classes[] = $post->post_type;
+ }
$classes[] = 'type-' . $post->post_type;
$classes[] = 'status-' . $post->post_status;
@@ -473,10 +500,11 @@
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
$post_format = get_post_format( $post->ID );
- if ( $post_format && !is_wp_error($post_format) )
+ if ( $post_format && ! is_wp_error( $post_format ) ) {
$classes[] = 'format-' . sanitize_html_class( $post_format );
- else
+ } else {
$classes[] = 'format-standard';
+ }
}
$post_password_required = post_password_required( $post->ID );
@@ -532,13 +560,13 @@
$classes = array_map( 'esc_attr', $classes );
/**
- * Filters the list of CSS classes for the current post.
+ * Filters the list of CSS class names for the current post.
*
* @since 2.7.0
*
- * @param array $classes An array of post classes.
- * @param array $class An array of additional classes added to the post.
- * @param int $post_id The post ID.
+ * @param string[] $classes An array of post class names.
+ * @param string[] $class An array of additional class names added to the post.
+ * @param int $post_id The post ID.
*/
$classes = apply_filters( 'post_class', $classes, $class, $post->ID );
@@ -546,57 +574,68 @@
}
/**
- * Display the classes for the body element.
+ * Displays the class names for the body element.
*
* @since 2.8.0
*
- * @param string|array $class One or more classes to add to the class list.
+ * @param string|string[] $class Space-separated string or array of class names to add to the class list.
*/
function body_class( $class = '' ) {
- // Separates classes with a single space, collates classes for body element
+ // Separates class names with a single space, collates class names for body element
echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
}
/**
- * Retrieve the classes for the body element as an array.
+ * Retrieves an array of the class names for the body element.
*
* @since 2.8.0
*
* @global WP_Query $wp_query
*
- * @param string|array $class One or more classes to add to the class list.
- * @return array Array of classes.
+ * @param string|string[] $class Space-separated string or array of class names to add to the class list.
+ * @return string[] Array of class names.
*/
function get_body_class( $class = '' ) {
global $wp_query;
$classes = array();
- if ( is_rtl() )
+ if ( is_rtl() ) {
$classes[] = 'rtl';
+ }
- if ( is_front_page() )
+ if ( is_front_page() ) {
$classes[] = 'home';
- if ( is_home() )
+ }
+ if ( is_home() ) {
$classes[] = 'blog';
- if ( is_archive() )
+ }
+ if ( is_privacy_policy() ) {
+ $classes[] = 'privacy-policy';
+ }
+ if ( is_archive() ) {
$classes[] = 'archive';
- if ( is_date() )
+ }
+ if ( is_date() ) {
$classes[] = 'date';
+ }
if ( is_search() ) {
$classes[] = 'search';
$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
}
- if ( is_paged() )
+ if ( is_paged() ) {
$classes[] = 'paged';
- if ( is_attachment() )
+ }
+ if ( is_attachment() ) {
$classes[] = 'attachment';
- if ( is_404() )
+ }
+ if ( is_404() ) {
$classes[] = 'error404';
+ }
if ( is_singular() ) {
- $post_id = $wp_query->get_queried_object_id();
- $post = $wp_query->get_queried_object();
+ $post_id = $wp_query->get_queried_object_id();
+ $post = $wp_query->get_queried_object();
$post_type = $post->post_type;
if ( is_page_template() ) {
@@ -623,29 +662,35 @@
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
$post_format = get_post_format( $post->ID );
- if ( $post_format && !is_wp_error($post_format) )
+ if ( $post_format && ! is_wp_error( $post_format ) ) {
$classes[] = 'single-format-' . sanitize_html_class( $post_format );
- else
+ } else {
$classes[] = 'single-format-standard';
+ }
}
}
}
if ( is_attachment() ) {
- $mime_type = get_post_mime_type($post_id);
+ $mime_type = get_post_mime_type( $post_id );
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
- $classes[] = 'attachmentid-' . $post_id;
- $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
+ $classes[] = 'attachmentid-' . $post_id;
+ $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
} elseif ( is_page() ) {
$classes[] = 'page';
$page_id = $wp_query->get_queried_object_id();
- $post = get_post($page_id);
+ $post = get_post( $page_id );
$classes[] = 'page-id-' . $page_id;
- if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
+ if ( get_pages(
+ array(
+ 'parent' => $page_id,
+ 'number' => 1,
+ )
+ ) ) {
$classes[] = 'page-parent';
}
@@ -658,18 +703,19 @@
if ( is_post_type_archive() ) {
$classes[] = 'post-type-archive';
$post_type = get_query_var( 'post_type' );
- if ( is_array( $post_type ) )
+ if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
+ }
$classes[] = 'post-type-archive-' . sanitize_html_class( $post_type );
} elseif ( is_author() ) {
- $author = $wp_query->get_queried_object();
+ $author = $wp_query->get_queried_object();
$classes[] = 'author';
if ( isset( $author->user_nicename ) ) {
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID );
$classes[] = 'author-' . $author->ID;
}
} elseif ( is_category() ) {
- $cat = $wp_query->get_queried_object();
+ $cat = $wp_query->get_queried_object();
$classes[] = 'category';
if ( isset( $cat->term_id ) ) {
$cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
@@ -681,7 +727,7 @@
$classes[] = 'category-' . $cat->term_id;
}
} elseif ( is_tag() ) {
- $tag = $wp_query->get_queried_object();
+ $tag = $wp_query->get_queried_object();
$classes[] = 'tag';
if ( isset( $tag->term_id ) ) {
$tag_class = sanitize_html_class( $tag->slug, $tag->term_id );
@@ -707,50 +753,60 @@
}
}
- if ( is_user_logged_in() )
+ if ( is_user_logged_in() ) {
$classes[] = 'logged-in';
+ }
if ( is_admin_bar_showing() ) {
$classes[] = 'admin-bar';
$classes[] = 'no-customize-support';
}
- if ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() )
+ if ( current_theme_supports( 'custom-background' )
+ && ( get_background_color() !== get_theme_support( 'custom-background', 'default-color' ) || get_background_image() ) ) {
$classes[] = 'custom-background';
+ }
if ( has_custom_logo() ) {
$classes[] = 'wp-custom-logo';
}
+ if ( current_theme_supports( 'responsive-embeds' ) ) {
+ $classes[] = 'wp-embed-responsive';
+ }
+
$page = $wp_query->get( 'page' );
- if ( ! $page || $page < 2 )
+ if ( ! $page || $page < 2 ) {
$page = $wp_query->get( 'paged' );
+ }
if ( $page && $page > 1 && ! is_404() ) {
$classes[] = 'paged-' . $page;
- if ( is_single() )
+ if ( is_single() ) {
$classes[] = 'single-paged-' . $page;
- elseif ( is_page() )
+ } elseif ( is_page() ) {
$classes[] = 'page-paged-' . $page;
- elseif ( is_category() )
+ } elseif ( is_category() ) {
$classes[] = 'category-paged-' . $page;
- elseif ( is_tag() )
+ } elseif ( is_tag() ) {
$classes[] = 'tag-paged-' . $page;
- elseif ( is_date() )
+ } elseif ( is_date() ) {
$classes[] = 'date-paged-' . $page;
- elseif ( is_author() )
+ } elseif ( is_author() ) {
$classes[] = 'author-paged-' . $page;
- elseif ( is_search() )
+ } elseif ( is_search() ) {
$classes[] = 'search-paged-' . $page;
- elseif ( is_post_type_archive() )
+ } elseif ( is_post_type_archive() ) {
$classes[] = 'post-type-paged-' . $page;
+ }
}
if ( ! empty( $class ) ) {
- if ( !is_array( $class ) )
+ if ( ! is_array( $class ) ) {
$class = preg_split( '#\s+#', $class );
+ }
$classes = array_merge( $classes, $class );
} else {
// Ensure that we always coerce class to being an array.
@@ -760,12 +816,12 @@
$classes = array_map( 'esc_attr', $classes );
/**
- * Filters the list of CSS body classes for the current post or page.
+ * Filters the list of CSS body class names for the current post or page.
*
* @since 2.8.0
*
- * @param array $classes An array of body classes.
- * @param array $class An array of additional classes added to the body.
+ * @param string[] $classes An array of body class names.
+ * @param string[] $class An array of additional class names added to the body.
*/
$classes = apply_filters( 'body_class', $classes, $class );
@@ -781,7 +837,7 @@
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
*/
function post_password_required( $post = null ) {
- $post = get_post($post);
+ $post = get_post( $post );
if ( empty( $post->post_password ) ) {
/** This filter is documented in wp-includes/post-template.php */
@@ -822,10 +878,11 @@
/**
* The formatted output of a list of pages.
*
- * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
+ * Displays page links for paginated posts (i.e. including the `<!--nextpage-->`
* Quicktag one or more times). This tag must be within The Loop.
*
* @since 1.2.0
+ * @since 5.1.0 Added the `aria_current` argument.
*
* @global int $page
* @global int $numpages
@@ -841,6 +898,8 @@
* 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 `<a>` tag.
* Also appended to the current item, which is not linked. Default empty.
+ * @type string $aria_current The value for the aria-current attribute. Possible values are 'page',
+ * 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
* @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 ' '.
@@ -857,16 +916,17 @@
global $page, $numpages, $multipage, $more;
$defaults = array(
- 'before' => '<p>' . __( 'Pages:' ),
+ 'before' => '<p class="post-nav-links">' . __( 'Pages:' ),
'after' => '</p>',
'link_before' => '',
'link_after' => '',
+ 'aria_current' => 'page',
'next_or_number' => 'number',
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => '%',
- 'echo' => 1
+ 'echo' => 1,
);
$params = wp_parse_args( $args, $defaults );
@@ -888,6 +948,8 @@
$link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after'];
if ( $i != $page || ! $more && 1 == $page ) {
$link = _wp_link_page( $i ) . $link . '</a>';
+ } elseif ( $i === $page ) {
+ $link = '<span class="post-page-numbers current" aria-current="' . esc_attr( $r['aria_current'] ) . '">' . $link . '</span>';
}
/**
* Filters the HTML output of individual page number links.
@@ -906,7 +968,7 @@
$output .= $r['after'];
} elseif ( $more ) {
$output .= $r['before'];
- $prev = $page - 1;
+ $prev = $page - 1;
if ( $prev > 0 ) {
$link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>';
@@ -956,31 +1018,32 @@
*/
function _wp_link_page( $i ) {
global $wp_rewrite;
- $post = get_post();
+ $post = get_post();
$query_args = array();
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' ) ) ) {
$url = add_query_arg( 'page', $i, get_permalink() );
- 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');
+ } 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' );
+ }
}
if ( is_preview() ) {
if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) {
- $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
+ $query_args['preview_id'] = wp_unslash( $_GET['preview_id'] );
$query_args['preview_nonce'] = wp_unslash( $_GET['preview_nonce'] );
}
$url = get_preview_post_link( $post, $query_args, $url );
}
- return '<a href="' . esc_url( $url ) . '">';
+ return '<a href="' . esc_url( $url ) . '" class="post-page-numbers">';
}
//
@@ -998,25 +1061,25 @@
function post_custom( $key = '' ) {
$custom = get_post_custom();
- if ( !isset( $custom[$key] ) )
+ if ( ! isset( $custom[ $key ] ) ) {
return false;
- elseif ( 1 == count($custom[$key]) )
- return $custom[$key][0];
- else
- return $custom[$key];
+ } elseif ( 1 == count( $custom[ $key ] ) ) {
+ return $custom[ $key ][0];
+ } else {
+ return $custom[ $key ];
+ }
}
/**
- * Display list of post custom fields.
+ * Display a list of post custom fields.
*
* @since 1.2.0
*
* @internal This will probably change at some point...
- *
*/
function the_meta() {
if ( $keys = get_post_custom_keys() ) {
- echo "<ul class='post-meta'>\n";
+ $li_html = '';
foreach ( (array) $keys as $key ) {
$keyt = trim( $key );
if ( is_protected_meta( $keyt, 'post' ) ) {
@@ -1024,9 +1087,10 @@
}
$values = array_map( 'trim', get_post_custom_values( $key ) );
- $value = implode( $values, ', ' );
+ $value = implode( $values, ', ' );
- $html = sprintf( "<li><span class='post-meta-key'>%s</span> %s</li>\n",
+ $html = sprintf(
+ "<li><span class='post-meta-key'>%s</span> %s</li>\n",
/* translators: %s: Post custom field name */
sprintf( _x( '%s:', 'Post custom field name' ), $key ),
$value
@@ -1041,9 +1105,12 @@
* @param string $key Meta key.
* @param string $value Meta value.
*/
- echo apply_filters( 'the_meta_key', $html, $key, $value );
+ $li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
}
- echo "</ul>\n";
+
+ if ( $li_html ) {
+ echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
+ }
}
}
@@ -1052,14 +1119,16 @@
//
/**
- * Retrieve or display list of pages as a dropdown (select list).
+ * Retrieve or display a list of pages as a dropdown (select list).
*
* @since 2.1.0
* @since 4.2.0 The `$value_field` argument was added.
* @since 4.3.0 The `$class` argument was added.
*
+ * @see get_pages()
+ *
* @param array|string $args {
- * Optional. Array or string of arguments to generate a pages drop-down element.
+ * Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments.
*
* @type int $depth Maximum depth. Default 0.
* @type int $child_of Page ID to retrieve child pages of. Default 0.
@@ -1081,18 +1150,22 @@
*/
function wp_dropdown_pages( $args = '' ) {
$defaults = array(
- 'depth' => 0, 'child_of' => 0,
- 'selected' => 0, 'echo' => 1,
- 'name' => 'page_id', 'id' => '',
- 'class' => '',
- 'show_option_none' => '', 'show_option_no_change' => '',
- 'option_none_value' => '',
- 'value_field' => 'ID',
+ 'depth' => 0,
+ 'child_of' => 0,
+ 'selected' => 0,
+ 'echo' => 1,
+ 'name' => 'page_id',
+ 'id' => '',
+ 'class' => '',
+ 'show_option_none' => '',
+ 'show_option_no_change' => '',
+ 'option_none_value' => '',
+ 'value_field' => 'ID',
);
$r = wp_parse_args( $args, $defaults );
- $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( $r['id'] ) ) {
@@ -1125,7 +1198,7 @@
* @param string $output HTML output for drop down list of pages.
* @param array $r The parsed arguments array.
* @param array $pages List of WP_Post objects returned by `get_pages()`
- */
+ */
$html = apply_filters( 'wp_dropdown_pages', $output, $r, $pages );
if ( $r['echo'] ) {
@@ -1135,7 +1208,7 @@
}
/**
- * Retrieve or display list of pages (or hierarchical post type items) in list (li) format.
+ * Retrieve or display a list of pages (or hierarchical post type items) in list (li) format.
*
* @since 1.5.0
* @since 4.7.0 Added the `item_spacing` argument.
@@ -1145,7 +1218,7 @@
* @global WP_Query $wp_query
*
* @param array|string $args {
- * Array or string of arguments. Optional.
+ * Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments.
*
* @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).
@@ -1198,7 +1271,7 @@
$r['item_spacing'] = $defaults['item_spacing'];
}
- $output = '';
+ $output = '';
$current_page = 0;
// sanitize, mostly to keep spaces out
@@ -1218,7 +1291,7 @@
// Query pages.
$r['hierarchical'] = 0;
- $pages = get_pages( $r );
+ $pages = get_pages( $r );
if ( ! empty( $pages ) ) {
if ( $r['title_li'] ) {
@@ -1265,7 +1338,7 @@
/**
* Displays or retrieves a list of pages with an optional home link.
*
- * The arguments are listed below and part of the arguments are for wp_list_pages()} function.
+ * The arguments are listed below and part of the arguments are for wp_list_pages() function.
* Check that function for more info on those arguments.
*
* @since 2.7.0
@@ -1273,7 +1346,7 @@
* @since 4.7.0 Added the `item_spacing` argument.
*
* @param array|string $args {
- * Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments.
+ * Optional. Array or string of arguments to generate a page menu. See `wp_list_pages()` for additional arguments.
*
* @type string $sort_column How to sort the list of pages. Accepts post column names.
* Default 'menu_order, post_title'.
@@ -1288,7 +1361,8 @@
* @type string $link_after The HTML or text to append to $show_home text. Default empty.
* @type string $before The HTML or text to prepend to the menu. Default is '<ul>'.
* @type string $after The HTML or text to append to the menu. Default is '</ul>'.
- * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. Default 'discard'.
+ * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve'
+ * or 'discard'. Default 'discard'.
* @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page).
* }
* @return string|void HTML menu
@@ -1307,7 +1381,7 @@
'item_spacing' => 'discard',
'walker' => '',
);
- $args = wp_parse_args( $args, $defaults );
+ $args = wp_parse_args( $args, $defaults );
if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ) ) ) {
// invalid value, fall back to default.
@@ -1338,29 +1412,31 @@
$list_args = $args;
// Show Home in the menu
- if ( ! empty($args['show_home']) ) {
- if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
- $text = __('Home');
- else
+ if ( ! empty( $args['show_home'] ) ) {
+ if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) {
+ $text = __( 'Home' );
+ } else {
$text = $args['show_home'];
+ }
$class = '';
- if ( is_front_page() && !is_paged() )
+ if ( is_front_page() && ! is_paged() ) {
$class = 'class="current_page_item"';
+ }
$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
// If the front page is a page, add it to the exclude list
- if (get_option('show_on_front') == 'page') {
- if ( !empty( $list_args['exclude'] ) ) {
+ if ( get_option( 'show_on_front' ) == 'page' ) {
+ if ( ! empty( $list_args['exclude'] ) ) {
$list_args['exclude'] .= ',';
} else {
$list_args['exclude'] = '';
}
- $list_args['exclude'] .= get_option('page_on_front');
+ $list_args['exclude'] .= get_option( 'page_on_front' );
}
}
- $list_args['echo'] = false;
+ $list_args['echo'] = false;
$list_args['title_li'] = '';
- $menu .= wp_list_pages( $list_args );
+ $menu .= wp_list_pages( $list_args );
$container = sanitize_text_field( $args['container'] );
@@ -1376,7 +1452,7 @@
'wp_page_menu' === $args['fallback_cb'] &&
'ul' !== $container ) {
$args['before'] = "<ul>{$n}";
- $args['after'] = '</ul>';
+ $args['after'] = '</ul>';
}
$menu = $args['before'] . $menu . $args['after'];
@@ -1404,10 +1480,11 @@
* @param array $args An array of arguments.
*/
$menu = apply_filters( 'wp_page_menu', $menu, $args );
- if ( $args['echo'] )
+ if ( $args['echo'] ) {
echo $menu;
- else
+ } else {
return $menu;
+ }
}
//
@@ -1427,18 +1504,20 @@
* @return string
*/
function walk_page_tree( $pages, $depth, $current_page, $r ) {
- if ( empty($r['walker']) )
+ if ( empty( $r['walker'] ) ) {
$walker = new Walker_Page;
- else
+ } else {
$walker = $r['walker'];
+ }
foreach ( (array) $pages as $page ) {
- if ( $page->post_parent )
+ if ( $page->post_parent ) {
$r['pages_with_children'][ $page->post_parent ] = true;
+ }
}
- $args = array($pages, $depth, $r, $current_page);
- return call_user_func_array(array($walker, 'walk'), $args);
+ $args = array( $pages, $depth, $r, $current_page );
+ return call_user_func_array( array( $walker, 'walk' ), $args );
}
/**
@@ -1452,12 +1531,13 @@
*/
function walk_page_dropdown_tree() {
$args = func_get_args();
- if ( empty($args[2]['walker']) ) // the user's options are the third parameter
+ if ( empty( $args[2]['walker'] ) ) { // the user's options are the third parameter
$walker = new Walker_PageDropdown;
- else
+ } else {
$walker = $args[2]['walker'];
+ }
- return call_user_func_array(array($walker, 'walk'), $args);
+ return call_user_func_array( array( $walker, 'walk' ), $args );
}
//
@@ -1475,13 +1555,15 @@
* @param bool $permalink Optional, default is false. Whether to include permalink.
*/
function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
- if ( !empty( $deprecated ) )
+ if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.5.0' );
+ }
- if ( $fullsize )
- echo wp_get_attachment_link($id, 'full', $permalink);
- else
- echo wp_get_attachment_link($id, 'thumbnail', $permalink);
+ if ( $fullsize ) {
+ echo wp_get_attachment_link( $id, 'full', $permalink );
+ } else {
+ echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
+ }
}
/**
@@ -1531,6 +1613,7 @@
* Filters a retrieved attachment page link.
*
* @since 2.7.0
+ * @since 5.1.0 Added the $attr parameter.
*
* @param string $link_html The page link HTML output.
* @param int $id Post ID.
@@ -1539,8 +1622,9 @@
* @param bool $permalink Whether to add permalink to image. Default false.
* @param bool $icon Whether to include an icon. Default false.
* @param string|bool $text If string, will be link text. Default false.
+ * @param array|string $attr Array or string of attributes. Default empty.
*/
- return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text );
+ return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
}
/**
@@ -1551,17 +1635,18 @@
* @param string $content
* @return string
*/
-function prepend_attachment($content) {
+function prepend_attachment( $content ) {
$post = get_post();
- if ( empty($post->post_type) || $post->post_type != 'attachment' )
+ if ( empty( $post->post_type ) || $post->post_type != 'attachment' ) {
return $content;
+ }
if ( wp_attachment_is( 'video', $post ) ) {
$meta = wp_get_attachment_metadata( get_the_ID() );
$atts = array( 'src' => wp_get_attachment_url() );
if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
- $atts['width'] = (int) $meta['width'];
+ $atts['width'] = (int) $meta['width'];
$atts['height'] = (int) $meta['height'];
}
if ( has_post_thumbnail() ) {
@@ -1573,7 +1658,7 @@
} else {
$p = '<p class="attachment">';
// show the medium sized image representation of the attachment if available, and link to the raw file
- $p .= wp_get_attachment_link(0, 'medium', false);
+ $p .= wp_get_attachment_link( 0, 'medium', false );
$p .= '</p>';
}
@@ -1604,8 +1689,8 @@
* @return string HTML content for password form for password protected post.
*/
function get_the_password_form( $post = 0 ) {
- $post = get_post( $post );
- $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
+ $post = get_post( $post );
+ $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
@@ -1626,12 +1711,16 @@
}
/**
- * Whether currently in a page template.
+ * Determines whether currently in a page template.
*
* This template tag allows you to determine if you are in a page template.
* You can optionally provide a template name or array of template names
* and then the check will be specific to that template.
*
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
+ *
* @since 2.5.0
* @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
* @since 4.7.0 Now works with any post type, not just pages.
@@ -1646,11 +1735,13 @@
$page_template = get_page_template_slug( get_queried_object_id() );
- if ( empty( $template ) )
+ if ( empty( $template ) ) {
return (bool) $page_template;
+ }
- if ( $template == $page_template )
+ if ( $template == $page_template ) {
return true;
+ }
if ( is_array( $template ) ) {
if ( ( in_array( 'default', $template, true ) && ! $page_template )
@@ -1671,7 +1762,7 @@
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @return string|false Page template filename. Returns an empty string when the default page template
- * is in use. Returns false if the post does not exist.
+ * is in use. Returns false if the post does not exist.
*/
function get_page_template_slug( $post = null ) {
$post = get_post( $post );
@@ -1699,27 +1790,31 @@
* @return string|false i18n formatted datetimestamp or localized 'Current Revision'.
*/
function wp_post_revision_title( $revision, $link = true ) {
- if ( !$revision = get_post( $revision ) )
+ if ( ! $revision = get_post( $revision ) ) {
return $revision;
+ }
- if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
+ if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
return false;
+ }
/* translators: revision date format, see https://secure.php.net/date */
$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
/* translators: %s: revision date */
$autosavef = __( '%s [Autosave]' );
/* translators: %s: revision date */
- $currentf = __( '%s [Current Revision]' );
+ $currentf = __( '%s [Current Revision]' );
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
- if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
+ if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
$date = "<a href='$link'>$date</a>";
+ }
- if ( !wp_is_post_revision( $revision ) )
+ if ( ! wp_is_post_revision( $revision ) ) {
$date = sprintf( $currentf, $date );
- elseif ( wp_is_post_autosave( $revision ) )
+ } elseif ( wp_is_post_autosave( $revision ) ) {
$date = sprintf( $autosavef, $date );
+ }
return $date;
}
@@ -1734,11 +1829,13 @@
* @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'.
*/
function wp_post_revision_title_expanded( $revision, $link = true ) {
- if ( !$revision = get_post( $revision ) )
+ if ( ! $revision = get_post( $revision ) ) {
return $revision;
+ }
- if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
+ if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) {
return false;
+ }
$author = get_the_author_meta( 'display_name', $revision->post_author );
/* translators: revision date format, see https://secure.php.net/date */
@@ -1747,8 +1844,9 @@
$gravatar = get_avatar( $revision->post_author, 24 );
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
- if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
+ if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) {
$date = "<a href='$link'>$date</a>";
+ }
$revision_date_author = sprintf(
/* translators: post revision title: 1: author avatar, 2: author name, 3: time ago, 4: date */
@@ -1762,12 +1860,13 @@
/* translators: %s: revision date with author avatar */
$autosavef = __( '%s [Autosave]' );
/* translators: %s: revision date with author avatar */
- $currentf = __( '%s [Current Revision]' );
+ $currentf = __( '%s [Current Revision]' );
- if ( !wp_is_post_revision( $revision ) )
+ if ( ! wp_is_post_revision( $revision ) ) {
$revision_date_author = sprintf( $currentf, $revision_date_author );
- elseif ( wp_is_post_autosave( $revision ) )
+ } elseif ( wp_is_post_autosave( $revision ) ) {
$revision_date_author = sprintf( $autosavef, $revision_date_author );
+ }
/**
* Filters the formatted author and date for a revision.
@@ -1783,7 +1882,7 @@
}
/**
- * Display list of a post's revisions.
+ * Display a list of a post's revisions.
*
* Can output either a UL with edit links or a TABLE with diff interface, and
* restore action links.
@@ -1794,26 +1893,30 @@
* @param string $type 'all' (default), 'revision' or 'autosave'
*/
function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
- if ( ! $post = get_post( $post_id ) )
+ if ( ! $post = get_post( $post_id ) ) {
return;
+ }
// $args array with (parent, format, right, left, type) deprecated since 3.6
if ( is_array( $type ) ) {
- $type = ! empty( $type['type'] ) ? $type['type'] : $type;
+ $type = ! empty( $type['type'] ) ? $type['type'] : $type;
_deprecated_argument( __FUNCTION__, '3.6.0' );
}
- if ( ! $revisions = wp_get_post_revisions( $post->ID ) )
+ if ( ! $revisions = wp_get_post_revisions( $post->ID ) ) {
return;
+ }
$rows = '';
foreach ( $revisions as $revision ) {
- if ( ! current_user_can( 'read_post', $revision->ID ) )
+ if ( ! current_user_can( 'read_post', $revision->ID ) ) {
continue;
+ }
$is_autosave = wp_is_post_autosave( $revision );
- if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) )
+ if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
continue;
+ }
$rows .= "\t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>\n";
}
@@ -1822,5 +1925,5 @@
echo "<ul class='post-revisions hide-if-no-js'>\n";
echo $rows;
- echo "</ul>";
+ echo '</ul>';
}