Make WordPress Core


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

    r53300 r53715  
    113113
    114114    $post = get_post( $post_id );
     115
    115116    if ( ! $post ) {
    116117        return;
     
    276277function wp_is_post_revision( $post ) {
    277278    $post = wp_get_post_revision( $post );
     279
    278280    if ( ! $post ) {
    279281        return false;
     
    293295function wp_is_post_autosave( $post ) {
    294296    $post = wp_get_post_revision( $post );
     297
    295298    if ( ! $post ) {
    296299        return false;
     
    356359 * @since 2.6.0
    357360 *
    358  * @param int|WP_Post $post   The post ID or object.
     361 * @param int|WP_Post $post   Post ID or post object.
    359362 * @param string      $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
    360363 *                            correspond to a WP_Post object, an associative array, or a numeric array,
     
    365368function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
    366369    $revision = get_post( $post, OBJECT, $filter );
     370
    367371    if ( ! $revision ) {
    368372        return $revision;
    369373    }
     374
    370375    if ( 'revision' !== $revision->post_type ) {
    371376        return null;
     
    392397 * @since 2.6.0
    393398 *
    394  * @param int|WP_Post $revision_id Revision ID or revision object.
    395  * @param array       $fields      Optional. What fields to restore from. Defaults to all.
     399 * @param int|WP_Post $revision Revision ID or revision object.
     400 * @param array       $fields   Optional. What fields to restore from. Defaults to all.
    396401 * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
    397402 */
    398 function wp_restore_post_revision( $revision_id, $fields = null ) {
    399     $revision = wp_get_post_revision( $revision_id, ARRAY_A );
     403function wp_restore_post_revision( $revision, $fields = null ) {
     404    $revision = wp_get_post_revision( $revision, ARRAY_A );
     405
    400406    if ( ! $revision ) {
    401407        return $revision;
     
    420426
    421427    $post_id = wp_update_post( $update );
     428
    422429    if ( ! $post_id || is_wp_error( $post_id ) ) {
    423430        return $post_id;
     
    447454 * @since 2.6.0
    448455 *
    449  * @param int|WP_Post $revision_id Revision ID or revision object.
     456 * @param int|WP_Post $revision Revision ID or revision object.
    450457 * @return WP_Post|false|null Null or false if error, deleted post object if success.
    451458 */
    452 function wp_delete_post_revision( $revision_id ) {
    453     $revision = wp_get_post_revision( $revision_id );
     459function wp_delete_post_revision( $revision ) {
     460    $revision = wp_get_post_revision( $revision );
     461
    454462    if ( ! $revision ) {
    455463        return $revision;
     
    457465
    458466    $delete = wp_delete_post( $revision->ID );
     467
    459468    if ( $delete ) {
    460469        /**
     
    479488 * @see get_children()
    480489 *
    481  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
    482  * @param array|null  $args    Optional. Arguments for retrieving post revisions. Default null.
     490 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
     491 * @param array|null  $args Optional. Arguments for retrieving post revisions. Default null.
    483492 * @return array An array of revisions, or an empty array if none.
    484493 */
    485 function wp_get_post_revisions( $post_id = 0, $args = null ) {
    486     $post = get_post( $post_id );
     494function wp_get_post_revisions( $post = 0, $args = null ) {
     495    $post = get_post( $post );
     496
    487497    if ( ! $post || empty( $post->ID ) ) {
    488498        return array();
     
    510520
    511521    $revisions = get_children( $args );
     522
    512523    if ( ! $revisions ) {
    513524        return array();
     
    522533 * @since 5.9.0
    523534 *
    524  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
     535 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
    525536 * @return null|string The URL for editing revisions on the given post, otherwise null.
    526537 */
    527 function wp_get_post_revisions_url( $post_id = 0 ) {
    528     $post = get_post( $post_id );
     538function wp_get_post_revisions_url( $post = 0 ) {
     539    $post = get_post( $post );
    529540
    530541    if ( ! $post instanceof WP_Post ) {
     
    685696function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
    686697    $post = get_post();
     698
    687699    if ( ! $post ) {
    688700        return $terms;
     
    720732function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
    721733    $post = get_post();
     734
    722735    if ( ! $post ) {
    723736        return $value;
     
    735748
    736749    $thumbnail_id = (int) $_REQUEST['_thumbnail_id'];
     750
    737751    if ( $thumbnail_id <= 0 ) {
    738752        return '';
     
    784798    $now    = time();
    785799    $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
     800
    786801    if ( ! $result ) {
    787802        // If we couldn't get a lock, see how old the previous lock is.
    788803        $locked = get_option( $lock );
     804
    789805        if ( ! $locked ) {
    790806            // Can't write to the lock, and can't read the lock.
Note: See TracChangeset for help on using the changeset viewer.