On this page
wp_xmlrpc_server::wp_newPost( array $args ): int|IXR_Error
Create a new post for any registered post type.
Parameters
$argsarray Required-
Method arguments. Note: top-level arguments must be ordered as documented.
- int
Blog ID (unused).
1stringUsername.2stringPassword.3arrayContent struct for adding a new post. See wp_insert_post() for information on additional post fieldspost_typestringPost type. Default'post'.post_statusstringPost status. Default'draft'post_titlestringPost title.post_authorintPost author ID.post_excerptstringPost excerpt.post_contentstringPost content.post_date_gmtstringPost date in GMT.post_datestringPost date.post_passwordstringPost password (20-character limit).comment_statusstringPost comment enabled status. Accepts'open'or'closed'.ping_statusstringPost ping status. Accepts'open'or'closed'.stickyboolWhether the post should be sticky. Automatically false if$post_statusis'private'.post_thumbnailintID of an image to use as the post thumbnail/featured image.custom_fieldsarrayArray of meta key/value pairs to add to the post.termsarrayAssociative array with taxonomy names as keys and arrays of term IDs as values.terms_namesarrayAssociative array with taxonomy names as keys and arrays of term names as values.enclosurearrayArray of feed enclosure data to add to post meta.urlstringURL for the feed enclosure.lengthintSize in bytes of the enclosure.typestringMime-type for the enclosure.
}
Return
int|IXR_Error Post ID on success, IXR_Error instance otherwise.
Source
File:
wp-includes/class-wp-xmlrpc-server.php. View all referencespublic 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->login( $username, $password ); if ( ! $user ) { 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 ( '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 ); }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.
Related
Uses
Uses Description wp_xmlrpc_server::_insert_post() wp-includes/class-wp-xmlrpc-server.php Helper method for wp_newPost() and wp_editPost(), containing shared logic.
wp_xmlrpc_server::minimum_args() wp-includes/class-wp-xmlrpc-server.php Checks if the method received at least the minimum number of arguments.
wp_xmlrpc_server::_convert_date() wp-includes/class-wp-xmlrpc-server.php Convert a WordPress date string to an IXR_Date object.
do_action() wp-includes/plugin.php Calls the callback functions that have been added to an action hook.
wp_xmlrpc_server::escape() wp-includes/class-wp-xmlrpc-server.php Escape string or array of strings for database.
wp_xmlrpc_server::login() wp-includes/class-wp-xmlrpc-server.php Log user in.
Changelog
Version Description 3.4.0 Introduced.
- int
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_newpost