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.php

    r53685 r53715  
    11451145            // Get parent status prior to trashing.
    11461146            $post_status = get_post_meta( $post->post_parent, '_wp_trash_meta_status', true );
     1147
    11471148            if ( ! $post_status ) {
    11481149                // Assume publish as above.
     
    22442245    if ( is_scalar( $post_type ) ) {
    22452246        $post_type = get_post_type_object( $post_type );
     2247
    22462248        if ( ! $post_type ) {
    22472249            return false;
     
    22872289    if ( is_scalar( $post_status ) ) {
    22882290        $post_status = get_post_status_object( $post_status );
     2291
    22892292        if ( ! $post_status ) {
    22902293            return false;
     
    25802583function get_post_custom( $post_id = 0 ) {
    25812584    $post_id = absint( $post_id );
     2585
    25822586    if ( ! $post_id ) {
    25832587        $post_id = get_the_ID();
     
    41904194     */
    41914195    $post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] );
     4196
    41924197    if ( ! $post_date ) {
    41934198        if ( $wp_error ) {
     
    48634868 * @since 2.5.0
    48644869 *
    4865  * @param int|WP_Post $post_id Post ID or post object.
    4866  */
    4867 function check_and_publish_future_post( $post_id ) {
    4868     $post = get_post( $post_id );
     4870 * @param int|WP_Post $post Post ID or post object.
     4871 */
     4872function check_and_publish_future_post( $post ) {
     4873    $post = get_post( $post );
    48694874
    48704875    if ( ! $post ) {
     
    48804885    // Uh oh, someone jumped the gun!
    48814886    if ( $time > time() ) {
    4882         wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // Clear anything else in the system.
    4883         wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) );
     4887        wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system.
     4888        wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) );
    48844889        return;
    48854890    }
    48864891
    48874892    // wp_publish_post() returns no meaningful value.
    4888     wp_publish_post( $post_id );
     4893    wp_publish_post( $post->ID );
    48894894}
    48904895
     
    53765381function wp_after_insert_post( $post, $update, $post_before ) {
    53775382    $post = get_post( $post );
     5383
    53785384    if ( ! $post ) {
    53795385        return;
     
    54045410 *
    54055411 * @since 1.5.0
    5406  * @since 4.7.0 `$post_id` can be a WP_Post object.
     5412 * @since 4.7.0 `$post` can be a WP_Post object.
    54075413 * @since 4.7.0 `$uri` can be an array of URIs.
    54085414 *
    54095415 * @global wpdb $wpdb WordPress database abstraction object.
    54105416 *
    5411  * @param int|WP_Post  $post_id Post object or ID.
    5412  * @param string|array $uri     Ping URI or array of URIs.
     5417 * @param int|WP_Post  $post Post ID or post object.
     5418 * @param string|array $uri  Ping URI or array of URIs.
    54135419 * @return int|false How many rows were updated.
    54145420 */
    5415 function add_ping( $post_id, $uri ) {
     5421function add_ping( $post, $uri ) {
    54165422    global $wpdb;
    54175423
    5418     $post = get_post( $post_id );
     5424    $post = get_post( $post );
    54195425
    54205426    if ( ! $post ) {
     
    54875493 * @since 1.5.0
    54885494 *
    5489  * @since 4.7.0 `$post_id` can be a WP_Post object.
    5490  *
    5491  * @param int|WP_Post $post_id Post ID or object.
     5495 * @since 4.7.0 `$post` can be a WP_Post object.
     5496 *
     5497 * @param int|WP_Post $post Post ID or object.
    54925498 * @return string[]|false Array of URLs already pinged for the given post, false if the post is not found.
    54935499 */
    5494 function get_pung( $post_id ) {
    5495     $post = get_post( $post_id );
     5500function get_pung( $post ) {
     5501    $post = get_post( $post );
    54965502
    54975503    if ( ! $post ) {
     
    55165522 *
    55175523 * @since 1.5.0
    5518  * @since 4.7.0 `$post_id` can be a WP_Post object.
    5519  *
    5520  * @param int|WP_Post $post_id Post Object or ID
     5524 * @since 4.7.0 `$post` can be a WP_Post object.
     5525 *
     5526 * @param int|WP_Post $post Post ID or post object.
    55215527 * @return string[]|false List of URLs yet to ping.
    55225528 */
    5523 function get_to_ping( $post_id ) {
    5524     $post = get_post( $post_id );
     5529function get_to_ping( $post ) {
     5530    $post = get_post( $post );
    55255531
    55265532    if ( ! $post ) {
     
    70797085    foreach ( $post_types as $post_type ) {
    70807086        $post_type_obj = get_post_type_object( $post_type );
     7087
    70817088        if ( ! $post_type_obj ) {
    70827089            continue;
     
    70937100         */
    70947101        $cap = apply_filters_deprecated( 'pub_priv_sql_capability', array( '' ), '3.2.0' );
     7102
    70957103        if ( ! $cap ) {
    70967104            $cap = current_user_can( $post_type_obj->cap->read_private_posts );
     
    70997107        // Only need to check the cap if $public_only is false.
    71007108        $post_status_sql = "post_status = 'publish'";
     7109
    71017110        if ( false === $public_only ) {
    71027111            if ( $cap ) {
     
    76407649function wp_get_post_parent_id( $post = null ) {
    76417650    $post = get_post( $post );
     7651
    76427652    if ( ! $post || is_wp_error( $post ) ) {
    76437653        return false;
    76447654    }
     7655
    76457656    return (int) $post->post_parent;
    76467657}
Note: See TracChangeset for help on using the changeset viewer.