Make WordPress Core


Ignore:
Timestamp:
07/18/2022 05:35:51 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Standardize on $post parameter name where appropriate.

This renames the $post_id or $id parameters to $post for functions that accept a post ID or post object:

  • get_sample_permalink()
  • get_sample_permalink_html()
  • wp_check_post_lock()
  • wp_set_post_lock()
  • get_the_tags()
  • comment_class()
  • get_comment_class()
  • get_comments_link()
  • get_comments_number()
  • comments_number()
  • get_comments_number_text()
  • comments_open()
  • pings_open()
  • comment_form()
  • do_trackbacks()
  • pingback()
  • post_permalink()
  • get_post_permalink()
  • get_edit_post_link()
  • edit_post_link()
  • get_delete_post_link()
  • post_class()
  • get_post_class()
  • the_attachment_link()
  • wp_get_attachment_link()
  • wp_list_post_revisions()
  • check_and_publish_future_post()
  • add_ping()
  • get_pung()
  • get_to_ping()
  • wp_get_post_revisions()
  • wp_get_post_revisions_url()

Additionally, $revision_id is renamed to $revision in:

  • wp_restore_post_revision()
  • wp_delete_post_revision()

Includes minor documentation improvements for consistency and code layout fixes for better readability.

Follow-up to [1599], [1794], [2881], [3303], [3851], [5302], [6633], [6716], [6985], [7103], [7149], [7747], [8011], [8638], [8643], [8695], [9138], [9273], [11425], [11922], [11956], [12284], [12810], [12923], [13023], [13171], [25567], [27156], [27473], [28558], [28602], [33659], [38852], [47276], [47366], [48622], [49544], [49597], [52095].

See #56243, #55647.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r53543 r53715  
    9191     *
    9292     * @since 3.1.0
    93      * @since 4.4.0 Added `$post_id` parameter.
     93     * @since 4.4.0 Added the `$post_id` parameter.
    9494     *
    9595     * @param WP_Term[] $categories An array of categories to return for the post.
    96      * @param int|false $post_id    ID of the post.
     96     * @param int|false $post_id    The post ID.
    9797     */
    9898    return apply_filters( 'get_the_categories', $categories, $post_id );
     
    134134 * @param string $separator Optional. Separator between the categories. By default, the links are placed
    135135 *                          in an unordered list. An empty string will result in the default behavior.
    136  * @param string $parents   Optional. How to display the parents.
    137  * @param int    $post_id   Optional. Post ID to retrieve categories.
     136 * @param string $parents   Optional. How to display the parents. Accepts 'multiple', 'single', or empty.
     137 *                          Default empty string.
     138 * @param int    $post_id   Optional. ID of the post to retrieve categories for. Defaults to the current post.
    138139 * @return string Category list for a post.
    139140 */
     
    152153     *
    153154     * @param WP_Term[] $categories An array of the post's categories.
    154      * @param int|bool  $post_id    ID of the post we're retrieving categories for.
    155      *                              When `false`, we assume the current post in the loop.
     155     * @param int|false $post_id    ID of the post to retrieve categories for.
     156     *                              When `false`, defaults to the current post in the loop.
    156157     */
    157158    $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
     
    251252 * @param int|string|int[]|string[] $category Category ID, name, slug, or array of such
    252253 *                                            to check against.
    253  * @param int|object                $post     Optional. Post to check instead of the current post.
     254 * @param int|WP_Post               $post     Optional. Post to check. Defaults to the current post.
    254255 * @return bool True if the current post is in any of the given categories.
    255256 */
     
    269270 * @param string $separator Optional. Separator between the categories. By default, the links are placed
    270271 *                          in an unordered list. An empty string will result in the default behavior.
    271  * @param string $parents   Optional. How to display the parents.
    272  * @param int    $post_id   Optional. Post ID to retrieve categories.
     272 * @param string $parents   Optional. How to display the parents. Accepts 'multiple', 'single', or empty.
     273 *                          Default empty string.
     274 * @param int    $post_id   Optional. ID of the post to retrieve categories for. Defaults to the current post.
    273275 */
    274276function the_category( $separator = '', $parents = '', $post_id = false ) {
     
    11621164 * @since 2.3.0
    11631165 *
    1164  * @param int|WP_Post $post_id Post ID or object.
     1166 * @param int|WP_Post $post Post ID or object.
    11651167 * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms
    11661168 *                                  or the post does not exist, WP_Error on failure.
    11671169 */
    1168 function get_the_tags( $post_id = 0 ) {
    1169     $terms = get_the_terms( $post_id, 'post_tag' );
     1170function get_the_tags( $post = 0 ) {
     1171    $terms = get_the_terms( $post, 'post_tag' );
    11701172
    11711173    /**
     
    12791281function get_the_terms( $post, $taxonomy ) {
    12801282    $post = get_post( $post );
     1283
    12811284    if ( ! $post ) {
    12821285        return false;
     
    12841287
    12851288    $terms = get_object_term_cache( $post->ID, $taxonomy );
     1289
    12861290    if ( false === $terms ) {
    12871291        $terms = wp_get_object_terms( $post->ID, $taxonomy );
     
    14771481 * @param string|int|array $category Optional. The category name/term_id/slug,
    14781482 *                                   or an array of them to check for. Default empty.
    1479  * @param int|object       $post     Optional. Post to check instead of the current post.
     1483 * @param int|WP_Post      $post     Optional. Post to check. Defaults to the current post.
    14801484 * @return bool True if the current post has any of the given categories
    14811485 *              (or any category, if no category specified). False otherwise.
     
    15041508 * @param string|int|array $tag  Optional. The tag name/term_id/slug,
    15051509 *                               or an array of them to check for. Default empty.
    1506  * @param int|object       $post Optional. Post to check instead of the current post.
     1510 * @param int|WP_Post      $post Optional. Post to check. Defaults to the current post.
    15071511 * @return bool True if the current post has any of the given tags
    15081512 *              (or any tag, if no tag specified). False otherwise.
     
    15251529 *                                   or an array of them to check for. Default empty.
    15261530 * @param string           $taxonomy Optional. Taxonomy name. Default empty.
    1527  * @param int|WP_Post      $post     Optional. Post to check instead of the current post.
     1531 * @param int|WP_Post      $post     Optional. Post to check. Defaults to the current post.
    15281532 * @return bool True if the current post has any of the given terms
    15291533 *              (or any term, if no term specified). False otherwise.
Note: See TracChangeset for help on using the changeset viewer.