Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r12300 r12183  
    133133function &get_comment(&$comment, $output = OBJECT) {
    134134    global $wpdb;
    135     $null = null;
    136135
    137136    if ( empty($comment) ) {
     
    148147        } elseif ( ! $_comment = wp_cache_get($comment, 'comment') ) {
    149148            $_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment));
    150             if ( ! $_comment )
    151                 return $null;
    152149            wp_cache_add($_comment->comment_ID, $_comment, 'comment');
    153150        }
     
    494491    // Simple duplicate check
    495492    // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
    496     $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
     493    $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";
    497494    if ( $comment_author_email )
    498495        $dupe .= "OR comment_author_email = '$comment_author_email' ";
     
    867864    do_action('trash_comment', $comment_id);
    868865
    869     if ( wp_set_comment_status($comment_id, 'trash') ) {
    870         add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);
    871         add_comment_meta($comment_id, '_wp_trash_meta_time', time() );
    872         do_action('trashed_comment', $comment_id);
    873         return true;
    874     }
    875 
    876     return false;
     866    add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);
     867    add_comment_meta($comment_id, '_wp_trash_meta_time', time() );
     868
     869    wp_set_comment_status($comment_id, 'trash');
     870
     871    do_action('trashed_comment', $comment_id);
     872
     873    return true;
    877874}
    878875
     
    881878 *
    882879 * @since 2.9.0
    883  * @uses do_action() on 'untrash_comment' before untrashing
    884  * @uses do_action() on 'untrashed_comment' after untrashing
     880 * @uses do_action() on 'untrash_comment' before undeletion
     881 * @uses do_action() on 'untrashed_comment' after undeletion
    885882 *
    886883 * @param int $comment_id Comment ID.
     
    893890    do_action('untrash_comment', $comment_id);
    894891
    895     $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     892    $comment = array('comment_ID'=>$comment_id);
     893
     894    $status = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
    896895    if ( empty($status) )
    897896        $status = '0';
    898897
    899     if ( wp_set_comment_status($comment_id, $status) ) {
    900         delete_comment_meta($comment_id, '_wp_trash_meta_time');
    901         delete_comment_meta($comment_id, '_wp_trash_meta_status');
    902         do_action('untrashed_comment', $comment_id);
    903         return true;
    904     }
    905 
    906     return false;
    907 }
    908 
    909 /**
    910  * Marks a comment as Spam
    911  *
    912  * @since 2.9.0
    913  * @uses do_action() on 'spam_comment' before spamming
    914  * @uses do_action() on 'spammed_comment' after spamming
    915  *
    916  * @param int $comment_id Comment ID.
    917  * @return mixed False on failure
    918  */
    919 function wp_spam_comment($comment_id) {
    920     if ( !$comment = get_comment($comment_id) )
    921         return false;
    922 
    923     do_action('spam_comment', $comment_id);
    924 
    925     if ( wp_set_comment_status($comment_id, 'spam') ) {
    926         add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);
    927         do_action('spammed_comment', $comment_id);
    928         return true;
    929     }
    930 
    931     return false;
    932 }
    933 
    934 /**
    935  * Removes a comment from the Spam
    936  *
    937  * @since 2.9.0
    938  * @uses do_action() on 'unspam_comment' before unspamming
    939  * @uses do_action() on 'unspammed_comment' after unspamming
    940  *
    941  * @param int $comment_id Comment ID.
    942  * @return mixed False on failure
    943  */
    944 function wp_unspam_comment($comment_id) {
    945     if ( ! (int)$comment_id )
    946         return false;
    947 
    948     do_action('unspam_comment', $comment_id);
    949 
    950     $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);
    951     if ( empty($status) )
    952         $status = '0';
    953 
    954     if ( wp_set_comment_status($comment_id, $status) ) {
    955         delete_comment_meta($comment_id, '_wp_trash_meta_status');
    956         do_action('unspammed_comment', $comment_id);
    957         return true;
    958     }
    959 
    960     return false;
     898    $comment['comment_approved'] = $status;
     899
     900    delete_comment_meta($comment_id, '_wp_trash_meta_time');
     901    delete_comment_meta($comment_id, '_wp_trash_meta_status');
     902
     903    wp_update_comment($comment);
     904
     905    do_action('untrashed_comment', $comment_id);
     906
     907    return true;
    961908}
    962909
     
    11271074 */
    11281075function wp_filter_comment($commentdata) {
    1129     if ( isset($commentdata['user_ID']) )
    1130         $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    1131     elseif ( isset($commentdata['user_id']) )
    1132         $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
     1076    $commentdata['user_id']              = apply_filters('pre_user_id', $commentdata['user_ID']);
    11331077    $commentdata['comment_agent']        = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']);
    11341078    $commentdata['comment_author']       = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
     
    11811125
    11821126    $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    1183     if ( isset($commentdata['user_ID']) )
    1184         $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    1185     elseif ( isset($commentdata['user_id']) )
    1186         $commentdata['user_id'] = (int) $commentdata['user_id'];
    1187 
    1188     $commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
     1127    $commentdata['user_ID']         = (int) $commentdata['user_ID'];
     1128
     1129    $commentdata['comment_parent'] = absint($commentdata['comment_parent']);
    11891130    $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
    11901131    $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
     
    12101151        $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
    12111152
    1212         if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_id'] )
     1153        if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] )
    12131154            wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
    12141155    }
     
    12611202    }
    12621203
    1263     $comment_old = wp_clone(get_comment($comment_id));
     1204    $comment_old = get_comment($comment_id);
    12641205
    12651206    if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) {
Note: See TracChangeset for help on using the changeset viewer.