跳转到主要内容

Users

Schema

The schema defines all the fields that exist within a user record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

id

Unique identifier for the user.

JSON data type: integer

Read only

Context: embed, view, edit

username

Login name for the user.

JSON data type: string

Context: edit

name

Display name for the user.

JSON data type: string

Context: embed, view, edit

first_name

First name for the user.

JSON data type: string

Context: edit

last_name

Last name for the user.

JSON data type: string

Context: edit

email

The email address for the user.

JSON data type: string, Format: email

Context: edit

url

URL of the user.

JSON data type: string, Format: uri

Context: embed, view, edit

description

Description of the user.

JSON data type: string

Context: embed, view, edit

locale

Locale for the user.

JSON data type: string

Context: edit

One of: , en_US

nickname

The nickname for the user.

JSON data type: string

Context: edit

slug

An alphanumeric identifier for the user.

JSON data type: string

Context: embed, view, edit

registered_date

Registration date for the user.

JSON data type: string, Format: datetime (details)

Read only

Context: edit

roles

Roles assigned to the user.

JSON data type: array

Context: edit

password

Password for the user (never included).

JSON data type: string

Context:

capabilities

All capabilities assigned to the user.

JSON data type: object

Read only

Context: edit

extra_capabilities

Any extra capabilities assigned to the user.

JSON data type: object

Read only

Context: edit

avatar_urls

Avatar URLs for the user.

JSON data type: object

Read only

Context: embed, view, edit

meta

Meta fields.

JSON data type: object

Context: view, edit

</div>

List Users

Query this endpoint to retrieve a collection of users. The response you receive can be controlled and filtered using the URL query parameters below.

	<h3>Definition</h3>

	<code>GET /wp/v2/users</code>

	<h3>Example Request</h3>

	<code>$ curl https://example.com/wp-json/wp/v2/users</code>
</div>
<div class="secondary">
		<h3>Arguments</h3>
<table class="arguments">
				<tr>
			<td>
										<code>context</code><br />
								</td>
			<td>
										<p>Scope under which the request is made; determines fields present in response.</p>
																				<p class="default">
						Default: <code>view</code>
					</p>
															<p>One of: <code>view</code>, <code>embed</code>, <code>edit</code></p>
								</td>
		</tr>
				<tr>
			<td>
										<code>page</code><br />
								</td>
			<td>
										<p>Current page of the collection.</p>
																				<p class="default">
						Default: <code>1</code>
					</p>
													</td>
		</tr>
				<tr>
			<td>
										<code>per_page</code><br />
								</td>
			<td>
										<p>Maximum number of items to be returned in result set.</p>
																				<p class="default">
						Default: <code>10</code>
					</p>
													</td>
		</tr>
				<tr>
			<td>
										<code>search</code><br />
								</td>
			<td>
										<p>Limit results to those matching a string.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>exclude</code><br />
								</td>
			<td>
										<p>Ensure result set excludes specific IDs.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>include</code><br />
								</td>
			<td>
										<p>Limit result set to specific IDs.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>offset</code><br />
								</td>
			<td>
										<p>Offset the result set by a specific number of items.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>order</code><br />
								</td>
			<td>
										<p>Order sort attribute ascending or descending.</p>
																				<p class="default">
						Default: <code>asc</code>
					</p>
															<p>One of: <code>asc</code>, <code>desc</code></p>
								</td>
		</tr>
				<tr>
			<td>
										<code>orderby</code><br />
								</td>
			<td>
										<p>Sort collection by user attribute.</p>
																				<p class="default">
						Default: <code>name</code>
					</p>
															<p>One of: <code>id</code>, <code>include</code>, <code>name</code>, <code>registered_date</code>, <code>slug</code>, <code>include_slugs</code>, <code>email</code>, <code>url</code></p>
								</td>
		</tr>
				<tr>
			<td>
										<code>slug</code><br />
								</td>
			<td>
										<p>Limit result set to users with one or more specific slugs.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>roles</code><br />
								</td>
			<td>
										<p>Limit result set to users matching at least one specific role provided. Accepts csv list or single role.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>capabilities</code><br />
								</td>
			<td>
										<p>Limit result set to users matching at least one specific capability provided. Accepts csv list or single capability.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>who</code><br />
								</td>
			<td>
										<p>Limit result set to users who are considered authors.</p>
																									<p>One of: <code>authors</code></p>
								</td>
		</tr>
				<tr>
			<td>
										<code>has_published_posts</code><br />
								</td>
			<td>
										<p>Limit result set to users who have published posts.</p>
																							</td>
		</tr>
		</table>

</div>

Create a User

Arguments

username

Login name for the user.

Required: 1

name

Display name for the user.

first_name

First name for the user.

last_name

Last name for the user.

email

The email address for the user.

Required: 1

url

URL of the user.

description

Description of the user.

locale

Locale for the user.

One of: , en_US

nickname

The nickname for the user.

slug

An alphanumeric identifier for the user.

roles

Roles assigned to the user.

password

Password for the user (never included).

Required: 1

meta

Meta fields.

</div>
<div class="secondary">
	<h3>Definition</h3>

	<code>POST /wp/v2/users</code>
</div>

Retrieve a User

	<h3>Definition & Example Request</h3>

	<code>GET /wp/v2/users/&lt;id&gt;</code>

	<p>Query this endpoint to retrieve a specific user record.</p>

	<code>$ curl https://example.com/wp-json/wp/v2/users/&lt;id&gt;</code>
</div>
<div class="secondary">
		<h3>Arguments</h3>
<table class="arguments">
				<tr>
			<td>
										<code>id</code><br />
								</td>
			<td>
										<p>Unique identifier for the user.</p>
																							</td>
		</tr>
				<tr>
			<td>
										<code>context</code><br />
								</td>
			<td>
										<p>Scope under which the request is made; determines fields present in response.</p>
																				<p class="default">
						Default: <code>view</code>
					</p>
															<p>One of: <code>view</code>, <code>embed</code>, <code>edit</code></p>
								</td>
		</tr>
		</table>

</div>

Update a User

Arguments

id

Unique identifier for the user.

username

Login name for the user.

name

Display name for the user.

first_name

First name for the user.

last_name

Last name for the user.

email

The email address for the user.

url

URL of the user.

description

Description of the user.

locale

Locale for the user.

One of: , en_US

nickname

The nickname for the user.

slug

An alphanumeric identifier for the user.

roles

Roles assigned to the user.

password

Password for the user (never included).

meta

Meta fields.

</div>
<div class="secondary">
	<h3>Definition</h3>

	<code>POST /wp/v2/users/&lt;id&gt;</code>

	<h3>Example Request</h3>

	<code></code>
</div>

Delete a User

Arguments

id

Unique identifier for the user.

force

Required to be true, as users do not support trashing.

reassign

Reassign the deleted user's posts and links to this user ID.

Required: 1

</div>
<div class="secondary">
	<h3>Definition</h3>

	<code>DELETE /wp/v2/users/&lt;id&gt;</code>

	<h3>Example Request</h3>

	<code>$ curl -X DELETE https://example.com/wp-json/wp/v2/users/&lt;id&gt;</code>
</div>

Retrieve a User

	<h3>Definition & Example Request</h3>

	<code>GET /wp/v2/users/me</code>

	<p>Query this endpoint to retrieve a specific user record.</p>

	<code>$ curl https://example.com/wp-json/wp/v2/users/me</code>
</div>
<div class="secondary">
		<h3>Arguments</h3>
<table class="arguments">
				<tr>
			<td>
										<code>context</code><br />
								</td>
			<td>
										<p>Scope under which the request is made; determines fields present in response.</p>
																				<p class="default">
						Default: <code>view</code>
					</p>
															<p>One of: <code>view</code>, <code>embed</code>, <code>edit</code></p>
								</td>
		</tr>
		</table>

</div>

Update a User

Arguments

username

Login name for the user.

name

Display name for the user.

first_name

First name for the user.

last_name

Last name for the user.

email

The email address for the user.

url

URL of the user.

description

Description of the user.

locale

Locale for the user.

One of: , en_US

nickname

The nickname for the user.

slug

An alphanumeric identifier for the user.

roles

Roles assigned to the user.

password

Password for the user (never included).

meta

Meta fields.

</div>
<div class="secondary">
	<h3>Definition</h3>

	<code>POST /wp/v2/users/me</code>

	<h3>Example Request</h3>

	<code></code>
</div>

Delete a User

Arguments

force

Required to be true, as users do not support trashing.

reassign

Reassign the deleted user's posts and links to this user ID.

Required: 1

</div>
<div class="secondary">
	<h3>Definition</h3>

	<code>DELETE /wp/v2/users/me</code>

	<h3>Example Request</h3>

	<code>$ curl -X DELETE https://example.com/wp-json/wp/v2/users/me</code>
</div>