wppaste
WordPress

wp_xmlrpc_server::wp_newPost( array $args ): int|IXR_Error

Since
3.4.0
Source
wp-includes/class-wp-xmlrpc-server.php:1324
Creates a new post for any registered post type.

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.
  • $0int

    Blog ID (unused).
  • $1string

    Username.
  • $2string

    Password.
  • $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 title

    Post status.
  • $post_authorint

    Post author ID.
  • $post_excerptstring

    Post excerpt.
  • $post_contentstring

    Post content.
  • $post_date_gmtstring

    Post date in GMT.
  • $post_datestring

    Post date.
  • $post_passwordstring

    Post password (20-character limit).
  • $comment_statusstring

    Post comment enabled status. Accepts 'open' or 'closed'.
  • $ping_statusstring

    Post ping status. Accepts 'open' or 'closed'.
  • $stickybool

    Whether the post should be sticky. Automatically false if $post_status is 'private'.
  • $post_thumbnailint

    ID of an image to use as the post thumbnail/featured image.
  • $custom_fieldsarray

    Array of meta key/value pairs to add to the post.
  • $termsarray

    Associative array with taxonomy names as keys and arrays of term IDs as values.
  • $terms_namesarray

    Associative array with taxonomy names as keys and arrays of term names as values.
  • $enclosurearray

    { Array of feed enclosure data to add to post meta.
  • $urlstring

    URL for the feed enclosure.
  • $lengthint

    Size in bytes of the enclosure.
  • $typestring

    Mime-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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
8–60

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

Plugin surface
1 hook

Third-party callbacks on 'xmlrpc_call' 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

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.

WhenInstructionsCalls 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:

  1. 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

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.

  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 6.9.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.