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.
Built from https://develop.svn.wordpress.org/trunk@53715


git-svn-id: http://core.svn.wordpress.org/trunk@53274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2022-07-18 17:37:17 +00:00
parent 4e0b801910
commit 1069ac4afd
13 changed files with 253 additions and 192 deletions

View File

@@ -112,6 +112,7 @@ function wp_save_post_revision( $post_id ) {
}
$post = get_post( $post_id );
if ( ! $post ) {
return;
}
@@ -275,6 +276,7 @@ function wp_get_post_autosave( $post_id, $user_id = 0 ) {
*/
function wp_is_post_revision( $post ) {
$post = wp_get_post_revision( $post );
if ( ! $post ) {
return false;
}
@@ -292,6 +294,7 @@ function wp_is_post_revision( $post ) {
*/
function wp_is_post_autosave( $post ) {
$post = wp_get_post_revision( $post );
if ( ! $post ) {
return false;
}
@@ -355,7 +358,7 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param int|WP_Post $post Post ID or post object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
* correspond to a WP_Post object, an associative array, or a numeric array,
* respectively. Default OBJECT.
@@ -364,9 +367,11 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
*/
function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
$revision = get_post( $post, OBJECT, $filter );
if ( ! $revision ) {
return $revision;
}
if ( 'revision' !== $revision->post_type ) {
return null;
}
@@ -391,12 +396,13 @@ function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @param int|WP_Post $revision Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
*/
function wp_restore_post_revision( $revision_id, $fields = null ) {
$revision = wp_get_post_revision( $revision_id, ARRAY_A );
function wp_restore_post_revision( $revision, $fields = null ) {
$revision = wp_get_post_revision( $revision, ARRAY_A );
if ( ! $revision ) {
return $revision;
}
@@ -419,6 +425,7 @@ function wp_restore_post_revision( $revision_id, $fields = null ) {
$update = wp_slash( $update ); // Since data is from DB.
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) ) {
return $post_id;
}
@@ -446,16 +453,18 @@ function wp_restore_post_revision( $revision_id, $fields = null ) {
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param int|WP_Post $revision Revision ID or revision object.
* @return WP_Post|false|null Null or false if error, deleted post object if success.
*/
function wp_delete_post_revision( $revision_id ) {
$revision = wp_get_post_revision( $revision_id );
function wp_delete_post_revision( $revision ) {
$revision = wp_get_post_revision( $revision );
if ( ! $revision ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
@@ -478,12 +487,13 @@ function wp_delete_post_revision( $revision_id ) {
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
function wp_get_post_revisions( $post = 0, $args = null ) {
$post = get_post( $post );
if ( ! $post || empty( $post->ID ) ) {
return array();
}
@@ -509,6 +519,7 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
);
$revisions = get_children( $args );
if ( ! $revisions ) {
return array();
}
@@ -521,11 +532,11 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
*
* @since 5.9.0
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
* @return null|string The URL for editing revisions on the given post, otherwise null.
*/
function wp_get_post_revisions_url( $post_id = 0 ) {
$post = get_post( $post_id );
function wp_get_post_revisions_url( $post = 0 ) {
$post = get_post( $post );
if ( ! $post instanceof WP_Post ) {
return null;
@@ -684,6 +695,7 @@ function _show_post_preview() {
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
$post = get_post();
if ( ! $post ) {
return $terms;
}
@@ -719,6 +731,7 @@ function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
$post = get_post();
if ( ! $post ) {
return $value;
}
@@ -734,6 +747,7 @@ function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
}
$thumbnail_id = (int) $_REQUEST['_thumbnail_id'];
if ( $thumbnail_id <= 0 ) {
return '';
}
@@ -783,9 +797,11 @@ function _wp_upgrade_revisions_of_post( $post, $revisions ) {
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is.
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened.