wp_xmlrpc_server::wp_newPost( array $args ): int|IXR_Error
- Since
- 3.4.0
- Source
wp-includes/class-wp-xmlrpc-server.php:1324
Compatibility
- WordPress
- since 3.4.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: top-level arguments must be ordered as documented.
$0intBlog ID (unused).$1stringUsername.$2stringPassword.$3arraydefault: 'post'{ Content struct for adding a new post. See wp_insert_post() for information on additional post fields @type string $post_type Post type.$post_statusstringdefault: 'draft' @type string $post_title Post titlePost status.$post_authorintPost author ID.$post_excerptstringPost excerpt.$post_contentstringPost content.$post_date_gmtstringPost date in GMT.$post_datestringPost date.$post_passwordstringPost password (20-character limit).$comment_statusstringPost comment enabled status. Accepts 'open' or 'closed'.$ping_statusstringPost ping status. Accepts 'open' or 'closed'.$stickyboolWhether the post should be sticky. Automatically false if$post_statusis 'private'.$post_thumbnailintID of an image to use as the post thumbnail/featured image.$custom_fieldsarrayArray of meta key/value pairs to add to the post.$termsarrayAssociative array with taxonomy names as keys and arrays of term IDs as values.$terms_namesarrayAssociative array with taxonomy names as keys and arrays of term names as values.$enclosurearray{ Array of feed enclosure data to add to post meta.$urlstringURL for the feed enclosure.$lengthintSize in bytes of the enclosure.$typestringMime-type for the enclosure. } }
Return value
int|IXR_Error- Post ID on success, IXR_Error instance otherwise.
Performance profile
How much work a call to wp_xmlrpc_server::wp_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
- Trivial
- Scaling
- Constant
- Instructions
- 8–60
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
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 66.
Third-party callbacks on 'xmlrpc_call' 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
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_xmlrpc_server::wp_newPost() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->minimum_args() | 8 | ->minimum_args() |
->minimum_args() | 20 | ->minimum_args(), ->escape(), ->login() |
->minimum_args() | 35–48 | ->minimum_args(), ->escape(), ->login(), do_action(), ->_insert_post() |
->minimum_args() && isset($content_struct) && !($value instanceof) | 45–55 | ->minimum_args(), ->escape(), ->login(), ->_convert_date(), do_action(), ->_insert_post() |
->minimum_args() && !($value instanceof) | 60 | ->minimum_args(), ->escape(), ->login(), ->_convert_date(), ->_convert_date(), do_action(), ->_insert_post() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 66 instructions, 8–60 executed per call, 8 branches. The work does not change between versions.
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 · 1
One hook fires while wp_xmlrpc_server::wp_newPost() runs, in this order:
- do_action( xmlrpc_call )actionline 1358 (+34 into the body)
Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.
Uses · 6
- do_action()Calls the callback functions that have been added to an action hook.
- wp_xmlrpc_server::minimum_args()Checks if the method received at least the minimum number of arguments.
- wp_xmlrpc_server::escape()Escapes string or array of strings for database.
- wp_xmlrpc_server::login()Logs user in.
- wp_xmlrpc_server::_convert_date()Converts a WordPress date string to an IXR_Date object.
- wp_xmlrpc_server::_insert_post()Helper method for wp_newPost() and wp_editPost(), containing shared logic.
Source code
public function wp_newPost( $args ) { if ( ! $this->minimum_args( $args, 4 ) ) { return $this->error; } $this->escape( $args ); $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; $user = $this->login( $username, $password ); if ( ! $user ) { return $this->error; } // Convert the date field back to IXR form. if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { $content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); } /* * Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, * since _insert_post() will ignore the non-GMT date if the GMT date is set. */ if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) { unset( $content_struct['post_date_gmt'] ); } else { $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); } } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.newPost', $args, $this ); unset( $content_struct['ID'] ); return $this->_insert_post( $user, $content_struct ); }Changelog
Introduced in 3.4.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.