wp_xmlrpc_server::blogger_newPost() WordPress Method

The wp_xmlrpc_server::blogger_newPost() method allows you to create a new post on a WordPress blog. This method takes three arguments: 1. The ID of the blog you want to post to. 2. The username of the user who is creating the post. 3. The password of the user who is creating the post. Once you have called the method, you will need to provide the title, content, and tags for the new post. Once you have done this, the new post will be created and published on the WordPress blog.

wp_xmlrpc_server::blogger_newPost( array $args ) #

Creates new post.


Parameters

$args

(array)(Required)Method arguments. Note: arguments must be ordered as documented.

  • 'appkey'
    (string) (unused)
  • 'blog_id'
    (int) (unused)
  • 'username'
    (string)
  • 'password'
    (string)
  • 'content'
    (string)
  • 'publish'
    (string)


Top ↑

Return

(int|IXR_Error)


Top ↑

Source

File: wp-includes/class-wp-xmlrpc-server.php

	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', 1 );

		$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;
	}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More