diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/post-template.php --- a/wp/wp-includes/post-template.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/post-template.php Fri Sep 05 18:40:08 2025 +0200 @@ -34,21 +34,22 @@ * * @since 0.71 * - * @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 void|string Void if `$echo` argument is true, current post title if `$echo` is false. + * @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 $display Optional. Whether to echo or return the title. Default true for echo. + * @return void|string Void if `$display` argument is true or the title is empty, + * current post title if `$display` is false. */ -function the_title( $before = '', $after = '', $echo = true ) { +function the_title( $before = '', $after = '', $display = true ) { $title = get_the_title(); - if ( strlen( $title ) == 0 ) { + if ( strlen( $title ) === 0 ) { return; } $title = $before . $title . $after; - if ( $echo ) { + if ( $display ) { echo $title; } else { return $title; @@ -88,7 +89,7 @@ $title = get_the_title( $parsed_args['post'] ); - if ( strlen( $title ) == 0 ) { + if ( strlen( $title ) === 0 ) { return; } @@ -117,8 +118,8 @@ function get_the_title( $post = 0 ) { $post = get_post( $post ); - $title = isset( $post->post_title ) ? $post->post_title : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_title = isset( $post->post_title ) ? $post->post_title : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; if ( ! is_admin() ) { if ( ! empty( $post->post_password ) ) { @@ -138,7 +139,8 @@ * @param WP_Post $post Current post object. */ $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); - $title = sprintf( $protected_title_format, $title ); + + $post_title = sprintf( $protected_title_format, $post_title ); } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { /* translators: %s: Private post title. */ @@ -156,7 +158,8 @@ * @param WP_Post $post Current post object. */ $private_title_format = apply_filters( 'private_title_format', $prepend, $post ); - $title = sprintf( $private_title_format, $title ); + + $post_title = sprintf( $private_title_format, $post_title ); } } @@ -165,10 +168,10 @@ * * @since 0.71 * - * @param string $title The post title. - * @param int $id The post ID. + * @param string $post_title The post title. + * @param int $post_id The post ID. */ - return apply_filters( 'the_title', $title, $id ); + return apply_filters( 'the_title', $post_title, $post_id ); } /** @@ -187,8 +190,8 @@ function the_guid( $post = 0 ) { $post = get_post( $post ); - $guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; /** * Filters the escaped Global Unique Identifier (guid) of the post. @@ -197,10 +200,10 @@ * * @see get_the_guid() * - * @param string $guid Escaped Global Unique Identifier (guid) of the post. - * @param int $id The post ID. + * @param string $post_guid Escaped Global Unique Identifier (guid) of the post. + * @param int $post_id The post ID. */ - echo apply_filters( 'the_guid', $guid, $id ); + echo apply_filters( 'the_guid', $post_guid, $post_id ); } /** @@ -218,18 +221,18 @@ function get_the_guid( $post = 0 ) { $post = get_post( $post ); - $guid = isset( $post->guid ) ? $post->guid : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_guid = isset( $post->guid ) ? $post->guid : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; /** * Filters the Global Unique Identifier (guid) of the post. * * @since 1.5.0 * - * @param string $guid Global Unique Identifier (guid) of the post. - * @param int $id The post ID. + * @param string $post_guid Global Unique Identifier (guid) of the post. + * @param int $post_id The post ID. */ - return apply_filters( 'get_the_guid', $guid, $id ); + return apply_filters( 'get_the_guid', $post_guid, $post_id ); } /** @@ -282,8 +285,10 @@ return ''; } - // Use the globals if the $post parameter was not specified, - // but only after they have been set up in setup_postdata(). + /* + * 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 { @@ -340,7 +345,9 @@ $content = array( $content ); } - if ( false !== strpos( $_post->post_content, '' ) && ( ! $elements['multipage'] || 1 == $elements['page'] ) ) { + if ( str_contains( $_post->post_content, '' ) + && ( ! $elements['multipage'] || 1 === $elements['page'] ) + ) { $strip_teaser = true; } @@ -451,48 +458,52 @@ * * @since 2.7.0 * - * @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`. + * @param string|string[] $css_class Optional. One or more classes to add to the class list. + * Default empty. + * @param int|WP_Post $post Optional. Post ID or post object. Defaults to the global `$post`. */ -function post_class( $class = '', $post_id = null ) { +function post_class( $css_class = '', $post = null ) { // Separates classes with a single space, collates classes for post DIV. - echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"'; + echo 'class="' . esc_attr( implode( ' ', get_post_class( $css_class, $post ) ) ) . '"'; } /** * 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 - * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that - * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' - - * eg 'category-foo' or 'my_custom_taxonomy-bar'. + * The class names are many: * - * The 'post_tag' taxonomy is a special - * 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. + * - If the post has a post thumbnail, `has-post-thumbnail` is added as a class. + * - If the post is sticky, then the `sticky` class name is added. + * - The class `hentry` is always added to each post. + * - For each taxonomy that the post belongs to, a class will be added of the format + * `{$taxonomy}-{$slug}`, e.g. `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 class names are passed through the filter, {@see 'post_class'}, followed by + * `$css_class` parameter value, with the post ID as the last parameter. * * @since 2.7.0 * @since 4.2.0 Custom taxonomy class names were added. * - * @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. + * @param string|string[] $css_class Optional. Space-separated string or array of class names + * to add to the class list. Default empty. + * @param int|WP_Post $post 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 ); +function get_post_class( $css_class = '', $post = null ) { + $post = get_post( $post ); $classes = array(); - if ( $class ) { - if ( ! is_array( $class ) ) { - $class = preg_split( '#\s+#', $class ); + if ( $css_class ) { + if ( ! is_array( $css_class ) ) { + $css_class = preg_split( '#\s+#', $css_class ); } - $classes = array_map( 'esc_attr', $class ); + $classes = array_map( 'esc_attr', $css_class ); } else { // Ensure that we always coerce class to being an array. - $class = array(); + $css_class = array(); } if ( ! $post ) { @@ -545,6 +556,21 @@ // All public taxonomies. $taxonomies = get_taxonomies( array( 'public' => true ) ); + + /** + * Filters the taxonomies to generate classes for each individual term. + * + * Default is all public taxonomies registered to the post type. + * + * @since 6.1.0 + * + * @param string[] $taxonomies List of all taxonomy names to generate classes for. + * @param int $post_id The post ID. + * @param string[] $classes An array of post class names. + * @param string[] $css_class An array of additional class names added to the post. + */ + $taxonomies = apply_filters( 'post_class_taxonomies', $taxonomies, $post->ID, $classes, $css_class ); + foreach ( (array) $taxonomies as $taxonomy ) { if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { @@ -574,11 +600,11 @@ * * @since 2.7.0 * - * @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. + * @param string[] $classes An array of post class names. + * @param string[] $css_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 ); + $classes = apply_filters( 'post_class', $classes, $css_class, $post->ID ); return array_unique( $classes ); } @@ -588,11 +614,12 @@ * * @since 2.8.0 * - * @param string|string[] $class Space-separated string or array of class names to add to the class list. + * @param string|string[] $css_class Optional. Space-separated string or array of class names + * to add to the class list. Default empty. */ -function body_class( $class = '' ) { +function body_class( $css_class = '' ) { // Separates class names with a single space, collates class names for body element. - echo 'class="' . esc_attr( implode( ' ', get_body_class( $class ) ) ) . '"'; + echo 'class="' . esc_attr( implode( ' ', get_body_class( $css_class ) ) ) . '"'; } /** @@ -602,10 +629,11 @@ * * @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. + * @param string|string[] $css_class Optional. Space-separated string or array of class names + * to add to the class list. Default empty. * @return string[] Array of class names. */ -function get_body_class( $class = '' ) { +function get_body_class( $css_class = '' ) { global $wp_query; $classes = array(); @@ -644,8 +672,8 @@ } if ( is_singular() ) { - $post_id = $wp_query->get_queried_object_id(); $post = $wp_query->get_queried_object(); + $post_id = $post->ID; $post_type = $post->post_type; if ( is_page_template() ) { @@ -688,16 +716,11 @@ $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 ); - - $classes[] = 'page-id-' . $page_id; + $classes[] = 'page-id-' . $post_id; if ( get_pages( array( - 'parent' => $page_id, + 'parent' => $post_id, 'number' => 1, ) ) ) { @@ -813,14 +836,14 @@ } } - if ( ! empty( $class ) ) { - if ( ! is_array( $class ) ) { - $class = preg_split( '#\s+#', $class ); + if ( ! empty( $css_class ) ) { + if ( ! is_array( $css_class ) ) { + $css_class = preg_split( '#\s+#', $css_class ); } - $classes = array_merge( $classes, $class ); + $classes = array_merge( $classes, $css_class ); } else { // Ensure that we always coerce class to being an array. - $class = array(); + $css_class = array(); } $classes = array_map( 'esc_attr', $classes ); @@ -830,10 +853,10 @@ * * @since 2.8.0 * - * @param string[] $classes An array of body class names. - * @param string[] $class An array of additional class names added to the body. + * @param string[] $classes An array of body class names. + * @param string[] $css_class An array of additional class names added to the body. */ - $classes = apply_filters( 'body_class', $classes, $class ); + $classes = apply_filters( 'body_class', $classes, $css_class ); return array_unique( $classes ); } @@ -863,7 +886,7 @@ $hasher = new PasswordHash( 8, true ); $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); - if ( 0 !== strpos( $hash, '$P$B' ) ) { + if ( ! str_starts_with( $hash, '$P$B' ) ) { $required = true; } else { $required = ! $hasher->CheckPassword( $post->post_password, $hash ); @@ -957,11 +980,13 @@ $output .= $parsed_args['before']; for ( $i = 1; $i <= $numpages; $i++ ) { $link = $parsed_args['link_before'] . str_replace( '%', $i, $parsed_args['pagelink'] ) . $parsed_args['link_after']; - if ( $i != $page || ! $more && 1 == $page ) { + + if ( $i !== $page || ! $more && 1 === $page ) { $link = _wp_link_page( $i ) . $link . ''; } elseif ( $i === $page ) { $link = '' . $link . ''; } + /** * Filters the HTML output of individual page number links. * @@ -1033,12 +1058,12 @@ $post = get_post(); $query_args = array(); - if ( 1 == $i ) { + if ( 1 === $i ) { $url = get_permalink(); } else { 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' ) && (int) 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' ); @@ -1143,7 +1168,7 @@ * @see get_pages() * * @param array|string $args { - * Optional. Array or string of arguments to generate a page dropdown. See `get_pages()` for additional arguments. + * 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. @@ -1205,12 +1230,12 @@ } /** - * Filters the HTML output of a list of pages as a drop down. + * Filters the HTML output of a list of pages as a dropdown. * * @since 2.1.0 * @since 4.4.0 `$parsed_args` and `$pages` added as arguments. * - * @param string $output HTML output for drop down list of pages. + * @param string $output HTML output for dropdown list of pages. * @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. @@ -1235,7 +1260,7 @@ * @global WP_Query $wp_query WordPress Query object. * * @param array|string $args { - * Optional. Array or string of arguments to generate a list of pages. See `get_pages()` for additional arguments. + * 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). @@ -1366,7 +1391,7 @@ * @since 4.7.0 Added the `item_spacing` argument. * * @param array|string $args { - * Optional. Array or string of 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'. @@ -1444,7 +1469,7 @@ if ( is_front_page() && ! is_paged() ) { $class = 'class="current_page_item"'; } - $menu .= '
'; /** @@ -1774,7 +1819,7 @@ return (bool) $page_template; } - if ( $template == $page_template ) { + if ( $template === $page_template ) { return true; } @@ -1820,12 +1865,13 @@ * * @since 2.6.0 * - * @param int|object $revision Revision ID or revision object. - * @param bool $link Optional. Whether to link to revision's page. Default true. + * @param int|WP_Post $revision Revision ID or revision object. + * @param bool $link Optional. Whether to link to revision's page. Default true. * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title( $revision, $link = true ) { $revision = get_post( $revision ); + if ( ! $revision ) { return $revision; } @@ -1861,12 +1907,13 @@ * * @since 3.6.0 * - * @param int|object $revision Revision ID or revision object. - * @param bool $link Optional. Whether to link to revision's page. Default true. + * @param int|WP_Post $revision Revision ID or revision object. + * @param bool $link Optional. Whether to link to revision's page. Default true. * @return string|false gravatar, user, i18n formatted datetimestamp or localized 'Current Revision'. */ function wp_post_revision_title_expanded( $revision, $link = true ) { $revision = get_post( $revision ); + if ( ! $revision ) { return $revision; } @@ -1928,11 +1975,12 @@ * * @since 2.6.0 * - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. - * @param string $type 'all' (default), 'revision' or 'autosave' + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. + * @param string $type 'all' (default), 'revision' or 'autosave' */ -function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { - $post = get_post( $post_id ); +function wp_list_post_revisions( $post = 0, $type = 'all' ) { + $post = get_post( $post ); + if ( ! $post ) { return; } @@ -1944,6 +1992,7 @@ } $revisions = wp_get_post_revisions( $post->ID ); + if ( ! $revisions ) { return; }