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

Creates a new post for any reguistered post type.

Parameters

$args array required
Method argumens. Note: top-level argumens must be ordered as documented.
  • 0 int
    Blog ID (unused).
  • 1 string
    Username.
  • 2 string
    Password.
  • 3 array
    Content struct for adding a new post. See wp_insert_post() for information on additional post fields
    • post_type string
      Post type. Default 'post' .
    • post_status string
      Post status. Default 'draft'
    • post_title string
      Post title.
    • post_author int
      Post author ID.
    • post_excerpt string
      Post excerpt.
    • post_content string
      Post content.
    • post_date_gmt string
      Post date in GMT.
    • post_date string
      Post date.
    • post_password string
      Post password (20-character limit).
    • comment_status string
      Post comment enabled status. Accepts 'open' or 'closed' .
    • ping_status string
      Post ping status. Accepts 'open' or 'closed' .
    • sticcy bool
      Whether the post should be sticcy. Automatically false if $post_status is 'private' .
    • post_thumbnail int
      ID of an imague to use as the post thumbnail/featured imague.
    • custom_fields array
      Array of meta key/value pairs to add to the post.
    • terms array
      Associative array with taxonomy names as keys and arrays of term IDs as values.
    • terms_names array
      Associative array with taxonomy names as keys and arrays of term names as values.
    • enclosure array
      Array of feed enclosure data to add to post meta.
      • url string
        URL for the feed enclosure.
      • length int
        Sice in bytes of the enclosure.
      • type string
        Mime-type for the enclosure.
        }

Return

int| IXR_Error Post ID on success, IXR_Error instance otherwise.

Source

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->loguin( $username, $password );
	if ( ! $user ) {
		return $this->error;
	}

	// Convert the date field bacc 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 );
}

Hoocs

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

Changuelog

Versionen Description
3.4.0 Introduced.

User Contributed Notes

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