@@ -969,16 +969,16 @@ function wp_count_comments( $post_id = 0 ) {
969969 *
970970 * @global wpdb $wpdb WordPress database abstraction object.
971971 *
972- * @param int $comment_id Comment ID
973- * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
972+ * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
973+ * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
974974 * @return bool True on success, false on failure.
975975 */
976976function wp_delete_comment ($ comment_id , $ force_delete = false ) {
977977 global $ wpdb ;
978978 if (!$ comment = get_comment ($ comment_id ))
979979 return false ;
980980
981- if ( !$ force_delete && EMPTY_TRASH_DAYS && !in_array ( wp_get_comment_status ($ comment_id ), array ( 'trash ' , 'spam ' ) ) )
981+ if ( !$ force_delete && EMPTY_TRASH_DAYS && !in_array ( wp_get_comment_status ( $ comment ), array ( 'trash ' , 'spam ' ) ) )
982982 return wp_trash_comment ($ comment_id );
983983
984984 /**
@@ -988,21 +988,21 @@ function wp_delete_comment($comment_id, $force_delete = false) {
988988 *
989989 * @param int $comment_id The comment ID.
990990 */
991- do_action ( 'delete_comment ' , $ comment_id );
991+ do_action ( 'delete_comment ' , $ comment -> comment_ID );
992992
993993 // Move children up a level.
994- $ children = $ wpdb ->get_col ( $ wpdb ->prepare ("SELECT comment_ID FROM $ wpdb ->comments WHERE comment_parent = %d " , $ comment_id ) );
994+ $ children = $ wpdb ->get_col ( $ wpdb ->prepare ("SELECT comment_ID FROM $ wpdb ->comments WHERE comment_parent = %d " , $ comment -> comment_ID ) );
995995 if ( !empty ($ children ) ) {
996- $ wpdb ->update ($ wpdb ->comments , array ('comment_parent ' => $ comment ->comment_parent ), array ('comment_parent ' => $ comment_id ));
996+ $ wpdb ->update ($ wpdb ->comments , array ('comment_parent ' => $ comment ->comment_parent ), array ('comment_parent ' => $ comment -> comment_ID ));
997997 clean_comment_cache ($ children );
998998 }
999999
10001000 // Delete metadata
1001- $ meta_ids = $ wpdb ->get_col ( $ wpdb ->prepare ( "SELECT meta_id FROM $ wpdb ->commentmeta WHERE comment_id = %d " , $ comment_id ) );
1001+ $ meta_ids = $ wpdb ->get_col ( $ wpdb ->prepare ( "SELECT meta_id FROM $ wpdb ->commentmeta WHERE comment_id = %d " , $ comment -> comment_ID ) );
10021002 foreach ( $ meta_ids as $ mid )
10031003 delete_metadata_by_mid ( 'comment ' , $ mid );
10041004
1005- if ( ! $ wpdb ->delete ( $ wpdb ->comments , array ( 'comment_ID ' => $ comment_id ) ) )
1005+ if ( ! $ wpdb ->delete ( $ wpdb ->comments , array ( 'comment_ID ' => $ comment -> comment_ID ) ) )
10061006 return false ;
10071007
10081008 /**
@@ -1012,16 +1012,16 @@ function wp_delete_comment($comment_id, $force_delete = false) {
10121012 *
10131013 * @param int $comment_id The comment ID.
10141014 */
1015- do_action ( 'deleted_comment ' , $ comment_id );
1015+ do_action ( 'deleted_comment ' , $ comment -> comment_ID );
10161016
10171017 $ post_id = $ comment ->comment_post_ID ;
10181018 if ( $ post_id && $ comment ->comment_approved == 1 )
10191019 wp_update_comment_count ($ post_id );
10201020
1021- clean_comment_cache ($ comment_id );
1021+ clean_comment_cache ( $ comment -> comment_ID );
10221022
10231023 /** This action is documented in wp-includes/comment-functions.php */
1024- do_action ( 'wp_set_comment_status ' , $ comment_id , 'delete ' );
1024+ do_action ( 'wp_set_comment_status ' , $ comment -> comment_ID , 'delete ' );
10251025
10261026 wp_transition_comment_status ('delete ' , $ comment ->comment_approved , $ comment );
10271027 return true ;
@@ -1034,7 +1034,7 @@ function wp_delete_comment($comment_id, $force_delete = false) {
10341034 *
10351035 * @since 2.9.0
10361036 *
1037- * @param int $comment_id Comment ID.
1037+ * @param int|WP_Comment $comment_id Comment ID or WP_Comment object .
10381038 * @return bool True on success, false on failure.
10391039 */
10401040function wp_trash_comment ($ comment_id ) {
@@ -1051,13 +1051,13 @@ function wp_trash_comment($comment_id) {
10511051 *
10521052 * @param int $comment_id The comment ID.
10531053 */
1054- do_action ( 'trash_comment ' , $ comment_id );
1054+ do_action ( 'trash_comment ' , $ comment -> comment_ID );
10551055
1056- if ( wp_set_comment_status ($ comment_id , 'trash ' ) ) {
1057- delete_comment_meta ( $ comment_id , '_wp_trash_meta_status ' );
1058- delete_comment_meta ( $ comment_id , '_wp_trash_meta_time ' );
1059- add_comment_meta ( $ comment_id , '_wp_trash_meta_status ' , $ comment ->comment_approved );
1060- add_comment_meta ( $ comment_id , '_wp_trash_meta_time ' , time () );
1056+ if ( wp_set_comment_status ( $ comment , 'trash ' ) ) {
1057+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' );
1058+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_time ' );
1059+ add_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' , $ comment ->comment_approved );
1060+ add_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_time ' , time () );
10611061
10621062 /**
10631063 * Fires immediately after a comment is sent to Trash.
@@ -1066,7 +1066,7 @@ function wp_trash_comment($comment_id) {
10661066 *
10671067 * @param int $comment_id The comment ID.
10681068 */
1069- do_action ( 'trashed_comment ' , $ comment_id );
1069+ do_action ( 'trashed_comment ' , $ comment -> comment_ID );
10701070 return true ;
10711071 }
10721072
@@ -1078,12 +1078,14 @@ function wp_trash_comment($comment_id) {
10781078 *
10791079 * @since 2.9.0
10801080 *
1081- * @param int $comment_id Comment ID.
1081+ * @param int|WP_Comment $comment_id Comment ID or WP_Comment object .
10821082 * @return bool True on success, false on failure.
10831083 */
10841084function wp_untrash_comment ($ comment_id ) {
1085- if ( ! (int )$ comment_id )
1085+ $ comment = get_comment ( $ comment_id );
1086+ if ( ! $ comment ) {
10861087 return false ;
1088+ }
10871089
10881090 /**
10891091 * Fires immediately before a comment is restored from the Trash.
@@ -1092,23 +1094,23 @@ function wp_untrash_comment($comment_id) {
10921094 *
10931095 * @param int $comment_id The comment ID.
10941096 */
1095- do_action ( 'untrash_comment ' , $ comment_id );
1097+ do_action ( 'untrash_comment ' , $ comment -> comment_ID );
10961098
1097- $ status = (string ) get_comment_meta ($ comment_id , '_wp_trash_meta_status ' , true );
1099+ $ status = (string ) get_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' , true );
10981100 if ( empty ($ status ) )
10991101 $ status = '0 ' ;
11001102
1101- if ( wp_set_comment_status ($ comment_id , $ status ) ) {
1102- delete_comment_meta ($ comment_id , '_wp_trash_meta_time ' );
1103- delete_comment_meta ($ comment_id , '_wp_trash_meta_status ' );
1103+ if ( wp_set_comment_status ( $ comment , $ status ) ) {
1104+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_time ' );
1105+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' );
11041106 /**
11051107 * Fires immediately after a comment is restored from the Trash.
11061108 *
11071109 * @since 2.9.0
11081110 *
11091111 * @param int $comment_id The comment ID.
11101112 */
1111- do_action ( 'untrashed_comment ' , $ comment_id );
1113+ do_action ( 'untrashed_comment ' , $ comment -> comment_ID );
11121114 return true ;
11131115 }
11141116
@@ -1120,12 +1122,14 @@ function wp_untrash_comment($comment_id) {
11201122 *
11211123 * @since 2.9.0
11221124 *
1123- * @param int $comment_id Comment ID.
1125+ * @param int|WP_Comment $comment_id Comment ID or WP_Comment object .
11241126 * @return bool True on success, false on failure.
11251127 */
1126- function wp_spam_comment ($ comment_id ) {
1127- if ( !$ comment = get_comment ($ comment_id ) )
1128+ function wp_spam_comment ( $ comment_id ) {
1129+ $ comment = get_comment ( $ comment_id );
1130+ if ( ! $ comment ) {
11281131 return false ;
1132+ }
11291133
11301134 /**
11311135 * Fires immediately before a comment is marked as Spam.
@@ -1134,21 +1138,21 @@ function wp_spam_comment($comment_id) {
11341138 *
11351139 * @param int $comment_id The comment ID.
11361140 */
1137- do_action ( 'spam_comment ' , $ comment_id );
1141+ do_action ( 'spam_comment ' , $ comment -> comment_ID );
11381142
1139- if ( wp_set_comment_status ($ comment_id , 'spam ' ) ) {
1140- delete_comment_meta ( $ comment_id , '_wp_trash_meta_status ' );
1141- delete_comment_meta ( $ comment_id , '_wp_trash_meta_time ' );
1142- add_comment_meta ( $ comment_id , '_wp_trash_meta_status ' , $ comment ->comment_approved );
1143- add_comment_meta ( $ comment_id , '_wp_trash_meta_time ' , time () );
1143+ if ( wp_set_comment_status ( $ comment , 'spam ' ) ) {
1144+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' );
1145+ delete_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_time ' );
1146+ add_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_status ' , $ comment ->comment_approved );
1147+ add_comment_meta ( $ comment -> comment_ID , '_wp_trash_meta_time ' , time () );
11441148 /**
11451149 * Fires immediately after a comment is marked as Spam.
11461150 *
11471151 * @since 2.9.0
11481152 *
11491153 * @param int $comment_id The comment ID.
11501154 */
1151- do_action ( 'spammed_comment ' , $ comment_id );
1155+ do_action ( 'spammed_comment ' , $ comment -> comment_ID );
11521156 return true ;
11531157 }
11541158
@@ -1167,6 +1171,11 @@ function wp_unspam_comment($comment_id) {
11671171 if ( ! (int )$ comment_id )
11681172 return false ;
11691173
1174+ $ comment = get_comment ( $ comment_id );
1175+ if ( ! $ comment ) {
1176+ return false ;
1177+ }
1178+
11701179 /**
11711180 * Fires immediately before a comment is unmarked as Spam.
11721181 *
@@ -1180,7 +1189,7 @@ function wp_unspam_comment($comment_id) {
11801189 if ( empty ($ status ) )
11811190 $ status = '0 ' ;
11821191
1183- if ( wp_set_comment_status ($ comment_id , $ status ) ) {
1192+ if ( wp_set_comment_status ( $ comment , $ status ) ) {
11841193 delete_comment_meta ( $ comment_id , '_wp_trash_meta_status ' );
11851194 delete_comment_meta ( $ comment_id , '_wp_trash_meta_time ' );
11861195 /**
@@ -1675,9 +1684,9 @@ function wp_new_comment_notify_postauthor( $comment_ID ) {
16751684 *
16761685 * global wpdb $wpdb
16771686 *
1678- * @param int $comment_id Comment ID.
1679- * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
1680- * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
1687+ * @param int|WP_Comment $comment_id Comment ID or WP_Comment object .
1688+ * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
1689+ * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
16811690 * @return bool|WP_Error True on success, false or WP_Error on failure.
16821691 */
16831692function 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)
17071716
17081717 $ comment_old = clone get_comment ($ comment_id );
17091718
1710- if ( !$ wpdb ->update ( $ wpdb ->comments , array ('comment_approved ' => $ status ), array ('comment_ID ' => $ comment_id ) ) ) {
1719+ if ( !$ wpdb ->update ( $ wpdb ->comments , array ('comment_approved ' => $ status ), array ( 'comment_ID ' => $ comment_old -> comment_ID ) ) ) {
17111720 if ( $ wp_error )
17121721 return new WP_Error ('db_update_error ' , __ ('Could not update comment status ' ), $ wpdb ->last_error );
17131722 else
17141723 return false ;
17151724 }
17161725
1717- clean_comment_cache ($ comment_id );
1726+ clean_comment_cache ( $ comment_old -> comment_ID );
17181727
1719- $ comment = get_comment ($ comment_id );
1728+ $ comment = get_comment ( $ comment_old -> comment_ID );
17201729
17211730 /**
17221731 * 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)
17281737 * @param string|bool $comment_status Current comment status. Possible values include
17291738 * 'hold', 'approve', 'spam', 'trash', or false.
17301739 */
1731- do_action ( 'wp_set_comment_status ' , $ comment_id , $ comment_status );
1740+ do_action ( 'wp_set_comment_status ' , $ comment -> comment_ID , $ comment_status );
17321741
17331742 wp_transition_comment_status ($ comment_status , $ comment_old ->comment_approved , $ comment );
17341743
@@ -2316,8 +2325,10 @@ function xmlrpc_pingback_error( $ixr_error ) {
23162325 * @param int|array $ids Comment ID or array of comment IDs to remove from cache
23172326 */
23182327function clean_comment_cache ($ ids ) {
2319- foreach ( (array ) $ ids as $ id )
2320- wp_cache_delete ($ id , 'comment ' );
2328+ foreach ( (array ) $ ids as $ id ) {
2329+ wp_cache_delete ( $ id , 'comment ' );
2330+ wp_cache_delete ( "comment- {$ id }" , 'counts ' );
2331+ }
23212332
23222333 wp_cache_set ( 'last_changed ' , microtime (), 'comment ' );
23232334}
0 commit comments