Comments: Check if wp_new_comment() returns an error.

Adds checks throughout to allow for `wp_new_comment()` returning a `WP_Error` instance.

Updates the docs for the `pre_comment_approved` filter to include that it can be passed an error.

Props enrico.sorcinelli, ryotsun.
Fixes #39730.



git-svn-id: https://develop.svn.wordpress.org/trunk@41980 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2017-10-23 22:11:11 +00:00
parent a0910276f1
commit 733a81d74d
5 changed files with 49 additions and 3 deletions
+4 -2
View File
@@ -769,9 +769,11 @@ function wp_allow_comment( $commentdata, $avoid_die = false ) {
* Filters a comment's approval status before it is set.
*
* @since 2.1.0
* @since 4.9.0 Returning a WP_Error value from the filter will shortcircuit comment insertion and
* allow skipping further processing.
*
* @param bool|string $approved The approval status. Accepts 1, 0, or 'spam'.
* @param array $commentdata Comment data.
* @param bool|string|WP_Error $approved The approval status. Accepts 1, 0, 'spam' or WP_Error.
* @param array $commentdata Comment data.
*/
$approved = apply_filters( 'pre_comment_approved', $approved, $commentdata );
return $approved;