Completed
Push — add/sync-partial-sync-checksum... ( 93f4e2...c9ed3f )
by
unknown
253:26 queued 243:12
created

functions.wp-notify.php ➔ wp_notify_moderator()   C

Complexity

Conditions 9
Paths 145

Size

Total Lines 159

Duplication

Lines 50
Ratio 31.45 %

Importance

Changes 0
Metric Value
cc 9
nc 145
nop 1
dl 50
loc 159
rs 6.1444
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/** phpcs:disable Squiz.Commenting.FileComment.MissingPackageTag,Generic.Commenting.DocComment.MissingShort
3
 * Register two plugabble functions to handle notification emails to authors and moderators.
4
 */
5
6
use Automattic\Jetpack\Redirect;
7
8
// phpcs:disable WordPress.WP.I18n.MissingArgDomain --reason: WP Core string.
9
10
if ( ! function_exists( 'wp_notify_postauthor' ) && Jetpack::is_active() ) :
11
	/**
12
	 * Notify an author (and/or others) of a comment/trackback/pingback on a post.
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
17
	 * @param string         $deprecated Not used.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $deprecated not be string|null?

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.

Loading history...
18
	 * @return bool True on completion. False if no email addresses were specified.
19
	 */
20
	function wp_notify_postauthor( $comment_id, $deprecated = null ) {
21
		if ( null !== $deprecated ) {
22
			_deprecated_argument( __FUNCTION__, '3.8.0' );
23
		}
24
25
		$comment = get_comment( $comment_id );
26
27
		if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) {
28
			return false;
29
		}
30
31
		$post   = get_post( $comment->comment_post_ID );
32
		$author = get_userdata( $post->post_author );
33
34
		// Who to notify? By default, just the post author, but others can be added.
35
		$emails = array();
36
		if ( $author ) {
37
			$emails[] = $author->user_email;
38
		}
39
40
		/** This filter is documented in core/src/wp-includes/pluggable.php */
41
		$emails = apply_filters( 'comment_notification_recipients', $emails, $comment->comment_ID );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment->comment_ID.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
		$emails = array_filter( $emails );
43
44
		// If there are no addresses to send the comment to, bail.
45
		if ( ! count( $emails ) ) {
46
			return false;
47
		}
48
49
		// Facilitate unsetting below without knowing the keys.
50
		$emails = array_flip( $emails );
51
52
		/** This filter is documented in core/src/wp-includes/pluggable.php */
53
		$notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment->comment_ID.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
55
		// The comment was left by the author.
56
		if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
57
			unset( $emails[ $author->user_email ] );
58
		}
59
60
		// The author moderated a comment on their own post.
61
		if ( $author && ! $notify_author && get_current_user_id() == $post->post_author ) {
62
			unset( $emails[ $author->user_email ] );
63
		}
64
65
		// The post author is no longer a member of the blog.
66
		if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
67
			unset( $emails[ $author->user_email ] );
68
		}
69
70
		// If there's no email to send the comment to, bail, otherwise flip array back around for use below.
71
		if ( ! count( $emails ) ) {
72
			return false;
73
		} else {
74
			$emails = array_flip( $emails );
75
		}
76
77
		$switched_locale = switch_to_locale( get_locale() );
78
79
		$comment_author_domain = @gethostbyaddr( $comment->comment_author_IP );
80
81
		// The blogname option is escaped with esc_html on the way into the database in sanitize_option
82
		// we want to reverse this for the plain text arena of emails.
83
		$blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
84
		$comment_content = wp_specialchars_decode( $comment->comment_content );
85
86
		// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
87
		function is_user_connected( $email ) {
88
			$user = get_user_by( 'email', $email );
89
			return Jetpack::is_user_connected( $user->ID );
90
		}
91
92
		$moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) );
93
94
		switch ( $comment->comment_type ) {
95 View Code Duplication
			case 'trackback':
96
				/* translators: 1: Post title */
97
				$notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
98
				/* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
99
				$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
100
				/* translators: %s: Site URL */
101
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
102
				/* translators: %s: Comment Content */
103
				$notify_message     .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
104
					$notify_message .= __( 'You can see all trackbacks on this post here:' ) . "\r\n";
105
					/* translators: 1: blog name, 2: post title */
106
					$subject = sprintf( __( '[%1$s] Trackback: "%2$s"' ), $blogname, $post->post_title );
107
				break;
108 View Code Duplication
			case 'pingback':
109
				/* translators: 1: Post title */
110
				$notify_message = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "\r\n";
111
				/* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
112
				$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
113
				/* translators: %s: Site URL */
114
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
115
				/* translators: %s: Comment Content */
116
				$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
117
				$notify_message .= __( 'You can see all pingbacks on this post here:' ) . "\r\n";
118
				/* translators: 1: blog name, 2: post title */
119
				$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
120
				break;
121
			default: // Comments.
122
				/* translators: 1: Post title */
123
				$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
124
				/* translators: 1: comment author, 2: comment author's IP address, 3: comment author's hostname */
125
				$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
126
				/* translators: %s: Email address */
127
				$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
128
				/* translators: %s: Site URL */
129
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
130
				/* translators: %s: Comment Content */
131
				$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
132
				$notify_message .= __( 'You can see all comments on this post here:' ) . "\r\n";
133
				/* translators: 1: blog name, 2: post title */
134
				$subject = sprintf( __( '[%1$s] Comment: "%2$s"' ), $blogname, $post->post_title );
135
				break;
136
		}
137
138
		$notify_message .= $moderate_on_wpcom
139
			? Redirect::get_url(
140
				'calypso-comments-all',
141
				array(
142
					'path' => $comment->comment_post_ID,
143
				)
144
			) . "/\r\n\r\n"
145
			: get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
146
147
		/* translators: %s: URL */
148
		$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
149
150
		$base_wpcom_edit_comment_url = Redirect::get_url(
151
			'calypso-edit-comment',
152
			array(
153
				'path'  => $comment_id,
154
				'query' => 'action=__action__', // __action__ will be replaced by the actual action.
155
			)
156
		);
157
158
		if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
159 View Code Duplication
			if ( EMPTY_TRASH_DAYS ) {
160
				$notify_message .= sprintf(
161
					/* translators: Placeholder is the edit URL */
162
					__( 'Trash it: %s' ),
163
					$moderate_on_wpcom
164
					? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url )
165
					: admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" )
166
				) . "\r\n";
167
			} else {
168
				$notify_message .= sprintf(
169
					/* translators: Placeholder is the edit URL */
170
					__( 'Delete it: %s' ),
171
					$moderate_on_wpcom
172
					? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url )
173
					: admin_url( "comment.php?action=delete&c={$comment->comment_ID}#wpbody-content" )
174
				) . "\r\n";
175
			}
176
			$notify_message .= sprintf(
177
				/* translators: Placeholder is the edit URL */
178
				__( 'Spam it: %s' ),
179
				$moderate_on_wpcom
180
				? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url )
181
				: admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" )
182
			) . "\r\n";
183
		}
184
185
		$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) );
186
187
		if ( '' == $comment->comment_author ) {
188
			$from = "From: \"$blogname\" <$wp_email>";
189
			if ( '' != $comment->comment_author_email ) {
190
				$reply_to = "Reply-To: $comment->comment_author_email";
191
			}
192
		} else {
193
			$from = "From: \"$comment->comment_author\" <$wp_email>";
194
			if ( '' != $comment->comment_author_email ) {
195
				$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
196
			}
197
		}
198
199
		$message_headers = "$from\n"
200
			. 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
201
202
		if ( isset( $reply_to ) ) {
203
			$message_headers .= $reply_to . "\n";
204
		}
205
206
		/** This filter is documented in core/src/wp-includes/pluggable.php */
207
		$notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment->comment_ID );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment->comment_ID.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
208
209
		/** This filter is documented in core/src/wp-includes/pluggable.php */
210
		$subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment->comment_ID.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
211
212
		/** This filter is documented in core/src/wp-includes/pluggable.php */
213
		$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment->comment_ID.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
214
215
		foreach ( $emails as $email ) {
216
			@wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
217
		}
218
219
		if ( $switched_locale ) {
220
			restore_previous_locale();
221
		}
222
223
		return true;
224
	}
225
endif;
226
227
if ( ! function_exists( 'wp_notify_moderator' ) && Jetpack::is_active() ) :
228
	/**
229
	 * Notifies the moderator of the site about a new comment that is awaiting approval.
230
	 *
231
	 * @since 1.0.0
232
	 *
233
	 * @global wpdb $wpdb WordPress database abstraction object.
234
	 *
235
	 * Uses the {@see 'notify_moderator'} filter to determine whether the site moderator
236
	 * should be notified, overriding the site setting.
237
	 *
238
	 * @param int $comment_id Comment ID.
239
	 * @return true Always returns true.
240
	 */
241
	function wp_notify_moderator( $comment_id ) {
242
		global $wpdb;
243
244
		$maybe_notify = get_option( 'moderation_notify' );
245
246
		/** This filter is documented in core/src/wp-includes/pluggable.php */
247
		$maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
248
249
		if ( ! $maybe_notify ) {
250
			return true;
251
		}
252
253
		$comment = get_comment( $comment_id );
254
		$post    = get_post( $comment->comment_post_ID );
255
		$user    = get_userdata( $post->post_author );
256
		// Send to the administration and to the post author if the author can modify the comment.
257
		$emails = array( get_option( 'admin_email' ) );
258
		if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) {
259
			if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
260
				$emails[] = $user->user_email;
261
			}
262
		}
263
264
		$switched_locale = switch_to_locale( get_locale() );
265
266
		$comment_author_domain = @gethostbyaddr( $comment->comment_author_IP );
267
		$comments_waiting      = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
268
269
		// The blogname option is escaped with esc_html on the way into the database in sanitize_option
270
		// we want to reverse this for the plain text arena of emails.
271
		$blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
272
		$comment_content = wp_specialchars_decode( $comment->comment_content );
273
274
		switch ( $comment->comment_type ) {
275 View Code Duplication
			case 'trackback':
276
				/* translators: 1: Post title */
277
				$notify_message  = sprintf( __( 'A new trackback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
278
				$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
279
				/* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
280
				$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
281
				/* translators: 1: Trackback/pingback/comment author URL */
282
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
283
				$notify_message .= __( 'Trackback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
284
				break;
285 View Code Duplication
			case 'pingback':
286
				/* translators: 1: Post title */
287
				$notify_message  = sprintf( __( 'A new pingback on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
288
				$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
289
				/* translators: 1: Trackback/pingback website name, 2: website IP address, 3: website hostname */
290
				$notify_message .= sprintf( __( 'Website: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
291
				/* translators: 1: Trackback/pingback/comment author URL */
292
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
293
				$notify_message .= __( 'Pingback excerpt: ' ) . "\r\n" . $comment_content . "\r\n\r\n";
294
				break;
295 View Code Duplication
			default: // Comments.
296
				/* translators: 1: Post title */
297
				$notify_message  = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
298
				$notify_message .= get_permalink( $comment->comment_post_ID ) . "\r\n\r\n";
299
				/* translators: 1: Comment author name, 2: comment author's IP address, 3: comment author's hostname */
300
				$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
301
				/* translators: 1: Comment author URL */
302
				$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
303
				/* translators: 1: Trackback/pingback/comment author URL */
304
				$notify_message .= sprintf( __( 'URL: %s' ), $comment->comment_author_url ) . "\r\n";
305
				/* translators: 1: Comment text */
306
				$notify_message .= sprintf( __( 'Comment: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
307
				break;
308
		}
309
310
		/** This filter is documented in core/src/wp-includes/pluggable.php */
311
		$emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
312
313
		// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
314
		function is_user_connected( $email ) {
0 ignored issues
show
Best Practice introduced by
The function is_user_connected() has been defined more than once; this definition is ignored, only the first definition in this file (L87-90) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
315
			$user = get_user_by( 'email', $email );
316
			return Jetpack::is_user_connected( $user->ID );
317
		}
318
319
		$moderate_on_wpcom = ! in_array( false, array_map( 'is_user_connected', $emails ) );
320
321
		$base_wpcom_edit_comment_url = Redirect::get_url(
322
			'calypso-edit-comment',
323
			array(
324
				'path'  => $comment_id,
325
				'query' => 'action=__action__', // __action__ will be replaced by the actual action.
326
			)
327
		);
328
329
		$notify_message .= sprintf(
330
			/* translators: Comment moderation. 1: Comment action URL */
331
			__( 'Approve it: %s' ),
332
			$moderate_on_wpcom
333
			? str_replace( '__action__', 'approve', $base_wpcom_edit_comment_url )
334
			: admin_url( "comment.php?action=approve&c={$comment_id}#wpbody-content" )
335
		) . "\r\n";
336
337 View Code Duplication
		if ( EMPTY_TRASH_DAYS ) {
338
			$notify_message .= sprintf(
339
				/* translators: Comment moderation. 1: Comment action URL */
340
				__( 'Trash it: %s' ),
341
				$moderate_on_wpcom
342
				? str_replace( '__action__', 'trash', $base_wpcom_edit_comment_url )
343
				: admin_url( "comment.php?action=trash&c={$comment_id}#wpbody-content" )
344
			) . "\r\n";
345
		} else {
346
			$notify_message .= sprintf(
347
				/* translators: Comment moderation. 1: Comment action URL */
348
				__( 'Delete it: %s' ),
349
				$moderate_on_wpcom
350
				? str_replace( '__action__', 'delete', $base_wpcom_edit_comment_url )
351
				: admin_url( "comment.php?action=delete&c={$comment_id}#wpbody-content" )
352
			) . "\r\n";
353
		}
354
355
		$notify_message .= sprintf(
356
			/* translators: Comment moderation. 1: Comment action URL */
357
			__( 'Spam it: %s' ),
358
			$moderate_on_wpcom
359
			? str_replace( '__action__', 'spam', $base_wpcom_edit_comment_url )
360
			: admin_url( "comment.php?action=spam&c={$comment_id}#wpbody-content" )
361
		) . "\r\n";
362
363
		$notify_message .= sprintf(
364
			/* translators: Comment moderation. 1: Number of comments awaiting approval */
365
			_n(
366
				'Currently %s comment is waiting for approval. Please visit the moderation panel:',
367
				'Currently %s comments are waiting for approval. Please visit the moderation panel:',
368
				$comments_waiting
369
			),
370
			number_format_i18n( $comments_waiting )
371
		) . "\r\n";
372
373
		$notify_message .= $moderate_on_wpcom
374
			? Redirect::get_url( 'calypso-comments-pending' )
375
			: admin_url( 'edit-comments.php?comment_status=moderated#wpbody-content' ) . "\r\n";
376
377
		/* translators: Comment moderation notification email subject. 1: Site name, 2: Post title */
378
		$subject         = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title );
379
		$message_headers = '';
380
381
		/** This filter is documented in core/src/wp-includes/pluggable.php */
382
		$notify_message = apply_filters( 'comment_moderation_text', $notify_message, $comment_id );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
383
384
		/** This filter is documented in core/src/wp-includes/pluggable.php */
385
		$subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
386
387
		/** This filter is documented in core/src/wp-includes/pluggable.php */
388
		$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
0 ignored issues
show
Unused Code introduced by
The call to apply_filters() has too many arguments starting with $comment_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
389
390
		foreach ( $emails as $email ) {
391
			@wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
392
		}
393
394
		if ( $switched_locale ) {
395
			restore_previous_locale();
396
		}
397
398
		return true;
399
	}
400
endif;
401