30 $date_field = 'comment_date'; |
30 $date_field = 'comment_date'; |
31 if ( 'gmt' === $timezone ) { |
31 if ( 'gmt' === $timezone ) { |
32 $date_field = 'comment_date_gmt'; |
32 $date_field = 'comment_date_gmt'; |
33 } |
33 } |
34 |
34 |
35 return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments |
35 return $wpdb->get_var( |
|
36 $wpdb->prepare( |
|
37 "SELECT comment_post_ID FROM $wpdb->comments |
36 WHERE comment_author = %s AND $date_field = %s", |
38 WHERE comment_author = %s AND $date_field = %s", |
37 stripslashes( $comment_author ), |
39 stripslashes( $comment_author ), |
38 stripslashes( $comment_date ) |
40 stripslashes( $comment_date ) |
39 ) ); |
41 ) |
|
42 ); |
40 } |
43 } |
41 |
44 |
42 /** |
45 /** |
43 * Update a comment with values provided in $_POST. |
46 * Update a comment with values provided in $_POST. |
44 * |
47 * |
45 * @since 2.0.0 |
48 * @since 2.0.0 |
46 */ |
49 */ |
47 function edit_comment() { |
50 function edit_comment() { |
48 if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) |
51 if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) { |
49 wp_die ( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); |
52 wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) ); |
50 |
53 } |
51 if ( isset( $_POST['newcomment_author'] ) ) |
54 |
|
55 if ( isset( $_POST['newcomment_author'] ) ) { |
52 $_POST['comment_author'] = $_POST['newcomment_author']; |
56 $_POST['comment_author'] = $_POST['newcomment_author']; |
53 if ( isset( $_POST['newcomment_author_email'] ) ) |
57 } |
|
58 if ( isset( $_POST['newcomment_author_email'] ) ) { |
54 $_POST['comment_author_email'] = $_POST['newcomment_author_email']; |
59 $_POST['comment_author_email'] = $_POST['newcomment_author_email']; |
55 if ( isset( $_POST['newcomment_author_url'] ) ) |
60 } |
|
61 if ( isset( $_POST['newcomment_author_url'] ) ) { |
56 $_POST['comment_author_url'] = $_POST['newcomment_author_url']; |
62 $_POST['comment_author_url'] = $_POST['newcomment_author_url']; |
57 if ( isset( $_POST['comment_status'] ) ) |
63 } |
|
64 if ( isset( $_POST['comment_status'] ) ) { |
58 $_POST['comment_approved'] = $_POST['comment_status']; |
65 $_POST['comment_approved'] = $_POST['comment_status']; |
59 if ( isset( $_POST['content'] ) ) |
66 } |
|
67 if ( isset( $_POST['content'] ) ) { |
60 $_POST['comment_content'] = $_POST['content']; |
68 $_POST['comment_content'] = $_POST['content']; |
61 if ( isset( $_POST['comment_ID'] ) ) |
69 } |
|
70 if ( isset( $_POST['comment_ID'] ) ) { |
62 $_POST['comment_ID'] = (int) $_POST['comment_ID']; |
71 $_POST['comment_ID'] = (int) $_POST['comment_ID']; |
63 |
72 } |
64 foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { |
73 |
65 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) { |
74 foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) { |
|
75 if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] != $_POST[ $timeunit ] ) { |
66 $_POST['edit_date'] = '1'; |
76 $_POST['edit_date'] = '1'; |
67 break; |
77 break; |
68 } |
78 } |
69 } |
79 } |
70 |
80 |
71 if ( !empty ( $_POST['edit_date'] ) ) { |
81 if ( ! empty( $_POST['edit_date'] ) ) { |
72 $aa = $_POST['aa']; |
82 $aa = $_POST['aa']; |
73 $mm = $_POST['mm']; |
83 $mm = $_POST['mm']; |
74 $jj = $_POST['jj']; |
84 $jj = $_POST['jj']; |
75 $hh = $_POST['hh']; |
85 $hh = $_POST['hh']; |
76 $mn = $_POST['mn']; |
86 $mn = $_POST['mn']; |
77 $ss = $_POST['ss']; |
87 $ss = $_POST['ss']; |
78 $jj = ($jj > 31 ) ? 31 : $jj; |
88 $jj = ( $jj > 31 ) ? 31 : $jj; |
79 $hh = ($hh > 23 ) ? $hh -24 : $hh; |
89 $hh = ( $hh > 23 ) ? $hh - 24 : $hh; |
80 $mn = ($mn > 59 ) ? $mn -60 : $mn; |
90 $mn = ( $mn > 59 ) ? $mn - 60 : $mn; |
81 $ss = ($ss > 59 ) ? $ss -60 : $ss; |
91 $ss = ( $ss > 59 ) ? $ss - 60 : $ss; |
82 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
92 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
83 } |
93 } |
84 |
94 |
85 wp_update_comment( $_POST ); |
95 wp_update_comment( $_POST ); |
86 } |
96 } |
92 * |
102 * |
93 * @param int $id ID of comment to retrieve. |
103 * @param int $id ID of comment to retrieve. |
94 * @return WP_Comment|false Comment if found. False on failure. |
104 * @return WP_Comment|false Comment if found. False on failure. |
95 */ |
105 */ |
96 function get_comment_to_edit( $id ) { |
106 function get_comment_to_edit( $id ) { |
97 if ( !$comment = get_comment($id) ) |
107 if ( ! $comment = get_comment( $id ) ) { |
98 return false; |
108 return false; |
99 |
109 } |
100 $comment->comment_ID = (int) $comment->comment_ID; |
110 |
|
111 $comment->comment_ID = (int) $comment->comment_ID; |
101 $comment->comment_post_ID = (int) $comment->comment_post_ID; |
112 $comment->comment_post_ID = (int) $comment->comment_post_ID; |
102 |
113 |
103 $comment->comment_content = format_to_edit( $comment->comment_content ); |
114 $comment->comment_content = format_to_edit( $comment->comment_content ); |
104 /** |
115 /** |
105 * Filters the comment content before editing. |
116 * Filters the comment content before editing. |
130 */ |
141 */ |
131 function get_pending_comments_num( $post_id ) { |
142 function get_pending_comments_num( $post_id ) { |
132 global $wpdb; |
143 global $wpdb; |
133 |
144 |
134 $single = false; |
145 $single = false; |
135 if ( !is_array($post_id) ) { |
146 if ( ! is_array( $post_id ) ) { |
136 $post_id_array = (array) $post_id; |
147 $post_id_array = (array) $post_id; |
137 $single = true; |
148 $single = true; |
138 } else { |
149 } else { |
139 $post_id_array = $post_id; |
150 $post_id_array = $post_id; |
140 } |
151 } |
141 $post_id_array = array_map('intval', $post_id_array); |
152 $post_id_array = array_map( 'intval', $post_id_array ); |
142 $post_id_in = "'" . implode("', '", $post_id_array) . "'"; |
153 $post_id_in = "'" . implode( "', '", $post_id_array ) . "'"; |
143 |
154 |
144 $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A ); |
155 $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A ); |
145 |
156 |
146 if ( $single ) { |
157 if ( $single ) { |
147 if ( empty($pending) ) |
158 if ( empty( $pending ) ) { |
148 return 0; |
159 return 0; |
149 else |
160 } else { |
150 return absint($pending[0]['num_comments']); |
161 return absint( $pending[0]['num_comments'] ); |
|
162 } |
151 } |
163 } |
152 |
164 |
153 $pending_keyed = array(); |
165 $pending_keyed = array(); |
154 |
166 |
155 // Default to zero pending for all posts in request |
167 // Default to zero pending for all posts in request |
156 foreach ( $post_id_array as $id ) |
168 foreach ( $post_id_array as $id ) { |
157 $pending_keyed[$id] = 0; |
169 $pending_keyed[ $id ] = 0; |
158 |
170 } |
159 if ( !empty($pending) ) |
171 |
160 foreach ( $pending as $pend ) |
172 if ( ! empty( $pending ) ) { |
161 $pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']); |
173 foreach ( $pending as $pend ) { |
|
174 $pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] ); |
|
175 } |
|
176 } |
162 |
177 |
163 return $pending_keyed; |
178 return $pending_keyed; |
164 } |
179 } |
165 |
180 |
166 /** |
181 /** |