PHP 클래스 WP_REST_Server, wordpress

부터: 4.4.0
파일 보기 프로젝트 열기: johnpbloch/wordpress 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$endpoints array Endpoints registered to the server.
$namespaces array Namespaces registered to the server.
$route_options array Options defined for the routes.

공개 메소드들

메소드 설명
__construct ( ) Instantiates the REST server.
check_authentication ( ) : WP_Error | null Checks the authentication headers if supplied.
dispatch ( WP_REST_Request $request ) : WP_REST_Response Matches the request to a callback and call it.
envelope_response ( WP_REST_Response $response, boolean $embed ) : WP_REST_Response Wraps the response in an envelope.
get_compact_response_links ( WP_REST_Response $response ) : array Retrieves the CURIEs (compact URIs) used for relations.
get_data_for_route ( string $route, array $callbacks, string $context = 'view' ) : array | null Retrieves publicly-visible data for the route.
get_data_for_routes ( array $routes, string $context = 'view' ) : array Retrieves the publicly-visible data for routes.
get_headers ( array $server ) : array Extracts headers from a PHP-style $_SERVER array.
get_index ( array $request ) : array Retrieves the site index.
get_namespace_index ( WP_REST_Request $request ) : WP_REST_Response | WP_Error Retrieves the index for a namespace.
get_namespaces ( ) : array Retrieves namespaces registered on the server.
get_raw_data ( ) : string Retrieves the raw request entity (body).
get_response_links ( WP_REST_Response $response ) : array Retrieves links from a response.
get_route_options ( string $route ) : array | null Retrieves specified options for a route.
get_routes ( ) : array Retrieves the route map.
register_route ( string $namespace, string $route, array $route_args, boolean $override = false ) Registers a route to the server.
response_to_data ( WP_REST_Response $response, boolean $embed ) : array Converts a response to data to send.
send_header ( string $key, string $value ) Sends an HTTP header.
send_headers ( array $headers ) Sends multiple HTTP headers.
serve_request ( string $path = null ) : false | null Handles serving an API request.

보호된 메소드들

메소드 설명
embed_links ( array $data ) : array Embeds the links from the data into the request.
error_to_response ( WP_Error $error ) : WP_REST_Response Converts an error to a response object.
get_json_last_error ( ) : boolean | string Returns if an error occurred during most recent JSON encode/decode.
json_error ( string $code, string $message, integer $status = null ) : string Retrieves an appropriate error representation in JSON.
set_status ( integer $code ) Sends an HTTP status code.

메소드 상세

__construct() 공개 메소드

Instantiates the REST server.
부터: 4.4.0
public __construct ( )

check_authentication() 공개 메소드

Checks the authentication headers if supplied.
부터: 4.4.0
public check_authentication ( ) : WP_Error | null
리턴 WP_Error | null WP_Error indicates unsuccessful login, null indicates successful or no authentication provided

dispatch() 공개 메소드

Matches the request to a callback and call it.
부터: 4.4.0
public dispatch ( WP_REST_Request $request ) : WP_REST_Response
$request WP_REST_Request Request to attempt dispatching.
리턴 WP_REST_Response Response returned by the callback.

envelope_response() 공개 메소드

The enveloping technique is used to work around browser/client compatibility issues. Essentially, it converts the full HTTP response to data instead.
부터: 4.4.0
public envelope_response ( WP_REST_Response $response, boolean $embed ) : WP_REST_Response
$response WP_REST_Response Response object.
$embed boolean Whether links should be embedded.
리턴 WP_REST_Response New response with wrapped data

error_to_response() 보호된 메소드

This iterates over all error codes and messages to change it into a flat array. This enables simpler client behaviour, as it is represented as a list in JSON rather than an object/map.
부터: 4.4.0
protected error_to_response ( WP_Error $error ) : WP_REST_Response
$error WP_Error WP_Error instance.
리턴 WP_REST_Response List of associative arrays with code and message keys.

get_data_for_route() 공개 메소드

Retrieves publicly-visible data for the route.
부터: 4.4.0
public get_data_for_route ( string $route, array $callbacks, string $context = 'view' ) : array | null
$route string Route to get data for.
$callbacks array Callbacks to convert to data.
$context string Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'.
리턴 array | null Data for the route, or null if no publicly-visible data.

get_data_for_routes() 공개 메소드

Retrieves the publicly-visible data for routes.
부터: 4.4.0
public get_data_for_routes ( array $routes, string $context = 'view' ) : array
$routes array Routes to get data for.
$context string Optional. Context for data. Accepts 'view' or 'help'. Default 'view'.
리턴 array Route data to expose in indexes.

get_headers() 공개 메소드

Extracts headers from a PHP-style $_SERVER array.
부터: 4.4.0
public get_headers ( array $server ) : array
$server array Associative array similar to `$_SERVER`.
리턴 array Headers extracted from the input.

get_index() 공개 메소드

This endpoint describes the capabilities of the site.
부터: 4.4.0
public get_index ( array $request ) : array
$request array { Request. @type string $context Context. }
리턴 array Index entity

get_json_last_error() 보호된 메소드

Strings to be translated will be in format like "Encoding error: Maximum stack depth exceeded".
부터: 4.4.0
protected get_json_last_error ( ) : boolean | string
리턴 boolean | string Boolean false or string error message.

get_namespace_index() 공개 메소드

Retrieves the index for a namespace.
부터: 4.4.0
public get_namespace_index ( WP_REST_Request $request ) : WP_REST_Response | WP_Error
$request WP_REST_Request REST request instance.
리턴 WP_REST_Response | WP_Error WP_REST_Response instance if the index was found, WP_Error if the namespace isn't set.

get_namespaces() 공개 메소드

Retrieves namespaces registered on the server.
부터: 4.4.0
public get_namespaces ( ) : array
리턴 array List of registered namespaces.

get_raw_data() 공개 정적인 메소드

Retrieves the raw request entity (body).
부터: 4.4.0
public static get_raw_data ( ) : string
리턴 string Raw request data.

get_route_options() 공개 메소드

Retrieves specified options for a route.
부터: 4.4.0
public get_route_options ( string $route ) : array | null
$route string Route pattern to fetch options for.
리턴 array | null Data as an associative array if found, or null if not found.

get_routes() 공개 메소드

The route map is an associative array with path regexes as the keys. The value is an indexed array with the callback function/method as the first item, and a bitmask of HTTP methods as the second item (see the class constants). Each route can be mapped to more than one callback by using an array of the indexed arrays. This allows mapping e.g. GET requests to one callback and POST requests to another. Note that the path regexes (array keys) must have @ escaped, as this is used as the delimiter with preg_match()
부터: 4.4.0
public get_routes ( ) : array
리턴 array `'/path/regex' => array( $callback, $bitmask )` or `'/path/regex' => array( array( $callback, $bitmask ), ...)`.

json_error() 보호된 메소드

Note: This should only be used in WP_REST_Server::serve_request(), as it cannot handle WP_Error internally. All callbacks and other internal methods should instead return a WP_Error with the data set to an array that includes a 'status' key, with the value being the HTTP status to send.
부터: 4.4.0
protected json_error ( string $code, string $message, integer $status = null ) : string
$code string WP_Error-style code.
$message string Human-readable message.
$status integer Optional. HTTP status code to send. Default null.
리턴 string JSON representation of the error

register_route() 공개 메소드

Registers a route to the server.
부터: 4.4.0
public register_route ( string $namespace, string $route, array $route_args, boolean $override = false )
$namespace string Namespace.
$route string The REST route.
$route_args array Route arguments.
$override boolean Optional. Whether the route should be overridden if it already exists. Default false.

response_to_data() 공개 메소드

Converts a response to data to send.
부터: 4.4.0
public response_to_data ( WP_REST_Response $response, boolean $embed ) : array
$response WP_REST_Response Response object.
$embed boolean Whether links should be embedded.
리턴 array { Data with sub-requests embedded. @type array [$_links] Links. @type array [$_embedded] Embeddeds. }

send_header() 공개 메소드

Sends an HTTP header.
부터: 4.4.0
public send_header ( string $key, string $value )
$key string Header key.
$value string Header value.

send_headers() 공개 메소드

Sends multiple HTTP headers.
부터: 4.4.0
public send_headers ( array $headers )
$headers array Map of header name to header value.

serve_request() 공개 메소드

Matches the current server URI to a route and runs the first matching callback then outputs a JSON representation of the returned value.
또한 보기: WP_REST_Server::dispatch()
부터: 4.4.0
public serve_request ( string $path = null ) : false | null
$path string Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used. Default null.
리턴 false | null Null if not served and a HEAD request, false otherwise.

set_status() 보호된 메소드

Sends an HTTP status code.
부터: 4.4.0
protected set_status ( integer $code )
$code integer HTTP status.

프로퍼티 상세

$endpoints 보호되어 있는 프로퍼티

Endpoints registered to the server.
부터: 4.4.0
protected array $endpoints
리턴 array

$namespaces 보호되어 있는 프로퍼티

Namespaces registered to the server.
부터: 4.4.0
protected array $namespaces
리턴 array

$route_options 보호되어 있는 프로퍼티

Options defined for the routes.
부터: 4.4.0
protected array $route_options
리턴 array