3 function comment_exists($comment_author, $comment_date) {
6 return $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments
7 WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");
10 function edit_comment() {
12 $comment_post_ID = (int) $_POST['comment_post_ID'];
14 if (!current_user_can( 'edit_post', $comment_post_ID ))
15 wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
17 $_POST['comment_author'] = $_POST['newcomment_author'];
18 $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
19 $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
20 $_POST['comment_approved'] = $_POST['comment_status'];
21 $_POST['comment_content'] = $_POST['content'];
22 $_POST['comment_ID'] = (int) $_POST['comment_ID'];
24 foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
25 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
26 $_POST['edit_date'] = '1';
32 if (!empty ( $_POST['edit_date'] ) ) {
39 $jj = ($jj > 31 ) ? 31 : $jj;
40 $hh = ($hh > 23 ) ? $hh -24 : $hh;
41 $mn = ($mn > 59 ) ? $mn -60 : $mn;
42 $ss = ($ss > 59 ) ? $ss -60 : $ss;
43 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
46 wp_update_comment( $_POST);
49 function get_comment_to_edit( $id ) {
50 if ( !$comment = get_comment($id) )
53 $comment->comment_ID = (int) $comment->comment_ID;
54 $comment->comment_post_ID = (int) $comment->comment_post_ID;
56 $comment->comment_content = format_to_edit( $comment->comment_content );
57 $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
59 $comment->comment_author = format_to_edit( $comment->comment_author );
60 $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
61 $comment->comment_author_url = clean_url($comment->comment_author_url);
62 $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
67 function get_pending_comments_num( $post_id ) {
71 if ( !is_array($post_id) ) {
72 $post_id = (array) $post_id;
75 $post_id = array_map('intval', $post_id);
76 $post_id = "'" . implode("', '", $post_id) . "'";
78 $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_N );
80 if ( empty($pending) )
84 return $pending[0][1];
86 $pending_keyed = array();
87 foreach ( $pending as $pend )
88 $pending_keyed[$pend[0]] = $pend[1];
90 return $pending_keyed;
93 // Add avatars to relevant places in admin, or try to
95 function floated_admin_avatar( $name ) {
98 $id = $avatar = false;
99 if ( $comment->comment_author_email )
100 $id = $comment->comment_author_email;
101 if ( $comment->user_id )
102 $id = $comment->user_id;
105 $avatar = get_avatar( $id, 32 );
107 return "$avatar $name";
110 if ( is_admin() && ('edit-comments.php' == $pagenow || 'edit.php' == $pagenow) ) {
111 if ( get_option('show_avatars') )
112 add_filter( 'comment_author', 'floated_admin_avatar' );