wp_xmlrpc_server::mt_setPostCategories()publicWP 1.5.0

Sets categories for a post.

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

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

Возвращает

true|IXR_Error. True on success.

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

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

Method arguments. Note: arguments must be ordered as documented.

  • 0(int)
    Post ID.

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

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

  • 3(массив)
    Categories.

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

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

Код wp_xmlrpc_server::mt_setPostCategories() WP 6.6.2

public function mt_setPostCategories( $args ) {
	$this->escape( $args );

	$post_id    = (int) $args[0];
	$username   = $args[1];
	$password   = $args[2];
	$categories = $args[3];

	$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', 'mt.setPostCategories', $args, $this );

	if ( ! get_post( $post_id ) ) {
		return new IXR_Error( 404, __( 'Invalid post ID.' ) );
	}

	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
	}

	$catids = array();
	foreach ( $categories as $cat ) {
		$catids[] = $cat['categoryId'];
	}

	wp_set_post_categories( $post_id, $catids );

	return true;
}