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

    r53559 r53715  
    13771377 * @since 2.5.0
    13781378 *
    1379  * @param int|WP_Post $id    Post ID or post object.
     1379 * @param int|WP_Post $post  Post ID or post object.
    13801380 * @param string|null $title Optional. Title to override the post's current title
    13811381 *                           when generating the post name. Default null.
     
    13881388 * }
    13891389 */
    1390 function get_sample_permalink( $id, $title = null, $name = null ) {
    1391     $post = get_post( $id );
     1390function get_sample_permalink( $post, $title = null, $name = null ) {
     1391    $post = get_post( $post );
     1392
    13921393    if ( ! $post ) {
    13931394        return array( '', '' );
     
    14691470 * @since 2.5.0
    14701471 *
    1471  * @param int|WP_Post $id        Post ID or post object.
     1472 * @param int|WP_Post $post      Post ID or post object.
    14721473 * @param string|null $new_title Optional. New title. Default null.
    14731474 * @param string|null $new_slug  Optional. New slug. Default null.
    14741475 * @return string The HTML of the sample permalink slug editor.
    14751476 */
    1476 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
    1477     $post = get_post( $id );
     1477function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) {
     1478    $post = get_post( $post );
     1479
    14781480    if ( ! $post ) {
    14791481        return '';
     
    15121514        // Encourage a pretty permalink setting.
    15131515        if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
    1514             && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
     1516            && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID )
    15151517        ) {
    15161518            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n";
     
    16291631 * @since 2.5.0
    16301632 *
    1631  * @param int|WP_Post $post_id ID or object of the post to check for editing.
     1633 * @param int|WP_Post $post ID or object of the post to check for editing.
    16321634 * @return int|false ID of the user with lock. False if the post does not exist, post is not locked,
    16331635 *                   the user with lock does not exist, or the post is locked by current user.
    16341636 */
    1635 function wp_check_post_lock( $post_id ) {
    1636     $post = get_post( $post_id );
     1637function wp_check_post_lock( $post ) {
     1638    $post = get_post( $post );
     1639
    16371640    if ( ! $post ) {
    16381641        return false;
     
    16401643
    16411644    $lock = get_post_meta( $post->ID, '_edit_lock', true );
     1645
    16421646    if ( ! $lock ) {
    16431647        return false;
     
    16671671 * @since 2.5.0
    16681672 *
    1669  * @param int|WP_Post $post_id ID or object of the post being edited.
     1673 * @param int|WP_Post $post ID or object of the post being edited.
    16701674 * @return array|false {
    16711675 *     Array of the lock time and user ID. False if the post does not exist, or there
     
    16761680 * }
    16771681 */
    1678 function wp_set_post_lock( $post_id ) {
    1679     $post = get_post( $post_id );
     1682function wp_set_post_lock( $post ) {
     1683    $post = get_post( $post );
     1684
    16801685    if ( ! $post ) {
    16811686        return false;
     
    16831688
    16841689    $user_id = get_current_user_id();
     1690
    16851691    if ( 0 == $user_id ) {
    16861692        return false;
     
    17021708function _admin_notice_post_locked() {
    17031709    $post = get_post();
     1710
    17041711    if ( ! $post ) {
    17051712        return;
     
    17081715    $user    = null;
    17091716    $user_id = wp_check_post_lock( $post->ID );
     1717
    17101718    if ( $user_id ) {
    17111719        $user = get_userdata( $user_id );
     
    19371945
    19381946    $post = get_post( $post_ID );
     1947
    19391948    if ( ! $post ) {
    19401949        wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
Note: See TracChangeset for help on using the changeset viewer.