Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r12183 r12300  
    133133function &get_comment(&$comment, $output = OBJECT) {
    134134    global $wpdb;
     135    $null = null;
    135136
    136137    if ( empty($comment) ) {
     
    147148        } elseif ( ! $_comment = wp_cache_get($comment, 'comment') ) {
    148149            $_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment));
     150            if ( ! $_comment )
     151                return $null;
    149152            wp_cache_add($_comment->comment_ID, $_comment, 'comment');
    150153        }
     
    491494    // Simple duplicate check
    492495    // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
    493     $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";
     496    $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
    494497    if ( $comment_author_email )
    495498        $dupe .= "OR comment_author_email = '$comment_author_email' ";
     
    864867    do_action('trash_comment', $comment_id);
    865868
    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;
     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;
    874877}
    875878
     
    878881 *
    879882 * @since 2.9.0
    880  * @uses do_action() on 'untrash_comment' before undeletion
    881  * @uses do_action() on 'untrashed_comment' after undeletion
     883 * @uses do_action() on 'untrash_comment' before untrashing
     884 * @uses do_action() on 'untrashed_comment' after untrashing
    882885 *
    883886 * @param int $comment_id Comment ID.
     
    890893    do_action('untrash_comment', $comment_id);
    891894
    892     $comment = array('comment_ID'=>$comment_id);
    893 
    894     $status = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     895    $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);
    895896    if ( empty($status) )
    896897        $status = '0';
    897898
    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;
     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 */
     919function 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 */
     944function 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;
    908961}
    909962
     
    10741127 */
    10751128function wp_filter_comment($commentdata) {
    1076     $commentdata['user_id']              = apply_filters('pre_user_id', $commentdata['user_ID']);
     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']);
    10771133    $commentdata['comment_agent']        = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']);
    10781134    $commentdata['comment_author']       = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
     
    11251181
    11261182    $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    1127     $commentdata['user_ID']         = (int) $commentdata['user_ID'];
    1128 
    1129     $commentdata['comment_parent'] = absint($commentdata['comment_parent']);
     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;
    11301189    $parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
    11311190    $commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;
     
    11511210        $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
    11521211
    1153         if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] )
     1212        if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_id'] )
    11541213            wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
    11551214    }
     
    12021261    }
    12031262
    1204     $comment_old = get_comment($comment_id);
     1263    $comment_old = wp_clone(get_comment($comment_id));
    12051264
    12061265    if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) {
Note: See TracChangeset for help on using the changeset viewer.