wp_xmlrpc_server::wp_newPost( array $args )
Creates a new post for any registered post type.
Parameters
- $args
-
(Required) Method arguments. Note: top-level arguments must be ordered as documented.<br>
- (int) Blog ID (unused).<br>
- '1'
(string) Username.<br> - '2'
(string) Password.<br> - '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'.<br> - 'post_status'
(string) Post status. Default 'draft' - 'post_title'
(string) Post title.<br> - 'post_author'
(int) Post author ID.<br> - 'post_excerpt'
(string) Post excerpt.<br> - 'post_content'
(string) Post content.<br> - 'post_date_gmt'
(string) Post date in GMT.<br> - 'post_date'
(string) Post date.<br> - 'post_password'
(string) Post password (20-character limit).<br> - 'comment_status'
(string) Post comment enabled status. Accepts 'open' or 'closed'.<br> - 'ping_status'
(string) Post ping status. Accepts 'open' or 'closed'.<br> - 'sticky'
(bool) Whether the post should be sticky. Automatically false if$post_status
is 'private'.<br> - 'post_thumbnail'
(int) ID of an image to use as the post thumbnail/featured image.<br> - 'custom_fields'
(array) Array of meta key/value pairs to add to the post.<br> - 'terms'
(array) Associative array with taxonomy names as keys and arrays of term IDs as values.<br> - 'terms_names'
(array) Associative array with taxonomy names as keys and arrays of term names as values.<br> - 'enclosure'
(array) Array of feed enclosure data to add to post meta.<br>- 'url'
(string) URL for the feed enclosure.<br> - 'length'
(int) Size in bytes of the enclosure.<br> - 'type'
(string) Mime-type for the enclosure.<br> }
- 'url'
- 'post_type'
Return
(int|IXR_Error) Post ID on success, IXR_Error instance otherwise.
Source
File: wp-includes/class-wp-xmlrpc-server.php
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];
if ( ! $user = $this->login( $username, $password ) )
return $this->error;
// convert the date field back 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 ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || 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' );
unset( $content_struct['ID'] );
return $this->_insert_post( $user, $content_struct );
}
Changelog
Version | Description |
---|---|
3.4.0 | Introduced. |