wppaste
WordPress

wp_xmlrpc_server::wp_editComment( array $args ): true|IXR_Error

Since
2.7.0
Source
wp-includes/class-wp-xmlrpc-server.php:3816
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 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.

Compatibility

WordPress
since 2.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$argsarray
Method arguments. Note: arguments must be ordered as documented.
  • $0int

    Blog ID (unused).
  • $1string

    Username.
  • $2string

    Password.
  • $3int

    Comment ID.
  • $4array

    Content structure.

Return value

true|IXR_Error
True, on success.

Performance profile

How much work a call to wp_xmlrpc_server::wp_editComment() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
17–107

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 146.

Plugin surface
2 hooks

Third-party callbacks on 'xmlrpc_call', 'xmlrpc_call_success_wp_editComment' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • querycontent queryget_post()one call below wp_xmlrpc_server::wp_editComment()

Further down the call graph this can also reach cache, option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 16 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_xmlrpc_server::wp_editComment() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always17->escape(), ->login()
!get_comment()27->escape(), ->login(), get_comment(), __()
get_comment() && !current_user_can()32->escape(), ->login(), get_comment(), current_user_can(), __()
get_comment() && current_user_can() && isset($content_struct) && !$statuses53->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), __(), comment_ID()
get_comment() && current_user_can() && !isset($content_struct) && empty($content_struct) && !is_wp_error()60–72->escape(), ->login(), get_comment(), current_user_can(), do_action(), wp_update_comment(), is_wp_error(), do_action()
get_comment() && current_user_can() && !isset($content_struct) && empty($content_struct) && is_wp_error()60–72->escape(), ->login(), get_comment(), current_user_can(), do_action(), wp_update_comment(), is_wp_error(), ->get_error_message()
get_comment() && current_user_can() && !isset($content_struct) && empty($content_struct) && !is_wp_error()62–74->escape(), ->login(), get_comment(), current_user_can(), do_action(), wp_update_comment(), is_wp_error(), __()
get_comment() && current_user_can() && isset($content_struct) && $statuses && empty($content_struct) && !is_wp_error()74–86->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), wp_update_comment(), is_wp_error(), do_action()
get_comment() && current_user_can() && isset($content_struct) && $statuses && empty($content_struct) && is_wp_error()74–86->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), wp_update_comment(), is_wp_error(), ->get_error_message()
get_comment() && current_user_can() && isset($content_struct) && $statuses && empty($content_struct) && !is_wp_error()76–88->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), wp_update_comment(), is_wp_error(), __()
get_comment() && current_user_can() && !isset($content_struct) && !empty($content_struct) && !is_wp_error()79–91->escape(), ->login(), get_comment(), current_user_can(), do_action(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), do_action()
get_comment() && current_user_can() && !isset($content_struct) && !empty($content_struct) && is_wp_error()79–91->escape(), ->login(), get_comment(), current_user_can(), do_action(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), ->get_error_message()
4 further outcomes, up to 107 instructions
get_comment() && current_user_can() && !isset($content_struct) && !empty($content_struct) && !is_wp_error()81–93->escape(), ->login(), get_comment(), current_user_can(), do_action(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), __()
get_comment() && current_user_can() && isset($content_struct) && $statuses && !empty($content_struct) && !is_wp_error()93–105->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), do_action()
get_comment() && current_user_can() && isset($content_struct) && $statuses && !empty($content_struct) && is_wp_error()93–105->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), ->get_error_message()
get_comment() && current_user_can() && isset($content_struct) && $statuses && !empty($content_struct) && !is_wp_error()95–107->escape(), ->login(), get_comment(), current_user_can(), do_action(), get_comment_statuses(), array_keys(), ->getIso(), rtrim(), get_date_from_gmt(), iso8601_to_datetime(), wp_update_comment(), is_wp_error(), __()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev14617–10712
8.514617–10712
8.414617–107123 fewer instructions than PHP 8.3
8.314917–11012
8.214917–11012
8.114917–11012
7.414917–11012

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while wp_xmlrpc_server::wp_editComment() runs, in this order:

  1. do_action( xmlrpc_call )actionline 3838 (+22 into the body)

    Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.

  2. do_action( xmlrpc_call_success_wp_editComment )actionline 3896 (+80 into the body)

    Fires after a comment has been successfully updated via XML-RPC.

Uses · 12

Source code

	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.			$date_created = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; 			$comment['comment_date']     = get_date_from_gmt( $date_created );			$comment['comment_date_gmt'] = iso8601_to_datetime( $date_created, '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.		 */

Changelog

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-xmlrpc-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.