wp_xmlrpc_server::blogger_newPost( array $args ): int|IXR_Error
- Since
- 1.5.0
- Source
wp-includes/class-wp-xmlrpc-server.php:5113
Compatibility
- WordPress
- since 1.5.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.
$0stringApp key (unused).$1intBlog ID (unused).$2stringUsername.$3stringPassword.$4stringContent.$5intPublish flag. 0 for draft, 1 for publish.
Return value
int|IXR_Error
Performance profile
How much work a call to wp_xmlrpc_server::blogger_newPost() 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
- 20–99
- 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 126.
Third-party callbacks on 'xmlrpc_call', 'xmlrpc_call_success_blogger_newPost' 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 - optionoption read or write
get_option()one call below wp_xmlrpc_server::blogger_newPost() - querycontent query
get_post()one call below wp_xmlrpc_server::blogger_newPost()
Further down the call graph this can also reach cache, 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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_xmlrpc_server::blogger_newPost() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 20 | ->escape(), ->login() |
!current_user_can() | 46–47 | ->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), __() |
| always | 50–51 | ->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), current_user_can(), __() |
current_user_can() && is_wp_error() | 93–95 | ->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), current_user_can(), xmlrpc_getposttitle(), xmlrpc_getpostcategory(), xmlrpc_removepostdata(), current_time(), current_time(), compact(), wp_insert_post(), is_wp_error(), ->get_error_message() |
current_user_can() && !is_wp_error() | 95–97 | ->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), current_user_can(), xmlrpc_getposttitle(), xmlrpc_getpostcategory(), xmlrpc_removepostdata(), current_time(), current_time(), compact(), wp_insert_post(), is_wp_error(), __() |
current_user_can() && !is_wp_error() | 97–99 | ->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), current_user_can(), xmlrpc_getposttitle(), xmlrpc_getpostcategory(), xmlrpc_removepostdata(), current_time(), current_time(), compact(), wp_insert_post(), is_wp_error(), ->attach_uploads(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 126 | 20–99 | 7 | |
| 8.5 | 126 | 20–99 | 7 | |
| 8.4 | 126 | 20–99 | 7 | |
| 8.3 | 126 | 20–99 | 7 | |
| 8.2 | 126 | 20–99 | 7 | |
| 8.1 | 126 | 20–99 | 7 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 127 | 20–100 | 7 |
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::blogger_newPost() runs, in this order:
- do_action( xmlrpc_call )actionline 5127 (+14 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_blogger_newPost )actionline 5166 (+53 into the body)
Fires after a new post has been successfully created via the XML-RPC Blogger API.
Uses · 14
- do_action()Calls the callback functions that have been added to an action hook.
- current_user_can()Returns whether the current user has the specified capability.
- get_post_type_object()Retrieves a post type object by name.
- __()Retrieves the translation of $text.
- xmlrpc_getposttitle()Retrieves post title from XMLRPC XML.
- xmlrpc_getpostcategory()Retrieves the post category or categories from XMLRPC XML.
- xmlrpc_removepostdata()XMLRPC XML content without title and category elements.
- current_time()Retrieves the current time based on specified type.
- wp_insert_post()Inserts or update a post.
- 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.
Show all 14
- IXR_Error::__construct()PHP5 constructor.
- wp_xmlrpc_server::attach_uploads()Attaches an upload to a post.
Source code
public function blogger_newPost( $args ) { $this->escape( $args ); $username = $args[2]; $password = $args[3]; $content = $args[4]; $publish = $args[5]; $user = $this->login( $username, $password ); if ( ! $user ) { return $this->error; } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'blogger.newPost', $args, $this ); $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); } $post_status = ( $publish ) ? 'publish' : 'draft'; $post_author = $user->ID; $post_title = xmlrpc_getposttitle( $content ); $post_category = xmlrpc_getpostcategory( $content ); $post_content = xmlrpc_removepostdata( $content ); $post_date = current_time( 'mysql' ); $post_date_gmt = current_time( 'mysql', 1 ); $post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' ); $post_id = wp_insert_post( $post_data ); if ( is_wp_error( $post_id ) ) { return new IXR_Error( 500, $post_id->get_error_message() ); } if ( ! $post_id ) { return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); } $this->attach_uploads( $post_id, $post_content ); /** * Fires after a new post has been successfully created via the XML-RPC Blogger API. * * @since 3.4.0 * * @param int $post_id ID of the new post. * @param array $args An array of new post arguments. */ do_action( 'xmlrpc_call_success_blogger_newPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return $post_id; }Changelog
Introduced in 1.5.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.7.7 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.