wp_xmlrpc_server::blogger_editPost()publicWP 1.5.0

Edits a post.

Method of the class: wp_xmlrpc_server{}

Return

true|IXR_Error. true when done.

Usage

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->blogger_editPost( $args );
$args(array) (required)

Method arguments. Note: arguments must be ordered as documented.

  • 0(int)
    Blog ID (unused).

  • 1(int)
    Post ID.

  • 2(string)
    Username.

  • 3(string)
    Password.

  • 4(string)
    Content

  • 5(int)
    Publish flag. 0 for draft, 1 for publish.

Changelog

Since 1.5.0 Introduced.

wp_xmlrpc_server::blogger_editPost() code WP 6.5.2

public function blogger_editPost( $args ) {

	$this->escape( $args );

	$post_id  = (int) $args[1];
	$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.editPost', $args, $this );

	$actual_post = get_post( $post_id, ARRAY_A );

	if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) {
		return new IXR_Error( 404, __( 'Sorry, no such post.' ) );
	}

	$this->escape( $actual_post );

	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
	}
	if ( 'publish' === $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) );
	}

	$postdata                  = array();
	$postdata['ID']            = $actual_post['ID'];
	$postdata['post_content']  = xmlrpc_removepostdata( $content );
	$postdata['post_title']    = xmlrpc_getposttitle( $content );
	$postdata['post_category'] = xmlrpc_getpostcategory( $content );
	$postdata['post_status']   = $actual_post['post_status'];
	$postdata['post_excerpt']  = $actual_post['post_excerpt'];
	$postdata['post_status']   = $publish ? 'publish' : 'draft';

	$result = wp_update_post( $postdata );

	if ( ! $result ) {
		return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) );
	}
	$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] );

	/**
	 * Fires after a post has been successfully updated via the XML-RPC Blogger API.
	 *
	 * @since 3.4.0
	 *
	 * @param int   $post_id ID of the updated post.
	 * @param array $args    An array of arguments for the post to edit.
	 */
	do_action( 'xmlrpc_call_success_blogger_editPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase

	return true;
}