Make WordPress Core


Ignore:
Timestamp:
06/05/2014 04:37:02 AM (11 years ago)
Author:
SergeyBiryukov
Message:

wp_insert_comment() and wp_new_comment() should check if the comment was successfully inserted into the database.

props pento.
fixes #28254.

File:
1 edited

Legend:

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

    r28654 r28672  
    15831583 *
    15841584 * @param array $commentdata Contains information on the comment.
    1585  * @return int The new comment's ID.
     1585 * @return int|bool The new comment's ID on success, false on failure.
    15861586 */
    15871587function wp_insert_comment( $commentdata ) {
     
    16081608
    16091609    $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
    1610     $wpdb->insert( $wpdb->comments, $compacted );
     1610    if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
     1611        return false;
     1612    }
    16111613
    16121614    $id = (int) $wpdb->insert_id;
     
    17281730 * @since 1.5.0
    17291731 * @param array $commentdata Contains information on the comment.
    1730  * @return int The ID of the comment after adding.
     1732 * @return int|bool The ID of the comment on success, false on failure.
    17311733 */
    17321734function wp_new_comment( $commentdata ) {
     
    17611763
    17621764    $comment_ID = wp_insert_comment($commentdata);
     1765    if ( ! $comment_ID ) {
     1766        return false;
     1767    }
    17631768
    17641769    /**
Note: See TracChangeset for help on using the changeset viewer.