Make WordPress Core


Ignore:
Timestamp:
06/28/2020 10:08:22 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Comments: Rename the $avoid_die parameter of wp_allow_comment() and wp_new_comment() to $wp_error.

This makes the function signatures more consistent with wp_update_comment() and wp_set_comment_status().

wp_check_comment_flood() is left as the only function with the $avoid_die parameter for now, as it does not return a WP_Error object.

Follow-up to [48154], [48207].

See #39732.

File:
1 edited

Legend:

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

    r48207 r48208  
    657657 *
    658658 * @since 2.0.0
    659  * @since 4.7.0 The `$avoid_die` parameter was added, allowing the function to
    660  *              return a WP_Error object instead of dying.
     659 * @since 4.7.0 The `$avoid_die` parameter was added, allowing the function
     660 *              to return a WP_Error object instead of dying.
     661 * @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
    661662 *
    662663 * @global wpdb $wpdb WordPress database abstraction object.
    663664 *
    664665 * @param array $commentdata Contains information on the comment.
    665  * @param bool  $avoid_die   When true, a disallowed comment will result in the function
     666 * @param bool  $wp_error    When true, a disallowed comment will result in the function
    666667 *                           returning a WP_Error object, rather than executing wp_die().
    667668 *                           Default false.
    668669 * @return int|string|WP_Error Allowed comments return the approval status (0|1|'spam'|'trash').
    669  *                             If `$avoid_die` is true, disallowed comments return a WP_Error.
    670  */
    671 function wp_allow_comment( $commentdata, $avoid_die = false ) {
     670 *                             If `$wp_error` is true, disallowed comments return a WP_Error.
     671 */
     672function wp_allow_comment( $commentdata, $wp_error = false ) {
    672673    global $wpdb;
    673674
     
    724725        $comment_duplicate_message = apply_filters( 'comment_duplicate_message', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) );
    725726
    726         if ( true === $avoid_die ) {
     727        if ( $wp_error ) {
    727728            return new WP_Error( 'comment_duplicate', $comment_duplicate_message, 409 );
    728729        } else {
     
    742743     * @since 2.3.0
    743744     * @since 4.7.0 The `$avoid_die` parameter was added.
     745     * @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
    744746     *
    745747     * @param string $comment_author_IP    Comment author's IP address.
    746748     * @param string $comment_author_email Comment author's email.
    747749     * @param string $comment_date_gmt     GMT date the comment was posted.
    748      * @param bool   $avoid_die            Whether to prevent executing wp_die()
    749      *                                     or die() if a comment flood is occurring.
     750     * @param bool   $wp_error             Whether to return a WP_Error object instead of executing
     751     *                                     wp_die() or die() if a comment flood is occurring.
    750752     */
    751753    do_action(
     
    754756        $commentdata['comment_author_email'],
    755757        $commentdata['comment_date_gmt'],
    756         $avoid_die
     758        $wp_error
    757759    );
    758760
     
    763765     *
    764766     * @since 4.7.0
     767     * @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
    765768     *
    766769     * @param bool   $is_flood             Is a comment flooding occurring? Default false.
     
    768771     * @param string $comment_author_email Comment author's email.
    769772     * @param string $comment_date_gmt     GMT date the comment was posted.
    770      * @param bool   $avoid_die            Whether to prevent executing wp_die()
    771      *                                     or die() if a comment flood is occurring.
     773     * @param bool   $wp_error             Whether to return a WP_Error object instead of executing
     774     *                                     wp_die() or die() if a comment flood is occurring.
    772775     */
    773776    $is_flood = apply_filters(
     
    777780        $commentdata['comment_author_email'],
    778781        $commentdata['comment_date_gmt'],
    779         $avoid_die
     782        $wp_error
    780783    );
    781784
     
    21402143 * @since 1.5.0
    21412144 * @since 4.3.0 Introduced the `comment_agent` and `comment_author_IP` arguments.
    2142  * @since 4.7.0 The `$avoid_die` parameter was added, allowing the function to
    2143  *              return a WP_Error object instead of dying.
     2145 * @since 4.7.0 The `$avoid_die` parameter was added, allowing the function
     2146 *              to return a WP_Error object instead of dying.
     2147 * @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
    21442148 * @since 5.5.0 Introduced the `comment_type` argument.
    21452149 *
     
    21672171 *                                        'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
    21682172 * }
    2169  * @param bool $avoid_die Should errors be returned as WP_Error objects instead of
    2170  *                        executing wp_die()? Default false.
     2173 * @param bool $wp_error Should errors be returned as WP_Error objects instead of
     2174 *                       executing wp_die()? Default false.
    21712175 * @return int|false|WP_Error The ID of the comment on success, false or WP_Error on failure.
    21722176 */
    2173 function wp_new_comment( $commentdata, $avoid_die = false ) {
     2177function wp_new_comment( $commentdata, $wp_error = false ) {
    21742178    global $wpdb;
    21752179
     
    22282232    $commentdata = wp_filter_comment( $commentdata );
    22292233
    2230     $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die );
     2234    $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
    22312235    if ( is_wp_error( $commentdata['comment_approved'] ) ) {
    22322236        return $commentdata['comment_approved'];
     
    22452249        $commentdata = wp_filter_comment( $commentdata );
    22462250
    2247         $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $avoid_die );
     2251        $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
    22482252        if ( is_wp_error( $commentdata['comment_approved'] ) ) {
    22492253            return $commentdata['comment_approved'];
     
    24162420 * @since 2.0.0
    24172421 * @since 4.9.0 Add updating comment meta during comment update.
    2418  * @since 5.5.0 Allow returning a WP_Error object on failure.
     2422 * @since 5.5.0 The `$wp_error` parameter was added.
    24192423 *
    24202424 * @global wpdb $wpdb WordPress database abstraction object.
     
    24892493     *
    24902494     * @since 4.7.0
    2491      * @since 5.5.0 Allow returning a WP_Error object on failure.
     2495     * @since 5.5.0 The `$wp_error` parameter was added.
    24922496     *
    24932497     * @param array $data       The new, processed comment data.
Note: See TracChangeset for help on using the changeset viewer.