Conditions | 9 |
Paths | 145 |
Total Lines | 146 |
Code Lines | 88 |
Lines | 48 |
Ratio | 32.88 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
207 | function wp_notify_moderator( $comment_id ) { |
||
208 | global $wpdb; |
||
209 | |||
210 | $maybe_notify = get_option( 'moderation_notify' ); |
||
211 | |||
212 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
||
213 | $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id ); |
||
214 | |||
215 | if ( ! $maybe_notify ) { |
||
216 | return true; |
||
217 | } |
||
218 | |||
219 | $comment = get_comment( $comment_id ); |
||
220 | $post = get_post( $comment->comment_post_ID ); |
||
221 | $user = get_userdata( $post->post_author ); |
||
222 | // Send to the administration and to the post author if the author can modify the comment. |
||
223 | $emails = array( get_option( 'admin_email' ) ); |
||
224 | if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { |
||
225 | if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { |
||
226 | $emails[] = $user->user_email; |
||
227 | } |
||
228 | } |
||
229 | |||
230 | $switched_locale = switch_to_locale( get_locale() ); |
||
231 | |||
232 | $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); |
||
233 | $comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" ); |
||
234 | |||
235 | // The blogname option is escaped with esc_html on the way into the database in sanitize_option |
||
236 | // we want to reverse this for the plain text arena of emails. |
||
237 | $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
||
238 | $comment_content = wp_specialchars_decode( $comment->comment_content ); |
||
239 | |||
240 | switch ( $comment->comment_type ) { |
||
241 | View Code Duplication | case 'trackback': |
|
242 | /* translators: 1: Post title */ |
||
243 | $notify_message = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
||
244 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
||
245 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
||
246 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
||
247 | /* translators: 1: Trackback/pingback/comment author URL */ |
||
248 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
||
249 | $notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
||
250 | break; |
||
251 | View Code Duplication | case 'pingback': |
|
252 | /* translators: 1: Post title */ |
||
253 | $notify_message = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
||
254 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
||
255 | /* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */ |
||
256 | $notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
||
257 | /* translators: 1: Trackback/pingback/comment author URL */ |
||
258 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
||
259 | $notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n"; |
||
260 | break; |
||
261 | View Code Duplication | default: // Comments |
|
262 | /* translators: 1: Post title */ |
||
263 | $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; |
||
264 | $notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n"; |
||
265 | /* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */ |
||
266 | $notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; |
||
267 | /* translators: 1: Comment author URL */ |
||
268 | $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; |
||
269 | /* translators: 1: Trackback/pingback/comment author URL */ |
||
270 | $notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n"; |
||
271 | /* translators: 1: Comment text */ |
||
272 | $notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n"; |
||
273 | break; |
||
274 | } |
||
275 | |||
276 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
||
277 | $emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id ); |
||
278 | |||
279 | function is_user_connected( $email ) { |
||
280 | $user = get_user_by( 'email', $email ); |
||
281 | return Jetpack::is_user_connected( $user->ID ); |
||
282 | } |
||
283 | |||
284 | $moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) ); |
||
285 | |||
286 | $primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); |
||
287 | |||
288 | /* translators: Comment moderation. 1: Comment action URL */ |
||
289 | $notify_message .= sprintf( |
||
290 | __( 'Approve it: %s' ), $moderate_on_wpcom |
||
291 | ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=approve" |
||
292 | : admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" ) |
||
293 | ) . "\r\n"; |
||
294 | |||
295 | View Code Duplication | if ( EMPTY_TRASH_DAYS ) { |
|
296 | /* translators: Comment moderation. 1: Comment action URL */ |
||
297 | $notify_message .= sprintf( |
||
298 | __( 'Trash it: %s' ), $moderate_on_wpcom |
||
299 | ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=trash" |
||
300 | : admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" ) |
||
301 | ) . "\r\n"; |
||
302 | } else { |
||
303 | /* translators: Comment moderation. 1: Comment action URL */ |
||
304 | $notify_message .= sprintf( |
||
305 | __( 'Delete it: %s' ), $moderate_on_wpcom |
||
306 | ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=delete" |
||
307 | : admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" ) |
||
308 | ) . "\r\n"; |
||
309 | } |
||
310 | |||
311 | /* translators: Comment moderation. 1: Comment action URL */ |
||
312 | $notify_message .= sprintf( |
||
313 | __( 'Spam it: %s' ), $moderate_on_wpcom |
||
314 | ? "https://wordpress.com/comment/{$primary_site_slug}/{$comment_id}?action=spam" |
||
315 | : admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" ) |
||
316 | ) . "\r\n"; |
||
317 | |||
318 | /* translators: Comment moderation. 1: Number of comments awaiting approval */ |
||
319 | $notify_message .= sprintf( |
||
320 | _n( |
||
321 | 'Currently %s comment is waiting for approval. Please visit the moderation panel:', |
||
322 | 'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comments_waiting |
||
323 | ), number_format_i18n( $comments_waiting ) |
||
324 | ) . "\r\n"; |
||
325 | |||
326 | $notify_message .= $moderate_on_wpcom |
||
327 | ? "https://wordpress.com/comments/pending/{$primary_site_slug}/" |
||
328 | : admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n"; |
||
329 | |||
330 | /* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */ |
||
331 | $subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title ); |
||
332 | $message_headers = ''; |
||
333 | |||
334 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
||
335 | $notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id ); |
||
336 | |||
337 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
||
338 | $subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id ); |
||
339 | |||
340 | /** This filter is documented in core/src/wp-includes/pluggable.php */ |
||
341 | $message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id ); |
||
342 | |||
343 | foreach ( $emails as $email ) { |
||
344 | @wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers ); |
||
345 | } |
||
346 | |||
347 | if ( $switched_locale ) { |
||
348 | restore_previous_locale(); |
||
349 | } |
||
350 | |||
351 | return true; |
||
352 | } |
||
353 | endif; |
||
354 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.