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/post-template.php

    r53656 r53715  
    118118        $post = get_post( $post );
    119119
    120         $title = isset( $post->post_title ) ? $post->post_title : '';
    121         $id    = isset( $post->ID ) ? $post->ID : 0;
     120        $post_title = isset( $post->post_title ) ? $post->post_title : '';
     121        $post_id    = isset( $post->ID ) ? $post->ID : 0;
    122122
    123123        if ( ! is_admin() ) {
     
    139139                         */
    140140                        $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post );
    141                         $title                  = sprintf( $protected_title_format, $title );
     141
     142                        $post_title = sprintf( $protected_title_format, $post_title );
    142143                } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
    143144
     
    157158                         */
    158159                        $private_title_format = apply_filters( 'private_title_format', $prepend, $post );
    159                         $title                = sprintf( $private_title_format, $title );
     160
     161                        $post_title = sprintf( $private_title_format, $post_title );
    160162                }
    161163        }
     
    166168         * @since 0.71
    167169         *
    168          * @param string $title The post title.
    169          * @param int    $id    The post ID.
     170         * @param string $post_title The post title.
     171         * @param int    $post_id    The post ID.
    170172         */
    171         return apply_filters( 'the_title', $title, $id );
     173        return apply_filters( 'the_title', $post_title, $post_id );
    172174}
    173175
     
    188190        $post = get_post( $post );
    189191
    190         $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
    191         $id   = isset( $post->ID ) ? $post->ID : 0;
     192        $post_guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
     193        $post_id   = isset( $post->ID ) ? $post->ID : 0;
    192194
    193195        /**
     
    198200         * @see get_the_guid()
    199201         *
    200          * @param string $guid Escaped Global Unique Identifier (guid) of the post.
    201          * @param int    $id   The post ID.
     202         * @param string $post_guid Escaped Global Unique Identifier (guid) of the post.
     203         * @param int    $post_id   The post ID.
    202204         */
    203         echo apply_filters( 'the_guid', $guid, $id );
     205        echo apply_filters( 'the_guid', $post_guid, $post_id );
    204206}
    205207
     
    219221        $post = get_post( $post );
    220222
    221         $guid = isset( $post->guid ) ? $post->guid : '';
    222         $id   = isset( $post->ID ) ? $post->ID : 0;
     223        $post_guid = isset( $post->guid ) ? $post->guid : '';
     224        $post_id   = isset( $post->ID ) ? $post->ID : 0;
    223225
    224226        /**
     
    227229         * @since 1.5.0
    228230         *
    229          * @param string $guid Global Unique Identifier (guid) of the post.
    230          * @param int    $id   The post ID.
     231         * @param string $post_guid Global Unique Identifier (guid) of the post.
     232         * @param int    $post_id   The post ID.
    231233         */
    232         return apply_filters( 'get_the_guid', $guid, $id );
     234        return apply_filters( 'get_the_guid', $post_guid, $post_id );
    233235}
    234236
     
    452454 * @since 2.7.0
    453455 *
    454  * @param string|string[] $class   One or more classes to add to the class list.
    455  * @param int|WP_Post     $post_id Optional. Post ID or post object. Defaults to the global `$post`.
    456  */
    457 function post_class( $class = '', $post_id = null ) {
     456 * @param string|string[] $class One or more classes to add to the class list.
     457 * @param int|WP_Post     $post  Optional. Post ID or post object. Defaults to the global `$post`.
     458 */
     459function post_class( $class = '', $post = null ) {
    458460        // Separates classes with a single space, collates classes for post DIV.
    459         echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"';
     461        echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post ) ) ) . '"';
    460462}
    461463
     
    477479 * @since 4.2.0 Custom taxonomy class names were added.
    478480 *
    479  * @param string|string[] $class   Space-separated string or array of class names to add to the class list.
    480  * @param int|WP_Post     $post_id Optional. Post ID or post object.
     481 * @param string|string[] $class Space-separated string or array of class names to add to the class list.
     482 * @param int|WP_Post     $post  Optional. Post ID or post object.
    481483 * @return string[] Array of class names.
    482484 */
    483 function get_post_class( $class = '', $post_id = null ) {
    484         $post = get_post( $post_id );
     485function get_post_class( $class = '', $post = null ) {
     486        $post = get_post( $post );
    485487
    486488        $classes = array();
     
    15811583 * @since 2.0.0
    15821584 *
    1583  * @param int|WP_Post $id Optional. Post ID or post object.
    1584  * @param bool        $fullsize     Optional. Whether to use full size. Default false.
    1585  * @param bool        $deprecated   Deprecated. Not used.
    1586  * @param bool        $permalink    Optional. Whether to include permalink. Default false.
    1587  */
    1588 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
     1585 * @param int|WP_Post $post      Optional. Post ID or post object.
     1586 * @param bool        $fullsize   Optional. Whether to use full size. Default false.
     1587 * @param bool        $deprecated Deprecated. Not used.
     1588 * @param bool        $permalink Optional. Whether to include permalink. Default false.
     1589 */
     1590function the_attachment_link( $post = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
    15891591        if ( ! empty( $deprecated ) ) {
    15901592                _deprecated_argument( __FUNCTION__, '2.5.0' );
     
    15921594
    15931595        if ( $fullsize ) {
    1594                 echo wp_get_attachment_link( $id, 'full', $permalink );
     1596                echo wp_get_attachment_link( $post, 'full', $permalink );
    15951597        } else {
    1596                 echo wp_get_attachment_link( $id, 'thumbnail', $permalink );
     1598                echo wp_get_attachment_link( $post, 'thumbnail', $permalink );
    15971599        }
    15981600}
     
    16021604 *
    16031605 * @since 2.5.0
    1604  * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object.
    1605  *
    1606  * @param int|WP_Post  $id        Optional. Post ID or post object.
     1606 * @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object.
     1607 *
     1608 * @param int|WP_Post  $post      Optional. Post ID or post object.
    16071609 * @param string|int[] $size      Optional. Image size. Accepts any registered image size name, or an array
    16081610 *                                of width and height values in pixels (in that order). Default 'thumbnail'.
     
    16141616 * @return string HTML content.
    16151617 */
    1616 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
    1617         $_post = get_post( $id );
     1618function wp_get_attachment_link( $post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
     1619        $_post = get_post( $post );
    16181620
    16191621        if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) {
     
    16421644                $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
    16431645        }
     1646
     1647        $link_html = "<a href='" . esc_url( $url ) . "'>$link_text</a>";
     1648
    16441649        /**
    16451650         * Filters a retrieved attachment page link.
     
    16491654         *
    16501655         * @param string       $link_html The page link HTML output.
    1651          * @param int|WP_Post  $id        Post ID or object. Can be 0 for the current global post.
     1656         * @param int|WP_Post  $post      Post ID or object. Can be 0 for the current global post.
    16521657         * @param string|int[] $size      Requested image size. Can be any registered image size name, or
    16531658         *                                an array of width and height values in pixels (in that order).
     
    16571662         * @param array|string $attr      Array or string of attributes.
    16581663         */
    1659         return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr );
     1664        return apply_filters( 'wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr );
    16601665}
    16611666
     
    18261831function wp_post_revision_title( $revision, $link = true ) {
    18271832        $revision = get_post( $revision );
     1833
    18281834        if ( ! $revision ) {
    18291835                return $revision;
     
    18671873function wp_post_revision_title_expanded( $revision, $link = true ) {
    18681874        $revision = get_post( $revision );
     1875
    18691876        if ( ! $revision ) {
    18701877                return $revision;
     
    19281935 * @since 2.6.0
    19291936 *
    1930  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    1931  * @param string      $type    'all' (default), 'revision' or 'autosave'
    1932  */
    1933 function wp_list_post_revisions( $post_id = 0, $type = 'all' ) {
    1934         $post = get_post( $post_id );
     1937 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
     1938 * @param string      $type 'all' (default), 'revision' or 'autosave'
     1939 */
     1940function wp_list_post_revisions( $post = 0, $type = 'all' ) {
     1941        $post = get_post( $post );
     1942
    19351943        if ( ! $post ) {
    19361944                return;
     
    19441952
    19451953        $revisions = wp_get_post_revisions( $post->ID );
     1954
    19461955        if ( ! $revisions ) {
    19471956                return;
Note: See TracChangeset for help on using the changeset viewer.