diff --git a/wp-admin/comment.php b/wp-admin/comment.php index 6d11e553ff..38e714f045 100644 --- a/wp-admin/comment.php +++ b/wp-admin/comment.php @@ -278,11 +278,11 @@ case 'unapprovecomment' : $redir = add_query_arg( array('unspammed' => '1'), $redir ); break; case 'approvecomment' : - wp_set_comment_status( $comment_id, 'approve' ); + wp_set_comment_status( $comment, 'approve' ); $redir = add_query_arg( array( 'approved' => 1 ), $redir ); break; case 'unapprovecomment' : - wp_set_comment_status( $comment_id, 'hold' ); + wp_set_comment_status( $comment, 'hold' ); $redir = add_query_arg( array( 'unapproved' => 1 ), $redir ); break; } diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index e0391dc970..771a109c32 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -520,7 +520,7 @@ function wp_ajax_delete_comment() { wp_die( -1 ); check_ajax_referer( "delete-comment_$id" ); - $status = wp_get_comment_status( $comment->comment_ID ); + $status = wp_get_comment_status( $comment ); $delta = -1; if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { @@ -730,15 +730,16 @@ function wp_ajax_dim_comment() { if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) wp_die( -1 ); - $current = wp_get_comment_status( $comment->comment_ID ); + $current = wp_get_comment_status( $comment ); if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) wp_die( time() ); check_ajax_referer( "approve-comment_$id" ); - if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) - $result = wp_set_comment_status( $comment->comment_ID, 'approve', true ); - else - $result = wp_set_comment_status( $comment->comment_ID, 'hold', true ); + if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { + $result = wp_set_comment_status( $comment, 'approve', true ); + } else { + $result = wp_set_comment_status( $comment, 'hold', true ); + } if ( is_wp_error($result) ) { $x = new WP_Ajax_Response( array( @@ -1015,7 +1016,7 @@ function wp_ajax_replyto_comment( $action ) { wp_die( -1 ); } - if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) ) + if ( wp_set_comment_status( $parent, 'approve' ) ) $comment_auto_approved = true; } } diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index 8a65a46d4c..2a32299aec 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -969,8 +969,8 @@ function wp_count_comments( $post_id = 0 ) { * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int $comment_id Comment ID - * @param bool $force_delete Whether to bypass trash and force deletion. Default is false. + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. + * @param bool $force_delete Whether to bypass trash and force deletion. Default is false. * @return bool True on success, false on failure. */ function wp_delete_comment($comment_id, $force_delete = false) { @@ -978,7 +978,7 @@ function wp_delete_comment($comment_id, $force_delete = false) { if (!$comment = get_comment($comment_id)) return false; - if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status($comment_id), array( 'trash', 'spam' ) ) ) + if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ) ) ) return wp_trash_comment($comment_id); /** @@ -988,21 +988,21 @@ function wp_delete_comment($comment_id, $force_delete = false) { * * @param int $comment_id The comment ID. */ - do_action( 'delete_comment', $comment_id ); + do_action( 'delete_comment', $comment->comment_ID ); // Move children up a level. - $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment_id) ); + $children = $wpdb->get_col( $wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_parent = %d", $comment->comment_ID) ); if ( !empty($children) ) { - $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment_id)); + $wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID)); clean_comment_cache($children); } // Delete metadata - $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) ); + $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment->comment_ID ) ); foreach ( $meta_ids as $mid ) delete_metadata_by_mid( 'comment', $mid ); - if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) ) + if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) return false; /** @@ -1012,16 +1012,16 @@ function wp_delete_comment($comment_id, $force_delete = false) { * * @param int $comment_id The comment ID. */ - do_action( 'deleted_comment', $comment_id ); + do_action( 'deleted_comment', $comment->comment_ID ); $post_id = $comment->comment_post_ID; if ( $post_id && $comment->comment_approved == 1 ) wp_update_comment_count($post_id); - clean_comment_cache($comment_id); + clean_comment_cache( $comment->comment_ID ); /** This action is documented in wp-includes/comment-functions.php */ - do_action( 'wp_set_comment_status', $comment_id, 'delete' ); + do_action( 'wp_set_comment_status', $comment->comment_ID, 'delete' ); wp_transition_comment_status('delete', $comment->comment_approved, $comment); return true; @@ -1034,7 +1034,7 @@ function wp_delete_comment($comment_id, $force_delete = false) { * * @since 2.9.0 * - * @param int $comment_id Comment ID. + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. * @return bool True on success, false on failure. */ function wp_trash_comment($comment_id) { @@ -1051,13 +1051,13 @@ function wp_trash_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'trash_comment', $comment_id ); + do_action( 'trash_comment', $comment->comment_ID ); - if ( wp_set_comment_status($comment_id, 'trash') ) { - delete_comment_meta( $comment_id, '_wp_trash_meta_status' ); - delete_comment_meta( $comment_id, '_wp_trash_meta_time' ); - add_comment_meta( $comment_id, '_wp_trash_meta_status', $comment->comment_approved ); - add_comment_meta( $comment_id, '_wp_trash_meta_time', time() ); + if ( wp_set_comment_status( $comment, 'trash' ) ) { + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); + add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); + add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); /** * Fires immediately after a comment is sent to Trash. @@ -1066,7 +1066,7 @@ function wp_trash_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'trashed_comment', $comment_id ); + do_action( 'trashed_comment', $comment->comment_ID ); return true; } @@ -1078,12 +1078,14 @@ function wp_trash_comment($comment_id) { * * @since 2.9.0 * - * @param int $comment_id Comment ID. + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. * @return bool True on success, false on failure. */ function wp_untrash_comment($comment_id) { - if ( ! (int)$comment_id ) + $comment = get_comment( $comment_id ); + if ( ! $comment ) { return false; + } /** * Fires immediately before a comment is restored from the Trash. @@ -1092,15 +1094,15 @@ function wp_untrash_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'untrash_comment', $comment_id ); + do_action( 'untrash_comment', $comment->comment_ID ); - $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true); + $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); if ( empty($status) ) $status = '0'; - if ( wp_set_comment_status($comment_id, $status) ) { - delete_comment_meta($comment_id, '_wp_trash_meta_time'); - delete_comment_meta($comment_id, '_wp_trash_meta_status'); + if ( wp_set_comment_status( $comment, $status ) ) { + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); /** * Fires immediately after a comment is restored from the Trash. * @@ -1108,7 +1110,7 @@ function wp_untrash_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'untrashed_comment', $comment_id ); + do_action( 'untrashed_comment', $comment->comment_ID ); return true; } @@ -1120,12 +1122,14 @@ function wp_untrash_comment($comment_id) { * * @since 2.9.0 * - * @param int $comment_id Comment ID. + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. * @return bool True on success, false on failure. */ -function wp_spam_comment($comment_id) { - if ( !$comment = get_comment($comment_id) ) +function wp_spam_comment( $comment_id ) { + $comment = get_comment( $comment_id ); + if ( ! $comment ) { return false; + } /** * Fires immediately before a comment is marked as Spam. @@ -1134,13 +1138,13 @@ function wp_spam_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'spam_comment', $comment_id ); + do_action( 'spam_comment', $comment->comment_ID ); - if ( wp_set_comment_status($comment_id, 'spam') ) { - delete_comment_meta( $comment_id, '_wp_trash_meta_status' ); - delete_comment_meta( $comment_id, '_wp_trash_meta_time' ); - add_comment_meta( $comment_id, '_wp_trash_meta_status', $comment->comment_approved ); - add_comment_meta( $comment_id, '_wp_trash_meta_time', time() ); + if ( wp_set_comment_status( $comment, 'spam' ) ) { + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' ); + delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' ); + add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved ); + add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() ); /** * Fires immediately after a comment is marked as Spam. * @@ -1148,7 +1152,7 @@ function wp_spam_comment($comment_id) { * * @param int $comment_id The comment ID. */ - do_action( 'spammed_comment', $comment_id ); + do_action( 'spammed_comment', $comment->comment_ID ); return true; } @@ -1167,6 +1171,11 @@ function wp_unspam_comment($comment_id) { if ( ! (int)$comment_id ) return false; + $comment = get_comment( $comment_id ); + if ( ! $comment ) { + return false; + } + /** * Fires immediately before a comment is unmarked as Spam. * @@ -1180,7 +1189,7 @@ function wp_unspam_comment($comment_id) { if ( empty($status) ) $status = '0'; - if ( wp_set_comment_status($comment_id, $status) ) { + if ( wp_set_comment_status( $comment, $status ) ) { delete_comment_meta( $comment_id, '_wp_trash_meta_status' ); delete_comment_meta( $comment_id, '_wp_trash_meta_time' ); /** @@ -1675,9 +1684,9 @@ function wp_new_comment_notify_postauthor( $comment_ID ) { * * global wpdb $wpdb * - * @param int $comment_id Comment ID. - * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'. - * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false. + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. + * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'. + * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false. * @return bool|WP_Error True on success, false or WP_Error on failure. */ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { @@ -1707,16 +1716,16 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) $comment_old = clone get_comment($comment_id); - if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) { + if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array( 'comment_ID' => $comment_old->comment_ID ) ) ) { if ( $wp_error ) return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); else return false; } - clean_comment_cache($comment_id); + clean_comment_cache( $comment_old->comment_ID ); - $comment = get_comment($comment_id); + $comment = get_comment( $comment_old->comment_ID ); /** * Fires immediately before transitioning a comment's status from one to another @@ -1728,7 +1737,7 @@ function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) * @param string|bool $comment_status Current comment status. Possible values include * 'hold', 'approve', 'spam', 'trash', or false. */ - do_action( 'wp_set_comment_status', $comment_id, $comment_status ); + do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); @@ -2316,8 +2325,10 @@ function xmlrpc_pingback_error( $ixr_error ) { * @param int|array $ids Comment ID or array of comment IDs to remove from cache */ function clean_comment_cache($ids) { - foreach ( (array) $ids as $id ) - wp_cache_delete($id, 'comment'); + foreach ( (array) $ids as $id ) { + wp_cache_delete( $id, 'comment' ); + wp_cache_delete( "comment-{$id}", 'counts' ); + } wp_cache_set( 'last_changed', microtime(), 'comment' ); } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index e0e98be7a5..2da3569ff1 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4265,7 +4265,7 @@ function wp_scheduled_delete() { delete_comment_meta($comment_id, '_wp_trash_meta_time'); delete_comment_meta($comment_id, '_wp_trash_meta_status'); } else { - wp_delete_comment($comment_id); + wp_delete_comment( $del_comment ); } } } diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 3317284381..e54384671d 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1353,8 +1353,8 @@ if ( ! function_exists('wp_notify_postauthor') ) : * * @since 1.0.0 * - * @param int $comment_id Comment ID - * @param string $deprecated Not used + * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. + * @param string $deprecated Not used * @return bool True on completion. False if no email addresses were specified. */ function wp_notify_postauthor( $comment_id, $deprecated = null ) { @@ -1386,7 +1386,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { * @param array $emails An array of email addresses to receive a comment notification. * @param int $comment_id The comment ID. */ - $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id ); + $emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID ); $emails = array_filter( $emails ); // If there are no addresses to send the comment to, bail. @@ -1409,7 +1409,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { * Default false. * @param int $comment_id The comment ID. */ - $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); + $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); // The comment was left by the author if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { @@ -1475,12 +1475,13 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n"; $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment ) ) . "\r\n"; - if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) { - if ( EMPTY_TRASH_DAYS ) - $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n"; - else - $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n"; - $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n"; + if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) { + if ( EMPTY_TRASH_DAYS ) { + $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c={$comment->comment_ID}") ) . "\r\n"; + } else { + $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c={$comment->comment_ID}") ) . "\r\n"; + } + $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c={$comment->comment_ID}") ) . "\r\n"; } $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); @@ -1509,7 +1510,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { * @param string $notify_message The comment notification email text. * @param int $comment_id Comment ID. */ - $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id ); + $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID ); /** * Filter the comment notification email subject. @@ -1519,7 +1520,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { * @param string $subject The comment notification email subject. * @param int $comment_id Comment ID. */ - $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id ); + $subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID ); /** * Filter the comment notification email headers. @@ -1529,7 +1530,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { * @param string $message_headers Headers for the comment notification email. * @param int $comment_id Comment ID. */ - $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id ); + $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID ); foreach ( $emails as $email ) { @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); diff --git a/wp-includes/version.php b/wp-includes/version.php index aa6f10c550..45c7aeb22d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34128'; +$wp_version = '4.4-alpha-34129'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.