wp_xmlrpc_server::wp_editComment( array $args )
Edits a comment.
Description
Besides the common blog_id (unused), username, and password arguments, it takes a comment_id integer and a content_struct array as last argument.
The allowed keys in the content_struct array are:
- ‘author’
- ‘author_url’
- ‘author_email’
- ‘content’
- ‘date_created_gmt’
- ‘status’. Common statuses are ‘approve’, ‘hold’, ‘spam’. See get_comment_statuses() for more details.
Parameters
- $args
-
(Required) Method arguments. Note: arguments must be ordered as documented.<br>
- (int) Blog ID (unused).<br>
- '1'
(string) Username.<br> - '2'
(string) Password.<br> - '3'
(int) Comment ID.<br> - '4'
(array) Content structure.<br>
Return
(true|IXR_Error) True, on success.
Source
File: wp-includes/class-wp-xmlrpc-server.php
public function wp_editComment( $args ) {
$this->escape( $args );
$username = $args[1];
$password = $args[2];
$comment_ID = (int) $args[3];
$content_struct = $args[4];
if ( !$user = $this->login( $username, $password ) ) {
return $this->error;
}
if ( ! get_comment( $comment_ID ) ) {
return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
}
if ( ! current_user_can( 'edit_comment', $comment_ID ) ) {
return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) );
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.editComment' );
$comment = array(
'comment_ID' => $comment_ID,
);
if ( isset($content_struct['status']) ) {
$statuses = get_comment_statuses();
$statuses = array_keys($statuses);
if ( ! in_array($content_struct['status'], $statuses) )
return new IXR_Error( 401, __( 'Invalid comment status.' ) );
$comment['comment_approved'] = $content_struct['status'];
}
// Do some timestamp voodoo
if ( !empty( $content_struct['date_created_gmt'] ) ) {
// We know this is supposed to be GMT, so we're going to slap that Z on there by force
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
$comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
$comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
}
if ( isset($content_struct['content']) ) {
$comment['comment_content'] = $content_struct['content'];
}
if ( isset($content_struct['author']) ) {
$comment['comment_author'] = $content_struct['author'];
}
if ( isset($content_struct['author_url']) ) {
$comment['comment_author_url'] = $content_struct['author_url'];
}
if ( isset($content_struct['author_email']) ) {
$comment['comment_author_email'] = $content_struct['author_email'];
}
$result = wp_update_comment($comment);
if ( is_wp_error( $result ) )
return new IXR_Error(500, $result->get_error_message());
if ( !$result )
return new IXR_Error(500, __('Sorry, the comment could not be edited.'));
/**
* Fires after a comment has been successfully updated via XML-RPC.
*
* @since WP-3.4.0
*
* @param int $comment_ID ID of the updated comment.
* @param array $args An array of arguments to update the comment.
*/
do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args );
return true;
}
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |