WordPress.org

Make WordPress Core

Changeset 48215


Ignore:
Timestamp:
06/29/2020 10:42:08 PM (3 months ago)
Author:
SergeyBiryukov
Message:

Comments: Minor adjustments to wp_update_comment():

  • Revert the logic of $wp_error checks to avoid negation.
  • Clarify the return value, restore the edits from [47017].
  • Update wp_update_comment_data filter check to allow false to prevent the update.

Follow-up to [48154].

See #39732.

File:
1 edited

Legend:

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

    r48214 r48215  
    24282428 * @param array $commentarr Contains information on the comment.
    24292429 * @param bool  $wp_error   Optional. Whether to return a WP_Error on failure. Default false.
    2430  * @return int|bool|WP_Error Comment was updated if value is 1, or was not updated if value is 0,
    2431  *                           false, or a WP_Error object.
     2430 * @return int|false|WP_Error The value 1 if the comment was updated, 0 if not updated.
     2431 *                            False or a WP_Error object on failure.
    24322432 */
    24332433function wp_update_comment( $commentarr, $wp_error = false ) {
     
    24372437    $comment = get_comment( $commentarr['comment_ID'], ARRAY_A );
    24382438    if ( empty( $comment ) ) {
    2439         if ( ! $wp_error ) {
     2439        if ( $wp_error ) {
     2440            return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) );
     2441        } else {
    24402442            return 0;
    24412443        }
    2442 
    2443         return new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) );
    24442444    }
    24452445
    24462446    // Make sure that the comment post ID is valid (if specified).
    24472447    if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
    2448         if ( ! $wp_error ) {
     2448        if ( $wp_error ) {
     2449            return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
     2450        } else {
    24492451            return 0;
    24502452        }
    2451 
    2452         return new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) );
    24532453    }
    24542454
     
    24912491     * Filters the comment data immediately before it is updated in the database.
    24922492     *
    2493      * Note: data being passed to the filter is already unslashed. Returning 0 or a
    2494      * WP_Error object is preventing the comment to be updated.
     2493     * Note: data being passed to the filter is already unslashed. Returning false
     2494     * or a WP_Error object would prevent the comment from being updated.
    24952495     *
    24962496     * @since 4.7.0
     
    25002500     * @param array $comment    The old, unslashed comment data.
    25012501     * @param array $commentarr The new, raw comment data.
    2502      * @param bool  $wp_error   Optional. Whether to return a WP_Error on failure.
    2503      *                          Default false.
     2502     * @param bool  $wp_error   Whether to return a WP_Error on failure.
    25042503     */
    25052504    $data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr, $wp_error );
    25062505
    25072506    // Do not carry on on failure.
    2508     if ( is_wp_error( $data ) || 0 === $data ) {
     2507    if ( is_wp_error( $data ) || ! $data ) {
    25092508        return $data;
    25102509    }
Note: See TracChangeset for help on using the changeset viewer.