wp_xmlrpc_server::wp_newPost()publicWP 3.4.0

Creates a new post for any registered post type.

Метод класса: wp_xmlrpc_server{}

Хуки из метода

Возвращает

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

Использование

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->wp_newPost( $args );
$args(массив) (обязательный)

Method arguments. Note: top-level arguments must be ordered as documented.

  • 0(int)
    Blog ID (unused).

  • 1(строка)
    Username.

  • 2(строка)
    Password.

  • 3(массив)
    Content struct for adding a new post. See wp_insert_post() for information on additional post fields

    • post_type(строка)
      Post type.
      По умолчанию: 'post'

    • post_status(строка)
      Post status.
      По умолчанию: 'draft'

    • post_title(строка)
      Post title.

    • post_author(int)
      Post author ID.

    • post_excerpt(строка)
      Post excerpt.

    • post_content(строка)
      Post content.

    • post_date_gmt(строка)
      Post date in GMT.

    • post_date(строка)
      Post date.

    • post_password(строка)
      Post password (20-character limit).

    • comment_status(строка)
      Post comment enabled status. Accepts 'open' or 'closed'.

    • ping_status(строка)
      Post ping status. Accepts 'open' or 'closed'.

    • sticky(true|false)
      Whether the post should be sticky. Automatically false if $post_status is 'private'.

    • post_thumbnail(int)
      ID of an image to use as the post thumbnail/featured image.

    • custom_fields(массив)
      Array of meta key/value pairs to add to the post.

    • terms(массив)
      Associative array with taxonomy names as keys and arrays of term IDs as values.

    • terms_names(массив)
      Associative array with taxonomy names as keys and arrays of term names as values.

    • enclosure(массив)
      Array of feed enclosure data to add to post meta.

      • url(строка)
        URL for the feed enclosure.

      • length(int)
        Size in bytes of the enclosure.

      • type(строка)
        Mime-type for the enclosure.

Список изменений

С версии 3.4.0 Введена.

Код wp_xmlrpc_server::wp_newPost() WP 6.6.2

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