Changeset 34129 for trunk/src/wp-includes/comment-functions.php
- Timestamp:
- 09/14/2015 09:39:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-functions.php
r34106 r34129 970 970 * @global wpdb $wpdb WordPress database abstraction object. 971 971 * 972 * @param int $comment_id Comment ID973 * @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. 974 974 * @return bool True on success, false on failure. 975 975 */ … … 979 979 return false; 980 980 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' ) ) ) 982 982 return wp_trash_comment($comment_id); 983 983 … … 989 989 * @param int $comment_id The comment ID. 990 990 */ 991 do_action( 'delete_comment', $comment _id);991 do_action( 'delete_comment', $comment->comment_ID ); 992 992 993 993 // 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) ); 995 995 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)); 997 997 clean_comment_cache($children); 998 998 } 999 999 1000 1000 // 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 ) ); 1002 1002 foreach ( $meta_ids as $mid ) 1003 1003 delete_metadata_by_mid( 'comment', $mid ); 1004 1004 1005 if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment _id) ) )1005 if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment->comment_ID ) ) ) 1006 1006 return false; 1007 1007 … … 1013 1013 * @param int $comment_id The comment ID. 1014 1014 */ 1015 do_action( 'deleted_comment', $comment _id);1015 do_action( 'deleted_comment', $comment->comment_ID ); 1016 1016 1017 1017 $post_id = $comment->comment_post_ID; … … 1019 1019 wp_update_comment_count($post_id); 1020 1020 1021 clean_comment_cache( $comment_id);1021 clean_comment_cache( $comment->comment_ID ); 1022 1022 1023 1023 /** 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' ); 1025 1025 1026 1026 wp_transition_comment_status('delete', $comment->comment_approved, $comment); … … 1035 1035 * @since 2.9.0 1036 1036 * 1037 * @param int $comment_id Comment ID.1037 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 1038 1038 * @return bool True on success, false on failure. 1039 1039 */ … … 1052 1052 * @param int $comment_id The comment ID. 1053 1053 */ 1054 do_action( 'trash_comment', $comment _id);1055 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() );1054 do_action( 'trash_comment', $comment->comment_ID ); 1055 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() ); 1061 1061 1062 1062 /** … … 1067 1067 * @param int $comment_id The comment ID. 1068 1068 */ 1069 do_action( 'trashed_comment', $comment _id);1069 do_action( 'trashed_comment', $comment->comment_ID ); 1070 1070 return true; 1071 1071 } … … 1076 1076 /** 1077 1077 * Removes a comment from the Trash 1078 * 1079 * @since 2.9.0 1080 * 1081 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 1082 * @return bool True on success, false on failure. 1083 */ 1084 function wp_untrash_comment($comment_id) { 1085 $comment = get_comment( $comment_id ); 1086 if ( ! $comment ) { 1087 return false; 1088 } 1089 1090 /** 1091 * Fires immediately before a comment is restored from the Trash. 1092 * 1093 * @since 2.9.0 1094 * 1095 * @param int $comment_id The comment ID. 1096 */ 1097 do_action( 'untrash_comment', $comment->comment_ID ); 1098 1099 $status = (string) get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ); 1100 if ( empty($status) ) 1101 $status = '0'; 1102 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' ); 1106 /** 1107 * Fires immediately after a comment is restored from the Trash. 1108 * 1109 * @since 2.9.0 1110 * 1111 * @param int $comment_id The comment ID. 1112 */ 1113 do_action( 'untrashed_comment', $comment->comment_ID ); 1114 return true; 1115 } 1116 1117 return false; 1118 } 1119 1120 /** 1121 * Marks a comment as Spam 1122 * 1123 * @since 2.9.0 1124 * 1125 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. 1126 * @return bool True on success, false on failure. 1127 */ 1128 function wp_spam_comment( $comment_id ) { 1129 $comment = get_comment( $comment_id ); 1130 if ( ! $comment ) { 1131 return false; 1132 } 1133 1134 /** 1135 * Fires immediately before a comment is marked as Spam. 1136 * 1137 * @since 2.9.0 1138 * 1139 * @param int $comment_id The comment ID. 1140 */ 1141 do_action( 'spam_comment', $comment->comment_ID ); 1142 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() ); 1148 /** 1149 * Fires immediately after a comment is marked as Spam. 1150 * 1151 * @since 2.9.0 1152 * 1153 * @param int $comment_id The comment ID. 1154 */ 1155 do_action( 'spammed_comment', $comment->comment_ID ); 1156 return true; 1157 } 1158 1159 return false; 1160 } 1161 1162 /** 1163 * Removes a comment from the Spam 1078 1164 * 1079 1165 * @since 2.9.0 … … 1082 1168 * @return bool True on success, false on failure. 1083 1169 */ 1084 function wp_un trash_comment($comment_id) {1170 function wp_unspam_comment($comment_id) { 1085 1171 if ( ! (int)$comment_id ) 1086 1172 return false; 1087 1173 1088 /** 1089 * Fires immediately before a comment is restored from the Trash. 1174 $comment = get_comment( $comment_id ); 1175 if ( ! $comment ) { 1176 return false; 1177 } 1178 1179 /** 1180 * Fires immediately before a comment is unmarked as Spam. 1090 1181 * 1091 1182 * @since 2.9.0 … … 1093 1184 * @param int $comment_id The comment ID. 1094 1185 */ 1095 do_action( 'un trash_comment', $comment_id );1186 do_action( 'unspam_comment', $comment_id ); 1096 1187 1097 1188 $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true); … … 1099 1190 $status = '0'; 1100 1191 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'); 1104 /** 1105 * Fires immediately after a comment is restored from the Trash. 1106 * 1107 * @since 2.9.0 1108 * 1109 * @param int $comment_id The comment ID. 1110 */ 1111 do_action( 'untrashed_comment', $comment_id ); 1112 return true; 1113 } 1114 1115 return false; 1116 } 1117 1118 /** 1119 * Marks a comment as Spam 1120 * 1121 * @since 2.9.0 1122 * 1123 * @param int $comment_id Comment ID. 1124 * @return bool True on success, false on failure. 1125 */ 1126 function wp_spam_comment($comment_id) { 1127 if ( !$comment = get_comment($comment_id) ) 1128 return false; 1129 1130 /** 1131 * Fires immediately before a comment is marked as Spam. 1132 * 1133 * @since 2.9.0 1134 * 1135 * @param int $comment_id The comment ID. 1136 */ 1137 do_action( 'spam_comment', $comment_id ); 1138 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() ); 1144 /** 1145 * Fires immediately after a comment is marked as Spam. 1146 * 1147 * @since 2.9.0 1148 * 1149 * @param int $comment_id The comment ID. 1150 */ 1151 do_action( 'spammed_comment', $comment_id ); 1152 return true; 1153 } 1154 1155 return false; 1156 } 1157 1158 /** 1159 * Removes a comment from the Spam 1160 * 1161 * @since 2.9.0 1162 * 1163 * @param int $comment_id Comment ID. 1164 * @return bool True on success, false on failure. 1165 */ 1166 function wp_unspam_comment($comment_id) { 1167 if ( ! (int)$comment_id ) 1168 return false; 1169 1170 /** 1171 * Fires immediately before a comment is unmarked as Spam. 1172 * 1173 * @since 2.9.0 1174 * 1175 * @param int $comment_id The comment ID. 1176 */ 1177 do_action( 'unspam_comment', $comment_id ); 1178 1179 $status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true); 1180 if ( empty($status) ) 1181 $status = '0'; 1182 1183 if ( wp_set_comment_status($comment_id, $status) ) { 1192 if ( wp_set_comment_status( $comment, $status ) ) { 1184 1193 delete_comment_meta( $comment_id, '_wp_trash_meta_status' ); 1185 1194 delete_comment_meta( $comment_id, '_wp_trash_meta_time' ); … … 1676 1685 * global wpdb $wpdb 1677 1686 * 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_errorWhether 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. 1681 1690 * @return bool|WP_Error True on success, false or WP_Error on failure. 1682 1691 */ … … 1708 1717 $comment_old = clone get_comment($comment_id); 1709 1718 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 ) ) ) { 1711 1720 if ( $wp_error ) 1712 1721 return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error); … … 1715 1724 } 1716 1725 1717 clean_comment_cache( $comment_id);1718 1719 $comment = get_comment( $comment_id);1726 clean_comment_cache( $comment_old->comment_ID ); 1727 1728 $comment = get_comment( $comment_old->comment_ID ); 1720 1729 1721 1730 /** … … 1729 1738 * 'hold', 'approve', 'spam', 'trash', or false. 1730 1739 */ 1731 do_action( 'wp_set_comment_status', $comment _id, $comment_status );1740 do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); 1732 1741 1733 1742 wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); … … 2317 2326 */ 2318 2327 function 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 } 2321 2332 2322 2333 wp_cache_set( 'last_changed', microtime(), 'comment' );
Note: See TracChangeset
for help on using the changeset viewer.