WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/30/2020 02:11:00 PM (15 months ago)
Author:
SergeyBiryukov
Message:

Comments: Make wp_update_comment() return false instead of 0 for an invalid comment or post ID.

This addresses an inconsistency where 0 could mean one of the three scenarios:

  • Invalid comment ID.
  • Invalid comment post ID.
  • No DB rows updated. This is not an error and should not be treated as one.

With this change, wp_update_comment() always returns either false or a WP_Error object on failure, depending on the value of the $wp_error parameter.

Follow-up to [48154], [48215], [48216], [48218], [48230].

Props dd32, jnylen0, enrico.sorcinelli.
Fixes #39732. See #38700, #39735.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r48230 r48235  
    24232423 * @since 4.9.0 Add updating comment meta during comment update.
    24242424 * @since 5.5.0 The `$wp_error` parameter was added.
     2425 * @since 5.5.0 The return values for an invalid comment or post ID
     2426 *              were changed to false instead of 0.
    24252427 *
    24262428 * @global wpdb $wpdb WordPress database abstraction object.
     
    24402442            return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) );
    24412443        } else {
    2442             return 0;
     2444            return false;
    24432445        }
    24442446    }
     
    24492451            return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
    24502452        } else {
    2451             return 0;
     2453            return false;
    24522454        }
    24532455    }
Note: See TracChangeset for help on using the changeset viewer.