wp_xmlrpc_server::wp_editComment( array $args ): true|IXR_Error
- Since
- 2.7.0
- Source
wp-includes/class-wp-xmlrpc-server.php:3810
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.
$0intBlog ID (unused).$1stringUsername.$2stringPassword.$3intComment ID.$4arrayContent 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
- Scaling
- Constant
- Instructions
- 17–107
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 146.
Third-party callbacks on 'xmlrpc_call', 'xmlrpc_call_success_wp_editComment' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 17 | ->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) && !$statuses | 53 | ->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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 146 | 17–107 | 12 | |
| 8.5 | 146 | 17–107 | 12 | |
| 8.4 | 146 | 17–107 | 12 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 149 | 17–110 | 12 | |
| 8.2 | 149 | 17–110 | 12 | |
| 8.1 | 149 | 17–110 | 12 | |
| 7.4 | 149 | 17–110 | 12 |
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:
- do_action( xmlrpc_call )actionline 3832 (+22 into the body)
Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.
- do_action( xmlrpc_call_success_wp_editComment )actionline 3890 (+80 into the body)
Fires after a comment has been successfully updated via XML-RPC.
Uses · 12
- get_comment()Retrieves comment data given a comment ID or comment object.
- __()Retrieves the translation of $text.
- current_user_can()Returns whether the current user has the specified capability.
- do_action()Calls the callback functions that have been added to an action hook.
- get_comment_statuses()Retrieves all of the WordPress supported comment statuses.
- get_date_from_gmt()Given a date in UTC or GMT timezone, returns that date in the timezone of the site.
- iso8601_to_datetime()Given an ISO 8601 (Ymd\TH:i:sO) date, returns a MySQL DateTime (Y-m-d H:i:s) format used by post_date[_gmt].
- wp_update_comment()Updates an existing comment in the database.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_xmlrpc_server::escape()Escapes string or array of strings for database.
- wp_xmlrpc_server::login()Logs user in.
- IXR_Error::__construct()PHP5 constructor.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.