From 1069ac4afda821742cf7f600412aacc139013a55 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 18 Jul 2022 17:37:17 +0000 Subject: [PATCH] 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 --- wp-admin/includes/post.php | 35 +++++++---- wp-includes/category-template.php | 34 +++++----- wp-includes/comment-template.php | 100 ++++++++++++++---------------- wp-includes/comment.php | 32 ++++++---- wp-includes/deprecated.php | 6 +- wp-includes/embed.php | 2 +- wp-includes/general-template.php | 10 +-- wp-includes/link-template.php | 34 ++++++---- wp-includes/media.php | 2 +- wp-includes/post-template.php | 93 ++++++++++++++------------- wp-includes/post.php | 49 +++++++++------ wp-includes/revision.php | 46 +++++++++----- wp-includes/version.php | 2 +- 13 files changed, 253 insertions(+), 192 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 51af5bb2f2..8eb0368220 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1376,7 +1376,7 @@ function postbox_classes( $box_id, $screen_id ) { * * @since 2.5.0 * - * @param int|WP_Post $id Post ID or post object. + * @param int|WP_Post $post Post ID or post object. * @param string|null $title Optional. Title to override the post's current title * when generating the post name. Default null. * @param string|null $name Optional. Name to override the post name. Default null. @@ -1387,8 +1387,9 @@ function postbox_classes( $box_id, $screen_id ) { * @type string $1 The post name. * } */ -function get_sample_permalink( $id, $title = null, $name = null ) { - $post = get_post( $id ); +function get_sample_permalink( $post, $title = null, $name = null ) { + $post = get_post( $post ); + if ( ! $post ) { return array( '', '' ); } @@ -1468,13 +1469,14 @@ function get_sample_permalink( $id, $title = null, $name = null ) { * * @since 2.5.0 * - * @param int|WP_Post $id Post ID or post object. + * @param int|WP_Post $post Post ID or post object. * @param string|null $new_title Optional. New title. Default null. * @param string|null $new_slug Optional. New slug. Default null. * @return string The HTML of the sample permalink slug editor. */ -function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { - $post = get_post( $id ); +function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) { + $post = get_post( $post ); + if ( ! $post ) { return ''; } @@ -1511,7 +1513,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { // Encourage a pretty permalink setting. if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) - && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id ) + && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) ) { $return .= '' . __( 'Change Permalink Structure' ) . "\n"; } @@ -1628,17 +1630,19 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { * * @since 2.5.0 * - * @param int|WP_Post $post_id ID or object of the post to check for editing. + * @param int|WP_Post $post ID or object of the post to check for editing. * @return int|false ID of the user with lock. False if the post does not exist, post is not locked, * the user with lock does not exist, or the post is locked by current user. */ -function wp_check_post_lock( $post_id ) { - $post = get_post( $post_id ); +function wp_check_post_lock( $post ) { + $post = get_post( $post ); + if ( ! $post ) { return false; } $lock = get_post_meta( $post->ID, '_edit_lock', true ); + if ( ! $lock ) { return false; } @@ -1666,7 +1670,7 @@ function wp_check_post_lock( $post_id ) { * * @since 2.5.0 * - * @param int|WP_Post $post_id ID or object of the post being edited. + * @param int|WP_Post $post ID or object of the post being edited. * @return array|false { * Array of the lock time and user ID. False if the post does not exist, or there * is no current user. @@ -1675,13 +1679,15 @@ function wp_check_post_lock( $post_id ) { * @type int $1 The ID of the current user. * } */ -function wp_set_post_lock( $post_id ) { - $post = get_post( $post_id ); +function wp_set_post_lock( $post ) { + $post = get_post( $post ); + if ( ! $post ) { return false; } $user_id = get_current_user_id(); + if ( 0 == $user_id ) { return false; } @@ -1701,12 +1707,14 @@ function wp_set_post_lock( $post_id ) { */ function _admin_notice_post_locked() { $post = get_post(); + if ( ! $post ) { return; } $user = null; $user_id = wp_check_post_lock( $post->ID ); + if ( $user_id ) { $user = get_userdata( $user_id ); } @@ -1936,6 +1944,7 @@ function post_preview() { $_POST['ID'] = $post_ID; $post = get_post( $post_ID ); + if ( ! $post ) { wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); } diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 326b90771b..c9e91a6f41 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -90,10 +90,10 @@ function get_the_category( $post_id = false ) { * Filters the array of categories to return for a post. * * @since 3.1.0 - * @since 4.4.0 Added `$post_id` parameter. + * @since 4.4.0 Added the `$post_id` parameter. * * @param WP_Term[] $categories An array of categories to return for the post. - * @param int|false $post_id ID of the post. + * @param int|false $post_id The post ID. */ return apply_filters( 'get_the_categories', $categories, $post_id ); } @@ -133,8 +133,9 @@ function get_the_category_by_ID( $cat_id ) { // phpcs:ignore WordPress.NamingCon * * @param string $separator Optional. Separator between the categories. By default, the links are placed * in an unordered list. An empty string will result in the default behavior. - * @param string $parents Optional. How to display the parents. - * @param int $post_id Optional. Post ID to retrieve categories. + * @param string $parents Optional. How to display the parents. Accepts 'multiple', 'single', or empty. + * Default empty string. + * @param int $post_id Optional. ID of the post to retrieve categories for. Defaults to the current post. * @return string Category list for a post. */ function get_the_category_list( $separator = '', $parents = '', $post_id = false ) { @@ -151,8 +152,8 @@ function get_the_category_list( $separator = '', $parents = '', $post_id = false * @since 4.4.0 * * @param WP_Term[] $categories An array of the post's categories. - * @param int|bool $post_id ID of the post we're retrieving categories for. - * When `false`, we assume the current post in the loop. + * @param int|false $post_id ID of the post to retrieve categories for. + * When `false`, defaults to the current post in the loop. */ $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id ); @@ -250,7 +251,7 @@ function get_the_category_list( $separator = '', $parents = '', $post_id = false * * @param int|string|int[]|string[] $category Category ID, name, slug, or array of such * to check against. - * @param int|object $post Optional. Post to check instead of the current post. + * @param int|WP_Post $post Optional. Post to check. Defaults to the current post. * @return bool True if the current post is in any of the given categories. */ function in_category( $category, $post = null ) { @@ -268,8 +269,9 @@ function in_category( $category, $post = null ) { * * @param string $separator Optional. Separator between the categories. By default, the links are placed * in an unordered list. An empty string will result in the default behavior. - * @param string $parents Optional. How to display the parents. - * @param int $post_id Optional. Post ID to retrieve categories. + * @param string $parents Optional. How to display the parents. Accepts 'multiple', 'single', or empty. + * Default empty string. + * @param int $post_id Optional. ID of the post to retrieve categories for. Defaults to the current post. */ function the_category( $separator = '', $parents = '', $post_id = false ) { echo get_the_category_list( $separator, $parents, $post_id ); @@ -1161,12 +1163,12 @@ function get_tag_link( $tag ) { * * @since 2.3.0 * - * @param int|WP_Post $post_id Post ID or object. + * @param int|WP_Post $post Post ID or object. * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms * or the post does not exist, WP_Error on failure. */ -function get_the_tags( $post_id = 0 ) { - $terms = get_the_terms( $post_id, 'post_tag' ); +function get_the_tags( $post = 0 ) { + $terms = get_the_terms( $post, 'post_tag' ); /** * Filters the array of tags for the given post. @@ -1278,11 +1280,13 @@ function term_description( $term = 0, $deprecated = null ) { */ function get_the_terms( $post, $taxonomy ) { $post = get_post( $post ); + if ( ! $post ) { return false; } $terms = get_object_term_cache( $post->ID, $taxonomy ); + if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy ); if ( ! is_wp_error( $terms ) ) { @@ -1476,7 +1480,7 @@ function the_terms( $post_id, $taxonomy, $before = '', $sep = ', ', $after = '' * * @param string|int|array $category Optional. The category name/term_id/slug, * or an array of them to check for. Default empty. - * @param int|object $post Optional. Post to check instead of the current post. + * @param int|WP_Post $post Optional. Post to check. Defaults to the current post. * @return bool True if the current post has any of the given categories * (or any category, if no category specified). False otherwise. */ @@ -1503,7 +1507,7 @@ function has_category( $category = '', $post = null ) { * * @param string|int|array $tag Optional. The tag name/term_id/slug, * or an array of them to check for. Default empty. - * @param int|object $post Optional. Post to check instead of the current post. + * @param int|WP_Post $post Optional. Post to check. Defaults to the current post. * @return bool True if the current post has any of the given tags * (or any tag, if no tag specified). False otherwise. */ @@ -1524,7 +1528,7 @@ function has_tag( $tag = '', $post = null ) { * @param string|int|array $term Optional. The term name/term_id/slug, * or an array of them to check for. Default empty. * @param string $taxonomy Optional. Taxonomy name. Default empty. - * @param int|WP_Post $post Optional. Post to check instead of the current post. + * @param int|WP_Post $post Optional. Post to check. Defaults to the current post. * @return bool True if the current post has any of the given terms * (or any term, if no term specified). False otherwise. */ diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index fcbd51c894..424e97c5bb 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -426,14 +426,14 @@ function comment_author_url_link( $linktext = '', $before = '', $after = '', $co * @param string|string[] $css_class Optional. One or more classes to add to the class list. * Default empty. * @param int|WP_Comment $comment Comment ID or WP_Comment object. Default current comment. - * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. + * @param int|WP_Post $post Post ID or WP_Post object. Default current post. * @param bool $display Optional. Whether to print or return the output. * Default true. * @return void|string Void if `$display` argument is true, comment classes if `$display` is false. */ -function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) { +function comment_class( $css_class = '', $comment = null, $post = null, $display = true ) { // Separates classes with a single space, collates classes for comment DIV. - $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"'; + $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post ) ) . '"'; if ( $display ) { echo $css_class; @@ -454,10 +454,10 @@ function comment_class( $css_class = '', $comment = null, $post_id = null, $disp * * @param string|string[] $css_class Optional. One or more classes to add to the class list. Default empty. * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment. - * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. + * @param int|WP_Post $post Post ID or WP_Post object. Default current post. * @return string[] An array of classes. */ -function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) { +function get_comment_class( $css_class = '', $comment_id = null, $post = null ) { global $comment_alt, $comment_depth, $comment_thread_alt; $classes = array(); @@ -476,9 +476,9 @@ function get_comment_class( $css_class = '', $comment_id = null, $post_id = null $classes[] = 'byuser'; $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id ); // For comment authors who are the author of the post. - $post = get_post( $post_id ); - if ( $post ) { - if ( $comment->user_id === $post->post_author ) { + $_post = get_post( $post ); + if ( $_post ) { + if ( $comment->user_id === $_post->post_author ) { $classes[] = 'bypostauthor'; } } @@ -534,9 +534,9 @@ function get_comment_class( $css_class = '', $comment_id = null, $post_id = null * @param string[] $css_class An array of additional classes added to the list. * @param string $comment_id The comment ID as a numeric string. * @param WP_Comment $comment The comment object. - * @param int|WP_Post $post_id The post ID or WP_Post object. + * @param int|WP_Post $post The post ID or WP_Post object. */ - return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id ); + return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post ); } /** @@ -808,12 +808,12 @@ function get_comment_link( $comment = null, $args = array() ) { * * @since 1.5.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 string The link to the comments. */ -function get_comments_link( $post_id = 0 ) { - $hash = get_comments_number( $post_id ) ? '#comments' : '#respond'; - $comments_link = get_permalink( $post_id ) . $hash; +function get_comments_link( $post = 0 ) { + $hash = get_comments_number( $post ) ? '#comments' : '#respond'; + $comments_link = get_permalink( $post ) . $hash; /** * Filters the returned post comments permalink. @@ -821,9 +821,9 @@ function get_comments_link( $post_id = 0 ) { * @since 3.6.0 * * @param string $comments_link Post comments permalink with '#comments' appended. - * @param int|WP_Post $post_id Post ID or WP_Post object. + * @param int|WP_Post $post Post ID or WP_Post object. */ - return apply_filters( 'get_comments_link', $comments_link, $post_id ); + return apply_filters( 'get_comments_link', $comments_link, $post ); } /** @@ -849,19 +849,15 @@ function comments_link( $deprecated = '', $deprecated_2 = '' ) { * * @since 1.5.0 * - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`. * @return string|int If the post exists, a numeric string representing the number of comments * the post has, otherwise 0. */ -function get_comments_number( $post_id = 0 ) { - $post = get_post( $post_id ); +function get_comments_number( $post = 0 ) { + $post = get_post( $post ); - if ( ! $post ) { - $count = 0; - } else { - $count = $post->comment_count; - $post_id = $post->ID; - } + $count = $post ? $post->comment_count : 0; + $post_id = $post ? $post->ID : 0; /** * Filters the returned comment count for a post. @@ -878,31 +874,31 @@ function get_comments_number( $post_id = 0 ) { * Displays the language string for the number of comments the current post has. * * @since 0.71 - * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`. + * @since 5.4.0 The `$deprecated` parameter was changed to `$post`. * - * @param string|false $zero Optional. Text for no comments. Default false. - * @param string|false $one Optional. Text for one comment. Default false. - * @param string|false $more Optional. Text for more than one comment. Default false. - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. + * @param string|false $zero Optional. Text for no comments. Default false. + * @param string|false $one Optional. Text for one comment. Default false. + * @param string|false $more Optional. Text for more than one comment. Default false. + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`. */ -function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) { - echo get_comments_number_text( $zero, $one, $more, $post_id ); +function comments_number( $zero = false, $one = false, $more = false, $post = 0 ) { + echo get_comments_number_text( $zero, $one, $more, $post ); } /** * Displays the language string for the number of comments the current post has. * * @since 4.0.0 - * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop. + * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop. * - * @param string $zero Optional. Text for no comments. Default false. - * @param string $one Optional. Text for one comment. Default false. - * @param string $more Optional. Text for more than one comment. Default false. - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`. + * @param string $zero Optional. Text for no comments. Default false. + * @param string $one Optional. Text for one comment. Default false. + * @param string $more Optional. Text for more than one comment. Default false. + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`. * @return string Language string for the number of comments a post has. */ -function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) { - $number = get_comments_number( $post_id ); +function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) { + $number = get_comments_number( $post ); if ( $number > 1 ) { if ( false === $more ) { @@ -1235,12 +1231,11 @@ function trackback_rdf( $deprecated = '' ) { * * @since 1.5.0 * - * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. + * @param int|WP_Post $post Post ID or WP_Post object. Default current post. * @return bool True if the comments are open. */ -function comments_open( $post_id = null ) { - - $_post = get_post( $post_id ); +function comments_open( $post = null ) { + $_post = get_post( $post ); $post_id = $_post ? $_post->ID : 0; $open = ( $_post && ( 'open' === $_post->comment_status ) ); @@ -1265,12 +1260,11 @@ function comments_open( $post_id = null ) { * * @since 1.5.0 * - * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post. + * @param int|WP_Post $post Post ID or WP_Post object. Default current post. * @return bool True if pings are accepted */ -function pings_open( $post_id = null ) { - - $_post = get_post( $post_id ); +function pings_open( $post = null ) { + $_post = get_post( $post ); $post_id = $_post ? $_post->ID : 0; $open = ( $_post && ( 'open' === $_post->ping_status ) ); @@ -1515,7 +1509,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false * @since 2.1.0 * * @param array $comments Array of comments supplied to the comments template. - * @param int $post_ID Post ID. + * @param int $post_id Post ID. */ $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID ); @@ -2324,12 +2318,12 @@ function wp_list_comments( $args = array(), $comments = null ) { * submit button markup and %2$s is the comment hidden fields. * @type string $format The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'. * } - * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post. + * @param int|WP_Post $post Post ID or WP_Post object to generate the form for. Default current post. */ -function comment_form( $args = array(), $post_id = null ) { - if ( null === $post_id ) { - $post_id = get_the_ID(); - } +function comment_form( $args = array(), $post = null ) { + $post = get_post( $post ); + + $post_id = $post ? $post->ID : get_the_ID(); // Exit the function when comments for the post are closed. if ( ! comments_open( $post_id ) ) { diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 376f0cbca6..ddc938a177 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -149,7 +149,7 @@ function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, } /** - * Retrieves the approved comments for post $post_id. + * Retrieves the approved comments for a post. * * @since 2.0.0 * @since 4.1.0 Refactored to leverage WP_Comment_Query over a direct query. @@ -859,7 +859,6 @@ function check_comment_flood_db() { * @return bool Whether comment flooding is occurring. */ function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = false ) { - global $wpdb; // Another callback has declared a flood. Trust it. @@ -1447,6 +1446,7 @@ function wp_count_comments( $post_id = 0 ) { */ function wp_delete_comment( $comment_id, $force_delete = false ) { global $wpdb; + $comment = get_comment( $comment_id ); if ( ! $comment ) { return false; @@ -1991,6 +1991,7 @@ function wp_get_unapproved_comment_author_email() { */ function wp_insert_comment( $commentdata ) { global $wpdb; + $data = wp_unslash( $commentdata ); $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; @@ -2651,7 +2652,9 @@ function wp_update_comment_count( $post_id, $do_deferred = false ) { */ function wp_update_comment_count_now( $post_id ) { global $wpdb; + $post_id = (int) $post_id; + if ( ! $post_id ) { return false; } @@ -2660,6 +2663,7 @@ function wp_update_comment_count_now( $post_id ) { wp_cache_delete( "comments-{$post_id}", 'counts' ); $post = get_post( $post_id ); + if ( ! $post ) { return false; } @@ -2886,21 +2890,24 @@ function do_all_trackbacks() { * Performs trackbacks. * * @since 1.5.0 - * @since 4.7.0 `$post_id` can be a WP_Post object. + * @since 4.7.0 `$post` can be a WP_Post object. * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int|WP_Post $post_id Post object or ID to do trackbacks on. + * @param int|WP_Post $post Post ID or object to do trackbacks on. */ -function do_trackbacks( $post_id ) { +function do_trackbacks( $post ) { global $wpdb; - $post = get_post( $post_id ); + + $post = get_post( $post ); + if ( ! $post ) { return false; } $to_ping = get_to_ping( $post ); $pinged = get_pung( $post ); + if ( empty( $to_ping ) ) { $wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) ); return; @@ -2947,7 +2954,7 @@ function do_trackbacks( $post_id ) { * @since 1.2.0 * * @param int $post_id Post ID. - * @return int Same as Post ID from parameter + * @return int Same post ID as provided. */ function generic_ping( $post_id = 0 ) { $services = get_option( 'ping_sites' ); @@ -2967,19 +2974,20 @@ function generic_ping( $post_id = 0 ) { * Pings back the links found in a post. * * @since 0.71 - * @since 4.7.0 `$post_id` can be a WP_Post object. + * @since 4.7.0 `$post` can be a WP_Post object. * * @param string $content Post content to check for links. If empty will retrieve from post. - * @param int|WP_Post $post_id Post Object or ID. + * @param int|WP_Post $post Post ID or object. */ -function pingback( $content, $post_id ) { +function pingback( $content, $post ) { include_once ABSPATH . WPINC . '/class-IXR.php'; include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php'; // Original code by Mort (http://mort.mine.nu:8080). $post_links = array(); - $post = get_post( $post_id ); + $post = get_post( $post ); + if ( ! $post ) { return; } @@ -3032,7 +3040,7 @@ function pingback( $content, $post_id ) { * * @param string[] $post_links Array of link URLs to be checked (passed by reference). * @param string[] $pung Array of link URLs already pinged (passed by reference). - * @param int $post_ID The post ID. + * @param int $post_id The post ID. */ do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) ); diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index af5eb95692..149f5b6e88 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -3631,13 +3631,13 @@ function wp_htmledit_pre($output) { * @deprecated 4.4.0 Use get_permalink() * @see get_permalink() * - * @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 string|false */ -function post_permalink( $post_id = 0 ) { +function post_permalink( $post = 0 ) { _deprecated_function( __FUNCTION__, '4.4.0', 'get_permalink()' ); - return get_permalink( $post_id ); + return get_permalink( $post ); } /** diff --git a/wp-includes/embed.php b/wp-includes/embed.php index f894578ad8..2710f392c7 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -537,7 +537,7 @@ function get_post_embed_html( $width, $height, $post = null ) { * * @since 4.4.0 * - * @param WP_Post|int $post Post object or ID. + * @param WP_Post|int $post Post ID or post object. * @param int $width The requested width. * @return array|false Response data on success, false if post doesn't exist * or is not publicly viewable. diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 58862b392a..12be5f7951 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2680,7 +2680,7 @@ function the_time( $format = '' ) { * @param string $format Optional. Format to use for retrieving the time the post * was written. Accepts 'G', 'U', or PHP date format. * Defaults to the 'time_format' option. - * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. + * @param int|WP_Post $post Post ID or post object. Default is global `$post` object. * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. * False on failure. */ @@ -2716,7 +2716,7 @@ function get_the_time( $format = '', $post = null ) { * @param string $format Optional. Format to use for retrieving the time the post * was written. Accepts 'G', 'U', or PHP date format. Default 'U'. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. - * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. + * @param int|WP_Post $post Post ID or post object. Default is global `$post` object. * @param bool $translate Whether to translate the time string. Default false. * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. * False on failure. @@ -2777,7 +2777,7 @@ function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = * * @since 5.3.0 * - * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. + * @param int|WP_Post $post Optional. Post ID or post object. Default is global `$post` object. * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. * Default 'date'. * @param string $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'. @@ -2822,7 +2822,7 @@ function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) { * * @since 5.3.0 * - * @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. + * @param int|WP_Post $post Optional. Post ID or post object. Default is global `$post` object. * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. * Default 'date'. * @return int|false Unix timestamp on success, false on failure. @@ -2905,7 +2905,7 @@ function get_the_modified_time( $format = '', $post = null ) { * @param string $format Optional. Format to use for retrieving the time the post * was modified. Accepts 'G', 'U', or PHP date format. Default 'U'. * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. - * @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. + * @param int|WP_Post $post Post ID or post object. Default is global `$post` object. * @param bool $translate Whether to translate the time string. Default false. * @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. * False on failure. diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 3e33865bd0..6b05040622 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -311,15 +311,15 @@ function get_permalink( $post = 0, $leavename = false ) { * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * - * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. + * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param bool $leavename Optional. Whether to keep post name. Default false. * @param bool $sample Optional. Is it a sample permalink. Default false. * @return string|WP_Error The post permalink. */ -function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { +function get_post_permalink( $post = 0, $leavename = false, $sample = false ) { global $wp_rewrite; - $post = get_post( $id ); + $post = get_post( $post ); if ( is_wp_error( $post ) ) { return $post; @@ -1298,6 +1298,7 @@ function get_post_type_archive_link( $post_type ) { global $wp_rewrite; $post_type_obj = get_post_type_object( $post_type ); + if ( ! $post_type_obj ) { return false; } @@ -1402,6 +1403,7 @@ function get_post_type_archive_feed_link( $post_type, $feed = '' ) { */ function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) { $post = get_post( $post ); + if ( ! $post ) { return; } @@ -1436,13 +1438,14 @@ function get_preview_post_link( $post = null, $query_args = array(), $preview_li * * @since 2.3.0 * - * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. + * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param string $context Optional. How to output the '&' character. Default '&'. * @return string|null The edit post link for the given post. Null if the post type does not exist * or does not allow an editing UI. */ -function get_edit_post_link( $id = 0, $context = 'display' ) { - $post = get_post( $id ); +function get_edit_post_link( $post = 0, $context = 'display' ) { + $post = get_post( $post ); + if ( ! $post ) { return; } @@ -1456,6 +1459,7 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { } $post_type_object = get_post_type_object( $post->post_type ); + if ( ! $post_type_object ) { return; } @@ -1492,16 +1496,18 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. - * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. + * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. */ -function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { - $post = get_post( $id ); +function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $class = 'post-edit-link' ) { + $post = get_post( $post ); + if ( ! $post ) { return; } $url = get_edit_post_link( $post->ID ); + if ( ! $url ) { return; } @@ -1531,22 +1537,24 @@ function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $clas * * @since 2.9.0 * - * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. + * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param string $deprecated Not used. * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. * @return string|void The delete post link URL for the given post. */ -function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { +function get_delete_post_link( $post = 0, $deprecated = '', $force_delete = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); } - $post = get_post( $id ); + $post = get_post( $post ); + if ( ! $post ) { return; } $post_type_object = get_post_type_object( $post->post_type ); + if ( ! $post_type_object ) { return; } @@ -1788,6 +1796,7 @@ function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo global $wpdb; $post = get_post(); + if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { return null; } @@ -2132,6 +2141,7 @@ function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded */ function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { $post = get_post(); + if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { return null; } diff --git a/wp-includes/media.php b/wp-includes/media.php index bc850cbe6d..aaf811d2d0 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -4299,7 +4299,7 @@ function wp_prepare_attachment_for_js( $attachment ) { * @param array $args { * Arguments for enqueuing media scripts. * - * @type int|WP_Post $post A post object or ID. + * @type int|WP_Post $post Post ID or post object. * } */ function wp_enqueue_media( $args = array() ) { diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index a4b7e3159d..800fda12c7 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -117,8 +117,8 @@ function the_title_attribute( $args = '' ) { function get_the_title( $post = 0 ) { $post = get_post( $post ); - $title = isset( $post->post_title ) ? $post->post_title : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_title = isset( $post->post_title ) ? $post->post_title : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; if ( ! is_admin() ) { if ( ! empty( $post->post_password ) ) { @@ -138,7 +138,8 @@ function get_the_title( $post = 0 ) { * @param WP_Post $post Current post object. */ $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); - $title = sprintf( $protected_title_format, $title ); + + $post_title = sprintf( $protected_title_format, $post_title ); } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { /* translators: %s: Private post title. */ @@ -156,7 +157,8 @@ function get_the_title( $post = 0 ) { * @param WP_Post $post Current post object. */ $private_title_format = apply_filters( 'private_title_format', $prepend, $post ); - $title = sprintf( $private_title_format, $title ); + + $post_title = sprintf( $private_title_format, $post_title ); } } @@ -165,10 +167,10 @@ function get_the_title( $post = 0 ) { * * @since 0.71 * - * @param string $title The post title. - * @param int $id The post ID. + * @param string $post_title The post title. + * @param int $post_id The post ID. */ - return apply_filters( 'the_title', $title, $id ); + return apply_filters( 'the_title', $post_title, $post_id ); } /** @@ -187,8 +189,8 @@ function get_the_title( $post = 0 ) { function the_guid( $post = 0 ) { $post = get_post( $post ); - $guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_guid = isset( $post->guid ) ? get_the_guid( $post ) : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; /** * Filters the escaped Global Unique Identifier (guid) of the post. @@ -197,10 +199,10 @@ function the_guid( $post = 0 ) { * * @see get_the_guid() * - * @param string $guid Escaped Global Unique Identifier (guid) of the post. - * @param int $id The post ID. + * @param string $post_guid Escaped Global Unique Identifier (guid) of the post. + * @param int $post_id The post ID. */ - echo apply_filters( 'the_guid', $guid, $id ); + echo apply_filters( 'the_guid', $post_guid, $post_id ); } /** @@ -218,18 +220,18 @@ function the_guid( $post = 0 ) { function get_the_guid( $post = 0 ) { $post = get_post( $post ); - $guid = isset( $post->guid ) ? $post->guid : ''; - $id = isset( $post->ID ) ? $post->ID : 0; + $post_guid = isset( $post->guid ) ? $post->guid : ''; + $post_id = isset( $post->ID ) ? $post->ID : 0; /** * Filters the Global Unique Identifier (guid) of the post. * * @since 1.5.0 * - * @param string $guid Global Unique Identifier (guid) of the post. - * @param int $id The post ID. + * @param string $post_guid Global Unique Identifier (guid) of the post. + * @param int $post_id The post ID. */ - return apply_filters( 'get_the_guid', $guid, $id ); + return apply_filters( 'get_the_guid', $post_guid, $post_id ); } /** @@ -451,12 +453,12 @@ function has_excerpt( $post = 0 ) { * * @since 2.7.0 * - * @param string|string[] $class One or more classes to add to the class list. - * @param int|WP_Post $post_id Optional. Post ID or post object. Defaults to the global `$post`. + * @param string|string[] $class One or more classes to add to the class list. + * @param int|WP_Post $post Optional. Post ID or post object. Defaults to the global `$post`. */ -function post_class( $class = '', $post_id = null ) { +function post_class( $class = '', $post = null ) { // Separates classes with a single space, collates classes for post DIV. - echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post_id ) ) ) . '"'; + echo 'class="' . esc_attr( implode( ' ', get_post_class( $class, $post ) ) ) . '"'; } /** @@ -476,12 +478,12 @@ function post_class( $class = '', $post_id = null ) { * @since 2.7.0 * @since 4.2.0 Custom taxonomy class names were added. * - * @param string|string[] $class Space-separated string or array of class names to add to the class list. - * @param int|WP_Post $post_id Optional. Post ID or post object. + * @param string|string[] $class Space-separated string or array of class names to add to the class list. + * @param int|WP_Post $post Optional. Post ID or post object. * @return string[] Array of class names. */ -function get_post_class( $class = '', $post_id = null ) { - $post = get_post( $post_id ); +function get_post_class( $class = '', $post = null ) { + $post = get_post( $post ); $classes = array(); @@ -1580,20 +1582,20 @@ function walk_page_dropdown_tree( ...$args ) { * * @since 2.0.0 * - * @param int|WP_Post $id Optional. Post ID or post object. - * @param bool $fullsize Optional. Whether to use full size. Default false. - * @param bool $deprecated Deprecated. Not used. - * @param bool $permalink Optional. Whether to include permalink. Default false. + * @param int|WP_Post $post Optional. Post ID or post object. + * @param bool $fullsize Optional. Whether to use full size. Default false. + * @param bool $deprecated Deprecated. Not used. + * @param bool $permalink Optional. Whether to include permalink. Default false. */ -function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { +function the_attachment_link( $post = 0, $fullsize = false, $deprecated = false, $permalink = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '2.5.0' ); } if ( $fullsize ) { - echo wp_get_attachment_link( $id, 'full', $permalink ); + echo wp_get_attachment_link( $post, 'full', $permalink ); } else { - echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); + echo wp_get_attachment_link( $post, 'thumbnail', $permalink ); } } @@ -1601,9 +1603,9 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $ * Retrieves an attachment page link using an image or icon, if possible. * * @since 2.5.0 - * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object. + * @since 4.4.0 The `$post` parameter can now accept either a post ID or `WP_Post` object. * - * @param int|WP_Post $id Optional. Post ID or post object. + * @param int|WP_Post $post Optional. Post ID or post object. * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array * of width and height values in pixels (in that order). Default 'thumbnail'. * @param bool $permalink Optional. Whether to add permalink to image. Default false. @@ -1613,8 +1615,8 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $ * @param array|string $attr Optional. Array or string of attributes. Default empty. * @return string HTML content. */ -function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { - $_post = get_post( $id ); +function wp_get_attachment_link( $post = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { + $_post = get_post( $post ); if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! wp_get_attachment_url( $_post->ID ) ) { return __( 'Missing Attachment' ); @@ -1641,6 +1643,9 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals if ( '' === trim( $link_text ) ) { $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) ); } + + $link_html = "$link_text"; + /** * Filters a retrieved attachment page link. * @@ -1648,7 +1653,7 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals * @since 5.1.0 Added the `$attr` parameter. * * @param string $link_html The page link HTML output. - * @param int|WP_Post $id Post ID or object. Can be 0 for the current global post. + * @param int|WP_Post $post Post ID or object. Can be 0 for the current global post. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param bool $permalink Whether to add permalink to image. Default false. @@ -1656,7 +1661,7 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals * @param string|false $text If string, will be link text. * @param array|string $attr Array or string of attributes. */ - return apply_filters( 'wp_get_attachment_link', "$link_text", $id, $size, $permalink, $icon, $text, $attr ); + return apply_filters( 'wp_get_attachment_link', $link_html, $post, $size, $permalink, $icon, $text, $attr ); } /** @@ -1825,6 +1830,7 @@ function get_page_template_slug( $post = null ) { */ function wp_post_revision_title( $revision, $link = true ) { $revision = get_post( $revision ); + if ( ! $revision ) { return $revision; } @@ -1866,6 +1872,7 @@ function wp_post_revision_title( $revision, $link = true ) { */ function wp_post_revision_title_expanded( $revision, $link = true ) { $revision = get_post( $revision ); + if ( ! $revision ) { return $revision; } @@ -1927,11 +1934,12 @@ function wp_post_revision_title_expanded( $revision, $link = true ) { * * @since 2.6.0 * - * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. - * @param string $type 'all' (default), 'revision' or 'autosave' + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. + * @param string $type 'all' (default), 'revision' or 'autosave' */ -function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { - $post = get_post( $post_id ); +function wp_list_post_revisions( $post = 0, $type = 'all' ) { + $post = get_post( $post ); + if ( ! $post ) { return; } @@ -1943,6 +1951,7 @@ function wp_list_post_revisions( $post_id = 0, $type = 'all' ) { } $revisions = wp_get_post_revisions( $post->ID ); + if ( ! $revisions ) { return; } diff --git a/wp-includes/post.php b/wp-includes/post.php index 4ceb8dd3a6..b20dfc603f 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1144,6 +1144,7 @@ function get_post_status( $post = null ) { } elseif ( 'trash' === get_post_status( $post->post_parent ) ) { // Get parent status prior to trashing. $post_status = get_post_meta( $post->post_parent, '_wp_trash_meta_status', true ); + if ( ! $post_status ) { // Assume publish as above. $post_status = 'publish'; @@ -2243,6 +2244,7 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) { function is_post_type_viewable( $post_type ) { if ( is_scalar( $post_type ) ) { $post_type = get_post_type_object( $post_type ); + if ( ! $post_type ) { return false; } @@ -2286,6 +2288,7 @@ function is_post_type_viewable( $post_type ) { function is_post_status_viewable( $post_status ) { if ( is_scalar( $post_status ) ) { $post_status = get_post_status_object( $post_status ); + if ( ! $post_status ) { return false; } @@ -2579,6 +2582,7 @@ function unregister_post_meta( $post_type, $meta_key ) { */ function get_post_custom( $post_id = 0 ) { $post_id = absint( $post_id ); + if ( ! $post_id ) { $post_id = get_the_ID(); } @@ -4189,6 +4193,7 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) * if none are provided, the date will be set to now. */ $post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] ); + if ( ! $post_date ) { if ( $wp_error ) { return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); @@ -4862,10 +4867,10 @@ function wp_publish_post( $post ) { * * @since 2.5.0 * - * @param int|WP_Post $post_id Post ID or post object. + * @param int|WP_Post $post Post ID or post object. */ -function check_and_publish_future_post( $post_id ) { - $post = get_post( $post_id ); +function check_and_publish_future_post( $post ) { + $post = get_post( $post ); if ( ! $post ) { return; @@ -4879,13 +4884,13 @@ function check_and_publish_future_post( $post_id ) { // Uh oh, someone jumped the gun! if ( $time > time() ) { - wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // Clear anything else in the system. - wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) ); + wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system. + wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) ); return; } // wp_publish_post() returns no meaningful value. - wp_publish_post( $post_id ); + wp_publish_post( $post->ID ); } /** @@ -5375,6 +5380,7 @@ function wp_transition_post_status( $new_status, $old_status, $post ) { */ function wp_after_insert_post( $post, $update, $post_before ) { $post = get_post( $post ); + if ( ! $post ) { return; } @@ -5403,19 +5409,19 @@ function wp_after_insert_post( $post, $update, $post_before ) { * Adds a URL to those already pinged. * * @since 1.5.0 - * @since 4.7.0 `$post_id` can be a WP_Post object. + * @since 4.7.0 `$post` can be a WP_Post object. * @since 4.7.0 `$uri` can be an array of URIs. * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int|WP_Post $post_id Post object or ID. - * @param string|array $uri Ping URI or array of URIs. + * @param int|WP_Post $post Post ID or post object. + * @param string|array $uri Ping URI or array of URIs. * @return int|false How many rows were updated. */ -function add_ping( $post_id, $uri ) { +function add_ping( $post, $uri ) { global $wpdb; - $post = get_post( $post_id ); + $post = get_post( $post ); if ( ! $post ) { return false; @@ -5486,13 +5492,13 @@ function get_enclosed( $post_id ) { * * @since 1.5.0 * - * @since 4.7.0 `$post_id` can be a WP_Post object. + * @since 4.7.0 `$post` can be a WP_Post object. * - * @param int|WP_Post $post_id Post ID or object. + * @param int|WP_Post $post Post ID or object. * @return string[]|false Array of URLs already pinged for the given post, false if the post is not found. */ -function get_pung( $post_id ) { - $post = get_post( $post_id ); +function get_pung( $post ) { + $post = get_post( $post ); if ( ! $post ) { return false; @@ -5515,13 +5521,13 @@ function get_pung( $post_id ) { * Retrieves URLs that need to be pinged. * * @since 1.5.0 - * @since 4.7.0 `$post_id` can be a WP_Post object. + * @since 4.7.0 `$post` can be a WP_Post object. * - * @param int|WP_Post $post_id Post Object or ID + * @param int|WP_Post $post Post ID or post object. * @return string[]|false List of URLs yet to ping. */ -function get_to_ping( $post_id ) { - $post = get_post( $post_id ); +function get_to_ping( $post ) { + $post = get_post( $post ); if ( ! $post ) { return false; @@ -7078,6 +7084,7 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $post_type_clauses = array(); foreach ( $post_types as $post_type ) { $post_type_obj = get_post_type_object( $post_type ); + if ( ! $post_type_obj ) { continue; } @@ -7092,12 +7099,14 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, * @param string $cap Capability. */ $cap = apply_filters_deprecated( 'pub_priv_sql_capability', array( '' ), '3.2.0' ); + if ( ! $cap ) { $cap = current_user_can( $post_type_obj->cap->read_private_posts ); } // Only need to check the cap if $public_only is false. $post_status_sql = "post_status = 'publish'"; + if ( false === $public_only ) { if ( $cap ) { // Does the user have the capability to view private posts? Guess so. @@ -7639,9 +7648,11 @@ function _publish_post_hook( $post_id ) { */ function wp_get_post_parent_id( $post = null ) { $post = get_post( $post ); + if ( ! $post || is_wp_error( $post ) ) { return false; } + return (int) $post->post_parent; } diff --git a/wp-includes/revision.php b/wp-includes/revision.php index 8f1d82ac02..1c837d7b59 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index a400f78b36..f37689a8da 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53714'; +$wp_version = '6.1-alpha-53715'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.