Make WordPress Core


Ignore:
Timestamp:
07/18/2022 05:35:51 PM (3 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/comment-template.php

    r53576 r53715  
    427427 *                                   Default empty.
    428428 * @param int|WP_Comment  $comment   Comment ID or WP_Comment object. Default current comment.
    429  * @param int|WP_Post     $post_id   Post ID or WP_Post object. Default current post.
     429 * @param int|WP_Post     $post      Post ID or WP_Post object. Default current post.
    430430 * @param bool            $display   Optional. Whether to print or return the output.
    431431 *                                   Default true.
    432432 * @return void|string Void if `$display` argument is true, comment classes if `$display` is false.
    433433 */
    434 function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) {
     434function comment_class( $css_class = '', $comment = null, $post = null, $display = true ) {
    435435    // Separates classes with a single space, collates classes for comment DIV.
    436     $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"';
     436    $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post ) ) . '"';
    437437
    438438    if ( $display ) {
     
    455455 * @param string|string[] $css_class  Optional. One or more classes to add to the class list. Default empty.
    456456 * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
    457  * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
     457 * @param int|WP_Post     $post       Post ID or WP_Post object. Default current post.
    458458 * @return string[] An array of classes.
    459459 */
    460 function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) {
     460function get_comment_class( $css_class = '', $comment_id = null, $post = null ) {
    461461    global $comment_alt, $comment_depth, $comment_thread_alt;
    462462
     
    477477        $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
    478478        // For comment authors who are the author of the post.
    479         $post = get_post( $post_id );
    480         if ( $post ) {
    481             if ( $comment->user_id === $post->post_author ) {
     479        $_post = get_post( $post );
     480        if ( $_post ) {
     481            if ( $comment->user_id === $_post->post_author ) {
    482482                $classes[] = 'bypostauthor';
    483483            }
     
    535535     * @param string      $comment_id The comment ID as a numeric string.
    536536     * @param WP_Comment  $comment    The comment object.
    537      * @param int|WP_Post $post_id    The post ID or WP_Post object.
    538      */
    539     return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id );
     537     * @param int|WP_Post $post       The post ID or WP_Post object.
     538     */
     539    return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post );
    540540}
    541541
     
    809809 * @since 1.5.0
    810810 *
    811  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
     811 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    812812 * @return string The link to the comments.
    813813 */
    814 function get_comments_link( $post_id = 0 ) {
    815     $hash          = get_comments_number( $post_id ) ? '#comments' : '#respond';
    816     $comments_link = get_permalink( $post_id ) . $hash;
     814function get_comments_link( $post = 0 ) {
     815    $hash          = get_comments_number( $post ) ? '#comments' : '#respond';
     816    $comments_link = get_permalink( $post ) . $hash;
    817817
    818818    /**
     
    822822     *
    823823     * @param string      $comments_link Post comments permalink with '#comments' appended.
    824      * @param int|WP_Post $post_id       Post ID or WP_Post object.
    825      */
    826     return apply_filters( 'get_comments_link', $comments_link, $post_id );
     824     * @param int|WP_Post $post          Post ID or WP_Post object.
     825     */
     826    return apply_filters( 'get_comments_link', $comments_link, $post );
    827827}
    828828
     
    850850 * @since 1.5.0
    851851 *
    852  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
     852 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
    853853 * @return string|int If the post exists, a numeric string representing the number of comments
    854854 *                    the post has, otherwise 0.
    855855 */
    856 function get_comments_number( $post_id = 0 ) {
    857     $post = get_post( $post_id );
    858 
    859     if ( ! $post ) {
    860         $count = 0;
    861     } else {
    862         $count   = $post->comment_count;
    863         $post_id = $post->ID;
    864     }
     856function get_comments_number( $post = 0 ) {
     857    $post = get_post( $post );
     858
     859    $count   = $post ? $post->comment_count : 0;
     860    $post_id = $post ? $post->ID : 0;
    865861
    866862    /**
     
    879875 *
    880876 * @since 0.71
    881  * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`.
    882  *
    883  * @param string|false $zero    Optional. Text for no comments. Default false.
    884  * @param string|false $one     Optional. Text for one comment. Default false.
    885  * @param string|false $more    Optional. Text for more than one comment. Default false.
    886  * @param int|WP_Post  $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
    887  */
    888 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) {
    889     echo get_comments_number_text( $zero, $one, $more, $post_id );
     877 * @since 5.4.0 The `$deprecated` parameter was changed to `$post`.
     878 *
     879 * @param string|false $zero Optional. Text for no comments. Default false.
     880 * @param string|false $one  Optional. Text for one comment. Default false.
     881 * @param string|false $more Optional. Text for more than one comment. Default false.
     882 * @param int|WP_Post  $post Optional. Post ID or WP_Post object. Default is the global `$post`.
     883 */
     884function comments_number( $zero = false, $one = false, $more = false, $post = 0 ) {
     885    echo get_comments_number_text( $zero, $one, $more, $post );
    890886}
    891887
     
    894890 *
    895891 * @since 4.0.0
    896  * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop.
    897  *
    898  * @param string      $zero    Optional. Text for no comments. Default false.
    899  * @param string      $one     Optional. Text for one comment. Default false.
    900  * @param string      $more    Optional. Text for more than one comment. Default false.
    901  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
     892 * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
     893 *
     894 * @param string      $zero Optional. Text for no comments. Default false.
     895 * @param string      $one  Optional. Text for one comment. Default false.
     896 * @param string      $more Optional. Text for more than one comment. Default false.
     897 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
    902898 * @return string Language string for the number of comments a post has.
    903899 */
    904 function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
    905     $number = get_comments_number( $post_id );
     900function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) {
     901    $number = get_comments_number( $post );
    906902
    907903    if ( $number > 1 ) {
     
    12361232 * @since 1.5.0
    12371233 *
    1238  * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
     1234 * @param int|WP_Post $post Post ID or WP_Post object. Default current post.
    12391235 * @return bool True if the comments are open.
    12401236 */
    1241 function comments_open( $post_id = null ) {
    1242 
    1243     $_post = get_post( $post_id );
     1237function comments_open( $post = null ) {
     1238    $_post = get_post( $post );
    12441239
    12451240    $post_id = $_post ? $_post->ID : 0;
     
    12661261 * @since 1.5.0
    12671262 *
    1268  * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
     1263 * @param int|WP_Post $post Post ID or WP_Post object. Default current post.
    12691264 * @return bool True if pings are accepted
    12701265 */
    1271 function pings_open( $post_id = null ) {
    1272 
    1273     $_post = get_post( $post_id );
     1266function pings_open( $post = null ) {
     1267    $_post = get_post( $post );
    12741268
    12751269    $post_id = $_post ? $_post->ID : 0;
     
    15161510     *
    15171511     * @param array $comments Array of comments supplied to the comments template.
    1518      * @param int   $post_ID  Post ID.
     1512     * @param int   $post_id  Post ID.
    15191513     */
    15201514    $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
     
    23252319 *     @type string $format               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
    23262320 * }
    2327  * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
    2328  */
    2329 function comment_form( $args = array(), $post_id = null ) {
    2330     if ( null === $post_id ) {
    2331         $post_id = get_the_ID();
    2332     }
     2321 * @param int|WP_Post $post Post ID or WP_Post object to generate the form for. Default current post.
     2322 */
     2323function comment_form( $args = array(), $post = null ) {
     2324    $post = get_post( $post );
     2325
     2326    $post_id = $post ? $post->ID : get_the_ID();
    23332327
    23342328    // Exit the function when comments for the post are closed.
Note: See TracChangeset for help on using the changeset viewer.