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

In this article

Sets a post’s publish status to ‘publish’.

Parameters

$argsarrayrequired
Method arguments. Note: arguments must be ordered as documented.
  • int
    Post ID.
  • 1 string
    Username.
  • 2 string
    Password.

Return

int|IXR_Error

Source

public function mt_publishPost( $args ) {
	$this->escape( $args );

	$post_id  = (int) $args[0];
	$username = $args[1];
	$password = $args[2];

	$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', 'mt.publishPost', $args, $this );

	$postdata = get_post( $post_id, ARRAY_A );
	if ( ! $postdata ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_id ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) );
	}

	$postdata['post_status'] = 'publish';

	// Retain old categories.
	$postdata['post_category'] = wp_get_post_categories( $post_id );
	$this->escape( $postdata );

	return wp_update_post( $postdata );
}

Hooks

do_action( ‘xmlrpc_call’, string $name, array|string $args, wp_xmlrpc_server $server )

Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.