wppaste
WordPress

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

Since
1.5.0
Source
wp-includes/class-wp-xmlrpc-server.php:5125
Creates a new post.

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

    App key (unused).
  • $1int

    Blog ID (unused).
  • $2string

    Username.
  • $3string

    Password.
  • $4string

    Content.
  • $5int

    Publish 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

Reaches the database via get_post().

Scaling
Constant

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

Instructions
20–99

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

Plugin surface
2 hooks

Third-party callbacks on 'xmlrpc_call', 'xmlrpc_call_success_blogger_newPost' 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
  • optionoption read or writeget_option()one call below wp_xmlrpc_server::blogger_newPost()
  • querycontent queryget_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.

WhenInstructionsCalls it makes
always20->escape(), ->login()
!current_user_can()46–47->escape(), ->login(), do_action(), get_post_type_object(), current_user_can(), __()
always50–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

PHPCompiledExecutedBranchesNotes
8.6-dev12620–997
8.512620–997
8.412620–997
8.312620–997
8.212620–997
8.112620–9971 fewer instruction than PHP 7.4
7.412720–1007

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:

  1. do_action( xmlrpc_call )actionline 5139 (+14 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_blogger_newPost )actionline 5186 (+61 into the body)

    Fires after a new post has been successfully created via the XML-RPC Blogger API.

Uses · 14

Show all 14

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', true ); 		$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.

  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.