wp/wp-includes/post-template.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-includes/post-template.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/post-template.php	Wed Sep 21 18:19:35 2022 +0200
@@ -451,12 +451,12 @@
  *
  * @since 2.7.0
  *
- * @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. Defaults to the global `$post`.
+ * @param string|string[] $class   One or more classes to add to the class list.
+ * @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="' . esc_attr( join( ' ', get_post_class( $class, $post_id ) ) ) . '"';
+	echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"';
 }
 
 /**
@@ -592,7 +592,7 @@
  */
 function 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 ) ) ) . '"';
+	echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"';
 }
 
 /**
@@ -876,7 +876,7 @@
 	 *
 	 * @param bool    $required Whether the user needs to supply a password. True if password has not been
 	 *                          provided or is incorrect, false if password has been supplied or is not required.
-	 * @param WP_Post $post     Post data.
+	 * @param WP_Post $post     Post object.
 	 */
 	return apply_filters( 'post_password_required', $required, $post );
 }
@@ -946,7 +946,8 @@
 	 *
 	 * @since 3.0.0
 	 *
-	 * @param array $parsed_args An array of arguments for page links for paginated posts.
+	 * @param array $parsed_args An array of page link arguments. See wp_link_pages()
+	 *                           for information on accepted arguments.
 	 */
 	$parsed_args = apply_filters( 'wp_link_pages_args', $parsed_args );
 
@@ -1005,7 +1006,8 @@
 	 * @since 3.6.0
 	 *
 	 * @param string $output HTML output of paginated posts' page links.
-	 * @param array  $args   An array of arguments.
+	 * @param array  $args   An array of arguments. See wp_link_pages()
+	 *                       for information on accepted arguments.
 	 */
 	$html = apply_filters( 'wp_link_pages', $output, $args );
 
@@ -1208,7 +1210,8 @@
 	 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments.
 	 *
 	 * @param string    $output      HTML output for drop down list of pages.
-	 * @param array     $parsed_args The parsed arguments array.
+	 * @param array     $parsed_args The parsed arguments array. See wp_dropdown_pages()
+	 *                               for information on accepted arguments.
 	 * @param WP_Post[] $pages       Array of the page objects.
 	 */
 	$html = apply_filters( 'wp_dropdown_pages', $output, $parsed_args, $pages );
@@ -1337,7 +1340,8 @@
 	 * @see wp_list_pages()
 	 *
 	 * @param string    $output      HTML output of the pages list.
-	 * @param array     $parsed_args An array of page-listing arguments.
+	 * @param array     $parsed_args An array of page-listing arguments. See wp_list_pages()
+	 *                               for information on accepted arguments.
 	 * @param WP_Post[] $pages       Array of the page objects.
 	 */
 	$html = apply_filters( 'wp_list_pages', $output, $parsed_args, $pages );
@@ -1417,7 +1421,8 @@
 	 *
 	 * @see wp_page_menu()
 	 *
-	 * @param array $args An array of page menu arguments.
+	 * @param array $args An array of page menu arguments. See wp_page_menu()
+	 *                    for information on accepted arguments.
 	 */
 	$args = apply_filters( 'wp_page_menu_args', $args );
 
@@ -1491,7 +1496,8 @@
 	 * @see wp_page_menu()
 	 *
 	 * @param string $menu The HTML output.
-	 * @param array  $args An array of arguments.
+	 * @param array  $args An array of arguments. See wp_page_menu()
+	 *                     for information on accepted arguments.
 	 */
 	$menu = apply_filters( 'wp_page_menu', $menu, $args );
 
@@ -1596,9 +1602,8 @@
  * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
  *
  * @param int|WP_Post  $id        Optional. Post ID or post object.
- * @param string|array $size      Optional. Image size. Accepts any valid image size, or an array
- *                                of width and height values in pixels (in that order).
- *                                Default 'thumbnail'.
+ * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
+ *                                of width and height values in pixels (in that order). Default 'thumbnail'.
  * @param bool         $permalink Optional. Whether to add permalink to image. Default false.
  * @param bool         $icon      Optional. Whether the attachment is an icon. Default false.
  * @param string|false $text      Optional. Link text to use. Activated by passing a string, false otherwise.
@@ -1638,16 +1643,16 @@
 	 * Filters a retrieved attachment page link.
 	 *
 	 * @since 2.7.0
-	 * @since 5.1.0 Added the $attr parameter.
+	 * @since 5.1.0 Added the `$attr` parameter.
 	 *
 	 * @param string       $link_html The page link HTML output.
 	 * @param int          $id        Post ID.
-	 * @param string|array $size      Size of the image. Image size or array of width and height values (in that order).
-	 *                                Default 'thumbnail'.
+	 * @param string|int[] $size      Requested image size. Can be any registered image size name, or
+	 *                                an array of width and height values in pixels (in that order).
 	 * @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.
+	 * @param bool         $icon      Whether to include an icon.
+	 * @param string|false $text      If string, will be link text.
+	 * @param array|string $attr      Array or string of attributes.
 	 */
 	return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
 }
@@ -1729,10 +1734,12 @@
 	 * size attribute in the form input.
 	 *
 	 * @since 2.7.0
+	 * @since 5.8.0 Added the `$post` parameter.
 	 *
-	 * @param string $output The password form HTML output.
+	 * @param string  $output The password form HTML output.
+	 * @param WP_Post $post   Post object.
 	 */
-	return apply_filters( 'the_password_form', $output );
+	return apply_filters( 'the_password_form', $output, $post );
 }
 
 /**
@@ -1750,7 +1757,7 @@
  * @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.
  *
- * @param string|array $template The specific template filename or array of templates to match.
+ * @param string|string[] $template The specific template filename or array of templates to match.
  * @return bool True on success, false on failure.
  */
 function is_page_template( $template = '' ) {
@@ -1824,7 +1831,7 @@
 		return false;
 	}
 
-	/* translators: Revision date format, see https://www.php.net/date */
+	/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
 	/* translators: %s: Revision date. */
 	$autosavef = __( '%s [Autosave]' );
@@ -1866,7 +1873,7 @@
 	}
 
 	$author = get_the_author_meta( 'display_name', $revision->post_author );
-	/* translators: Revision date format, see https://www.php.net/date */
+	/* translators: Revision date format, see https://www.php.net/manual/datetime.format.php */
 	$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
 
 	$gravatar = get_avatar( $revision->post_author, 24 );
@@ -1958,3 +1965,28 @@
 	echo $rows;
 	echo '</ul>';
 }
+
+/**
+ * Retrieves the parent post object for the given post.
+ *
+ * @since 5.7.0
+ *
+ * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
+ * @return WP_Post|null Parent post object, or null if there isn't one.
+ */
+function get_post_parent( $post = null ) {
+	$wp_post = get_post( $post );
+	return ! empty( $wp_post->post_parent ) ? get_post( $wp_post->post_parent ) : null;
+}
+
+/**
+ * Returns whether the given post has a parent post.
+ *
+ * @since 5.7.0
+ *
+ * @param int|WP_Post|null $post Optional. Post ID or WP_Post object. Default is global $post.
+ * @return bool Whether the post has a parent post.
+ */
+function has_post_parent( $post = null ) {
+	return (bool) get_post_parent( $post );
+}