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. Built from https://develop.svn.wordpress.org/trunk@41980 git-svn-id: http://core.svn.wordpress.org/trunk@41814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
29d213cfbd
commit
339d838475
|
@ -1100,6 +1100,11 @@ function wp_ajax_replyto_comment( $action ) {
|
|||
}
|
||||
|
||||
$comment_id = wp_new_comment( $commentdata );
|
||||
|
||||
if ( is_wp_error( $comment_id ) ) {
|
||||
wp_die( $comment_id->get_error_message() );
|
||||
}
|
||||
|
||||
$comment = get_comment($comment_id);
|
||||
if ( ! $comment ) wp_die( 1 );
|
||||
|
||||
|
|
|
@ -6487,6 +6487,10 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
$comment_ID = wp_new_comment($commentdata);
|
||||
|
||||
if ( is_wp_error( $comment_ID ) ) {
|
||||
return $this->pingback_error( 0, $comment_ID->get_error_message() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after a post pingback has been sent.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.9-beta3-41979';
|
||||
$wp_version = '4.9-beta3-41980';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
|
@ -126,7 +126,12 @@ if ( !empty($tb_url) && !empty($title) ) {
|
|||
|
||||
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
|
||||
|
||||
wp_new_comment($commentdata);
|
||||
$result = wp_new_comment( $commentdata );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
trackback_response( 1, $result->get_error_message() );
|
||||
}
|
||||
|
||||
$trackback_id = $wpdb->insert_id;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue