Skip to content

Commit

Permalink
Coding Standards: Make checks for an empty post in `wp-includes/post.…
Browse files Browse the repository at this point in the history
…php` more consistent.

See #50767.

git-svn-id: https://develop.svn.wordpress.org/trunk@49086 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 2, 2020
1 parent 0488373 commit 5d4a0c0
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/wp-includes/post.php
Expand Up @@ -3190,6 +3190,7 @@ function wp_trash_post( $post_id = 0 ) {
* @param WP_Post $post Post object.
*/
$check = apply_filters( 'pre_trash_post', null, $post );

if ( null !== $check ) {
return $check;
}
Expand Down Expand Up @@ -3316,7 +3317,8 @@ function wp_trash_post_comments( $post = null ) {
global $wpdb;

$post = get_post( $post );
if ( empty( $post ) ) {

if ( ! $post ) {
return;
}

Expand All @@ -3332,7 +3334,8 @@ function wp_trash_post_comments( $post = null ) {
do_action( 'trash_post_comments', $post_id );

$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
if ( empty( $comments ) ) {

if ( ! $comments ) {
return;
}

Expand Down Expand Up @@ -3375,15 +3378,16 @@ function wp_untrash_post_comments( $post = null ) {
global $wpdb;

$post = get_post( $post );
if ( empty( $post ) ) {

if ( ! $post ) {
return;
}

$post_id = $post->ID;

$statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true );

if ( empty( $statuses ) ) {
if ( ! $statuses ) {
return true;
}

Expand Down Expand Up @@ -4370,6 +4374,7 @@ function wp_publish_post( $post ) {
global $wpdb;

$post = get_post( $post );

if ( ! $post ) {
return;
}
Expand Down Expand Up @@ -4442,7 +4447,7 @@ function wp_publish_post( $post ) {
function check_and_publish_future_post( $post_id ) {
$post = get_post( $post_id );

if ( empty( $post ) ) {
if ( ! $post ) {
return;
}

Expand Down Expand Up @@ -4897,6 +4902,7 @@ function add_ping( $post_id, $uri ) {
global $wpdb;

$post = get_post( $post_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -4973,6 +4979,7 @@ function get_enclosed( $post_id ) {
*/
function get_pung( $post_id ) {
$post = get_post( $post_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -5994,7 +6001,7 @@ function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {

$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );

if ( empty( $data ) ) {
if ( ! $data ) {
return false;
}

Expand Down Expand Up @@ -6027,6 +6034,7 @@ function wp_update_attachment_metadata( $attachment_id, $data ) {
$attachment_id = (int) $attachment_id;

$post = get_post( $attachment_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -6061,6 +6069,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
$attachment_id = (int) $attachment_id;

$post = get_post( $attachment_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -6094,7 +6103,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
* If any of the above options failed, Fallback on the GUID as used pre-2.7,
* not recommended to rely upon this.
*/
if ( empty( $url ) ) {
if ( ! $url ) {
$url = get_the_guid( $post->ID );
}

Expand All @@ -6113,7 +6122,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
*/
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );

if ( empty( $url ) ) {
if ( ! $url ) {
return false;
}

Expand All @@ -6131,6 +6140,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) {
function wp_get_attachment_caption( $post_id = 0 ) {
$post_id = (int) $post_id;
$post = get_post( $post_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -6163,6 +6173,7 @@ function wp_get_attachment_caption( $post_id = 0 ) {
function wp_get_attachment_thumb_file( $post_id = 0 ) {
$post_id = (int) $post_id;
$post = get_post( $post_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -6202,6 +6213,7 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) {
function wp_get_attachment_thumb_url( $post_id = 0 ) {
$post_id = (int) $post_id;
$post = get_post( $post_id );

if ( ! $post ) {
return false;
}
Expand Down Expand Up @@ -6245,11 +6257,13 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) {
*/
function wp_attachment_is( $type, $post = null ) {
$post = get_post( $post );

if ( ! $post ) {
return false;
}

$file = get_attached_file( $post->ID );

if ( ! $file ) {
return false;
}
Expand All @@ -6259,6 +6273,7 @@ function wp_attachment_is( $type, $post = null ) {
}

$check = wp_check_filetype( $file );

if ( empty( $check['ext'] ) ) {
return false;
}
Expand Down Expand Up @@ -6829,7 +6844,8 @@ function clean_post_cache( $post ) {
}

$post = get_post( $post );
if ( empty( $post ) ) {

if ( ! $post ) {
return;
}

Expand Down Expand Up @@ -7126,7 +7142,7 @@ function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) {
}

// New post can't cause a loop.
if ( empty( $post_ID ) ) {
if ( ! $post_ID ) {
return $post_parent;
}

Expand Down Expand Up @@ -7475,7 +7491,7 @@ function wp_get_original_image_url( $attachment_id ) {

$image_url = wp_get_attachment_url( $attachment_id );

if ( empty( $image_url ) ) {
if ( ! $image_url ) {
return false;
}

Expand Down

0 comments on commit 5d4a0c0

Please sign in to comment.