REST API: Allow comments to be created setting the user_agent parameter.

As of WordPress 4.3 the `wp_new_comment()` function has been updated to allow the comment_agent value to be set when a comment is created. The comments API endpoint now allows the comment author's user agent to be set when creating a comment.
Also, the `readonly` property on the `author_user_agent` parameter in the schema was removed.

Props rabmalin for the initial patch.
Fixes #38425.
Built from https://develop.svn.wordpress.org/trunk@38864


git-svn-id: http://core.svn.wordpress.org/trunk@38807 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Rachel Baker 2016-10-21 18:28:32 +00:00
parent 6c8508023f
commit cdce9d5dac
2 changed files with 12 additions and 3 deletions

View File

@ -419,7 +419,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
$prepared_comment['comment_author_url'] = '';
}
$prepared_comment['comment_agent'] = '';
if ( ! isset( $prepared_comment['comment_agent'] ) ) {
$prepared_comment['comment_agent'] = '';
}
$prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true );
if ( is_wp_error( $prepared_comment['comment_approved'] ) ) {
@ -888,6 +891,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
$prepared_comment['comment_author_IP'] = $request['author_ip'];
}
if ( isset( $request['author_user_agent'] ) ) {
$prepared_comment['comment_agent'] = $request['author_user_agent'];
}
if ( isset( $request['type'] ) ) {
// Comment type "comment" needs to be created as an empty string.
$prepared_comment['comment_type'] = 'comment' === $request['type'] ? '' : $request['type'];
@ -975,7 +982,9 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
'description' => __( 'User agent for the object author.' ),
'type' => 'string',
'context' => array( 'edit' ),
'readonly' => true,
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
'content' => array(
'description' => __( 'The content for the object.' ),

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38863';
$wp_version = '4.7-alpha-38864';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.