wp_xmlrpc_server::wp_editComment()
Edits a comment.
Besides the common blog_id (unused), username, and password arguments, it takes a comment_id integer and a content_struct array as the 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.
Метод класса: wp_xmlrpc_server{}
Хуки из метода
Возвращает
true|IXR_Error
. True, on success.
Использование
$wp_xmlrpc_server = new wp_xmlrpc_server(); $wp_xmlrpc_server->wp_editComment( $args );
- $args(массив) (обязательный)
Method arguments. Note: arguments must be ordered as documented.
-
0(int)
Blog ID (unused). -
1(строка)
Username. -
2(строка)
Password. -
3(int)
Comment ID. - 4(массив)
Content structure.
-
Список изменений
С версии 2.7.0 | Введена. |
Код wp_xmlrpc_server::wp_editComment() wp xmlrpc server::wp editComment WP 6.6.2
public function wp_editComment( $args ) { $this->escape( $args ); $username = $args[1]; $password = $args[2]; $comment_id = (int) $args[3]; $content_struct = $args[4]; $user = $this->login( $username, $password ); if ( ! $user ) { 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', $args, $this ); $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, true ) ) { 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( $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, true ); 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 updated.' ) ); } /** * Fires after a comment has been successfully updated via XML-RPC. * * @since 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 ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return true; }