REST API: Introduce baby API to the world.
Baby API was born at 2.8KLOC on October 8th at 2:30 UTC. API has lots of growing to do, so wish it the best of luck. Thanks to everyone who helped along the way: Props rmccue, rachelbaker, danielbachhuber, joehoyle, drewapicture, adamsilverstein, netweb, tlovett1, shelob9, kadamwhite, pento, westonruter, nikv, tobych, redsweater, alecuf, pollyplummer, hurtige, bpetty, oso96_2000, ericlewis, wonderboymusic, joshkadis, mordauk, jdgrimes, johnbillion, jeremyfelt, thiago-negri, jdolan, pkevan, iseulde, thenbrent, maxcutler, kwight, markoheijnen, phh, natewr, jjeaton, shprink, mattheu, quasel, jmusal, codebykat, hubdotcom, tapsboy, QWp6t, pushred, jaredcobb, justinsainton, japh, matrixik, jorbin, frozzare, codfish, michael-arestad, kellbot, ironpaperweight, simonlampen, alisspers, eliorivero, davidbhayes, JohnDittmar, dimadin, traversal, cmmarslender, Toddses, kokarn, welcher, and ericpedia. Fixes #33982. Built from https://develop.svn.wordpress.org/trunk@34928 git-svn-id: http://core.svn.wordpress.org/trunk@34893 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b3051048be
commit
94e2352956
|
@ -204,6 +204,17 @@ add_filter( 'title_save_pre', 'trim' );
|
|||
|
||||
add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
|
||||
|
||||
// REST API filters.
|
||||
add_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
|
||||
add_action( 'wp_head', 'rest_output_link_wp_head', 10, 0 );
|
||||
add_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
|
||||
add_action( 'auth_cookie_malformed', 'rest_cookie_collect_status' );
|
||||
add_action( 'auth_cookie_expired', 'rest_cookie_collect_status' );
|
||||
add_action( 'auth_cookie_bad_username', 'rest_cookie_collect_status' );
|
||||
add_action( 'auth_cookie_bad_hash', 'rest_cookie_collect_status' );
|
||||
add_action( 'auth_cookie_valid', 'rest_cookie_collect_status' );
|
||||
add_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
|
||||
|
||||
// Actions
|
||||
add_action( 'wp_head', '_wp_render_title_tag', 1 );
|
||||
add_action( 'wp_head', 'wp_enqueue_scripts', 1 );
|
||||
|
@ -347,6 +358,11 @@ add_action( 'after_password_reset', 'wp_password_change_notification' );
|
|||
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
|
||||
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
|
||||
|
||||
// REST API actions.
|
||||
add_action( 'init', 'rest_api_init' );
|
||||
add_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
|
||||
add_action( 'parse_request', 'rest_api_loaded' );
|
||||
|
||||
/**
|
||||
* Filters formerly mixed into wp-includes
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API functions.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST_API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Version number for our API.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
define( 'REST_API_VERSION', '2.0' );
|
||||
|
||||
/** WP_REST_Server class */
|
||||
require_once( ABSPATH . WPINC . '/rest-api/lib/class-wp-rest-server.php' );
|
||||
|
||||
/** WP_REST_Response class */
|
||||
require_once( ABSPATH . WPINC . '/rest-api/lib/class-wp-rest-response.php' );
|
||||
|
||||
/** WP_REST_Request class */
|
||||
require_once( ABSPATH . WPINC . '/rest-api/lib/class-wp-rest-request.php' );
|
||||
|
||||
/** REST functions */
|
||||
require_once( ABSPATH . WPINC . '/rest-api/rest-functions.php' );
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API: WP_HTTP_Response class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST_API
|
||||
* @since 4.4.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Core class used to prepare HTTP responses.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
class WP_HTTP_Response {
|
||||
|
||||
/**
|
||||
* Response data.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Response headers.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* Response status.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $data Response data. Default null.
|
||||
* @param int $status Optional. HTTP status code. Default 200.
|
||||
* @param array $headers Optional. HTTP header map. Default empty array.
|
||||
*/
|
||||
public function __construct( $data = null, $status = 200, $headers = array() ) {
|
||||
$this->data = $data;
|
||||
$this->set_status( $status );
|
||||
$this->set_headers( $headers );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves headers associated with the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Map of header name to header value.
|
||||
*/
|
||||
public function get_headers() {
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all header values.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $headers Map of header name to header value.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a single HTTP header.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name.
|
||||
* @param string $value Header value.
|
||||
* @param bool $replace Optional. Whether to replace an existing header of the same name.
|
||||
* Default true.
|
||||
*/
|
||||
public function header( $key, $value, $replace = true ) {
|
||||
if ( $replace || ! isset( $this->headers[ $key ] ) ) {
|
||||
$this->headers[ $key ] = $value;
|
||||
} else {
|
||||
$this->headers[ $key ] .= ', ' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the HTTP return code for the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return int The 3-digit HTTP status code.
|
||||
*/
|
||||
public function get_status() {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the 3-digit HTTP status code.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param int $code HTTP status.
|
||||
*/
|
||||
public function set_status( $code ) {
|
||||
$this->status = absint( $code );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the response data.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return mixed Response data.
|
||||
*/
|
||||
public function get_data() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response data.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param mixed $data Response data.
|
||||
*/
|
||||
public function set_data( $data ) {
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the response data for JSON serialization.
|
||||
*
|
||||
* It is expected that in most implementations, this will return the same as get_data(),
|
||||
* however this may be different if you want to do custom JSON data handling.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return mixed Any JSON-serializable value.
|
||||
*/
|
||||
public function jsonSerialize() {
|
||||
return $this->get_data();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,930 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API: WP_REST_Request class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST_API
|
||||
* @since 4.4.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Core class used to implement a REST request object.
|
||||
*
|
||||
* Contains data from the request, to be passed to the callback.
|
||||
*
|
||||
* Note: This implements ArrayAccess, and acts as an array of parameters when
|
||||
* used in that manner. It does not use ArrayObject (as we cannot rely on SPL),
|
||||
* so be aware it may have non-array behaviour in some cases.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see ArrayAccess
|
||||
*/
|
||||
class WP_REST_Request implements ArrayAccess {
|
||||
|
||||
/**
|
||||
* HTTP method.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $method = '';
|
||||
|
||||
/**
|
||||
* Parameters passed to the request.
|
||||
*
|
||||
* These typically come from the `$_GET`, `$_POST` and `$_FILES`
|
||||
* superglobals when being created from the global scope.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var array Contains GET, POST and FILES keys mapping to arrays of data.
|
||||
*/
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* HTTP headers for the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var array Map of key to value. Key is always lowercase, as per HTTP specification.
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Body data.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var string Binary data from the request.
|
||||
*/
|
||||
protected $body = null;
|
||||
|
||||
/**
|
||||
* Route matched for the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $route;
|
||||
|
||||
/**
|
||||
* Attributes (options) for the route that was matched.
|
||||
*
|
||||
* This is the options array used when the route was registered, typically
|
||||
* containing the callback as well as the valid methods for the route.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var array Attributes for the request.
|
||||
*/
|
||||
protected $attributes = array();
|
||||
|
||||
/**
|
||||
* Used to determine if the JSON data has been parsed yet.
|
||||
*
|
||||
* Allows lazy-parsing of JSON data where possible.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected $parsed_json = false;
|
||||
|
||||
/**
|
||||
* Used to determine if the body data has been parsed yet.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var bool
|
||||
*/
|
||||
protected $parsed_body = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $method Optional. Request method. Default empty.
|
||||
* @param string $route Optional. Request route. Default empty.
|
||||
* @param array $attributes Optional. Request attributes. Default empty array.
|
||||
*/
|
||||
public function __construct( $method = '', $route = '', $attributes = array() ) {
|
||||
$this->params = array(
|
||||
'URL' => array(),
|
||||
'GET' => array(),
|
||||
'POST' => array(),
|
||||
'FILES' => array(),
|
||||
|
||||
// See parse_json_params.
|
||||
'JSON' => null,
|
||||
|
||||
'defaults' => array(),
|
||||
);
|
||||
|
||||
$this->set_method( $method );
|
||||
$this->set_route( $route );
|
||||
$this->set_attributes( $attributes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the HTTP method for the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return string HTTP method.
|
||||
*/
|
||||
public function get_method() {
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets HTTP method for the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $method HTTP method.
|
||||
*/
|
||||
public function set_method( $method ) {
|
||||
$this->method = strtoupper( $method );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all headers from the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Map of key to value. Key is always lowercase, as per HTTP specification.
|
||||
*/
|
||||
public function get_headers() {
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonicalizes the header name.
|
||||
*
|
||||
* Ensures that header names are always treated the same regardless of
|
||||
* source. Header names are always case insensitive.
|
||||
*
|
||||
* Note that we treat `-` (dashes) and `_` (underscores) as the same
|
||||
* character, as per header parsing rules in both Apache and nginx.
|
||||
*
|
||||
* @link http://stackoverflow.com/q/18185366
|
||||
* @link http://wiki.nginx.org/Pitfalls#Missing_.28disappearing.29_HTTP_headers
|
||||
* @link http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param string $key Header name.
|
||||
* @return string Canonicalized name.
|
||||
*/
|
||||
public static function canonicalize_header_name( $key ) {
|
||||
$key = strtolower( $key );
|
||||
$key = str_replace( '-', '_', $key );
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the given header from the request.
|
||||
*
|
||||
* If the header has multiple values, they will be concatenated with a comma
|
||||
* as per the HTTP specification. Be aware that some non-compliant headers
|
||||
* (notably cookie headers) cannot be joined this way.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name, will be canonicalized to lowercase.
|
||||
* @return string|null String value if set, null otherwise.
|
||||
*/
|
||||
public function get_header( $key ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
|
||||
if ( ! isset( $this->headers[ $key ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return implode( ',', $this->headers[ $key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves header values from the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name, will be canonicalized to lowercase.
|
||||
* @return array|null List of string values if set, null otherwise.
|
||||
*/
|
||||
public function get_header_as_array( $key ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
|
||||
if ( ! isset( $this->headers[ $key ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->headers[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header on request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name.
|
||||
* @param string $value Header value, or list of values.
|
||||
*/
|
||||
public function set_header( $key, $value ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$value = (array) $value;
|
||||
|
||||
$this->headers[ $key ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a header value for the given header.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name.
|
||||
* @param string $value Header value, or list of values.
|
||||
*/
|
||||
public function add_header( $key, $value ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$value = (array) $value;
|
||||
|
||||
if ( ! isset( $this->headers[ $key ] ) ) {
|
||||
$this->headers[ $key ] = array();
|
||||
}
|
||||
|
||||
$this->headers[ $key ] = array_merge( $this->headers[ $key ], $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all values for a header.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Header name.
|
||||
*/
|
||||
public function remove_header( $key ) {
|
||||
unset( $this->headers[ $key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets headers on the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $headers Map of header name to value.
|
||||
* @param bool $override If true, replace the request's headers. Otherwise, merge with existing.
|
||||
*/
|
||||
public function set_headers( $headers, $override = true ) {
|
||||
if ( true === $override ) {
|
||||
$this->headers = array();
|
||||
}
|
||||
|
||||
foreach ( $headers as $key => $value ) {
|
||||
$this->set_header( $key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the content-type of the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Map containing 'value' and 'parameters' keys.
|
||||
*/
|
||||
public function get_content_type() {
|
||||
$value = $this->get_header( 'content-type' );
|
||||
if ( empty( $value ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$parameters = '';
|
||||
if ( strpos( $value, ';' ) ) {
|
||||
list( $value, $parameters ) = explode( ';', $value, 2 );
|
||||
}
|
||||
|
||||
$value = strtolower( $value );
|
||||
if ( strpos( $value, '/' ) === false ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Parse type and subtype out.
|
||||
list( $type, $subtype ) = explode( '/', $value, 2 );
|
||||
|
||||
$data = compact( 'value', 'type', 'subtype', 'parameters' );
|
||||
$data = array_map( 'trim', $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the parameter priority order.
|
||||
*
|
||||
* Used when checking parameters in get_param().
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array List of types to check, in order of priority.
|
||||
*/
|
||||
protected function get_parameter_order() {
|
||||
$order = array();
|
||||
$order[] = 'JSON';
|
||||
|
||||
$this->parse_json_params();
|
||||
|
||||
// Ensure we parse the body data.
|
||||
$body = $this->get_body();
|
||||
if ( $this->method !== 'POST' && ! empty( $body ) ) {
|
||||
$this->parse_body_params();
|
||||
}
|
||||
|
||||
$accepts_body_data = array( 'POST', 'PUT', 'PATCH' );
|
||||
if ( in_array( $this->method, $accepts_body_data ) ) {
|
||||
$order[] = 'POST';
|
||||
}
|
||||
|
||||
$order[] = 'GET';
|
||||
$order[] = 'URL';
|
||||
$order[] = 'defaults';
|
||||
|
||||
/**
|
||||
* Filter the parameter order.
|
||||
*
|
||||
* The order affects which parameters are checked when using get_param() and family.
|
||||
* This acts similarly to PHP's `request_order` setting.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param array $order {
|
||||
* An array of types to check, in order of priority.
|
||||
*
|
||||
* @param string $type The type to check.
|
||||
* }
|
||||
* @param WP_REST_Request $this The request object.
|
||||
*/
|
||||
return apply_filters( 'rest_request_parameter_order', $order, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a parameter from the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Parameter name.
|
||||
* @return mixed|null Value if set, null otherwise.
|
||||
*/
|
||||
public function get_param( $key ) {
|
||||
$order = $this->get_parameter_order();
|
||||
|
||||
foreach ( $order as $type ) {
|
||||
// Determine if we have the parameter for this type.
|
||||
if ( isset( $this->params[ $type ][ $key ] ) ) {
|
||||
return $this->params[ $type ][ $key ];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter on the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $key Parameter name.
|
||||
* @param mixed $value Parameter value.
|
||||
*/
|
||||
public function set_param( $key, $value ) {
|
||||
switch ( $this->method ) {
|
||||
case 'POST':
|
||||
$this->params['POST'][ $key ] = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->params['GET'][ $key ] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves merged parameters from the request.
|
||||
*
|
||||
* The equivalent of get_param(), but returns all parameters for the request.
|
||||
* Handles merging all the available values into a single array.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Map of key to value.
|
||||
*/
|
||||
public function get_params() {
|
||||
$order = $this->get_parameter_order();
|
||||
$order = array_reverse( $order, true );
|
||||
|
||||
$params = array();
|
||||
foreach ( $order as $type ) {
|
||||
$params = array_merge( $params, (array) $this->params[ $type ] );
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves parameters from the route itself.
|
||||
*
|
||||
* These are parsed from the URL using the regex.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value.
|
||||
*/
|
||||
public function get_url_params() {
|
||||
return $this->params['URL'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets parameters from the route.
|
||||
*
|
||||
* Typically, this is set after parsing the URL.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $params Parameter map of key to value.
|
||||
*/
|
||||
public function set_url_params( $params ) {
|
||||
$this->params['URL'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves parameters from the query string.
|
||||
*
|
||||
* These are the parameters you'd typically find in `$_GET`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value
|
||||
*/
|
||||
public function get_query_params() {
|
||||
return $this->params['GET'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets parameters from the query string.
|
||||
*
|
||||
* Typically, this is set from `$_GET`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $params Parameter map of key to value.
|
||||
*/
|
||||
public function set_query_params( $params ) {
|
||||
$this->params['GET'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves parameters from the body.
|
||||
*
|
||||
* These are the parameters you'd typically find in `$_POST`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value.
|
||||
*/
|
||||
public function get_body_params() {
|
||||
return $this->params['POST'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets parameters from the body.
|
||||
*
|
||||
* Typically, this is set from `$_POST`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $params Parameter map of key to value.
|
||||
*/
|
||||
public function set_body_params( $params ) {
|
||||
$this->params['POST'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves multipart file parameters from the body.
|
||||
*
|
||||
* These are the parameters you'd typically find in `$_FILES`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value
|
||||
*/
|
||||
public function get_file_params() {
|
||||
return $this->params['FILES'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets multipart file parameters from the body.
|
||||
*
|
||||
* Typically, this is set from `$_FILES`.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $params Parameter map of key to value.
|
||||
*/
|
||||
public function set_file_params( $params ) {
|
||||
$this->params['FILES'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default parameters.
|
||||
*
|
||||
* These are the parameters set in the route registration.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value
|
||||
*/
|
||||
public function get_default_params() {
|
||||
return $this->params['defaults'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default parameters.
|
||||
*
|
||||
* These are the parameters set in the route registration.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $params Parameter map of key to value.
|
||||
*/
|
||||
public function set_default_params( $params ) {
|
||||
$this->params['defaults'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the request body content.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Binary data from the request body.
|
||||
*/
|
||||
public function get_body() {
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets body content.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $data Binary data from the request body.
|
||||
*/
|
||||
public function set_body( $data ) {
|
||||
$this->body = $data;
|
||||
|
||||
// Enable lazy parsing.
|
||||
$this->parsed_json = false;
|
||||
$this->parsed_body = false;
|
||||
$this->params['JSON'] = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the parameters from a JSON-formatted body.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Parameter map of key to value.
|
||||
*/
|
||||
public function get_json_params() {
|
||||
// Ensure the parameters have been parsed out.
|
||||
$this->parse_json_params();
|
||||
|
||||
return $this->params['JSON'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the JSON parameters.
|
||||
*
|
||||
* Avoids parsing the JSON data until we need to access it.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function parse_json_params() {
|
||||
if ( $this->parsed_json ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->parsed_json = true;
|
||||
|
||||
// Check that we actually got JSON.
|
||||
$content_type = $this->get_content_type();
|
||||
|
||||
if ( empty( $content_type ) || 'application/json' !== $content_type['value'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = json_decode( $this->get_body(), true );
|
||||
|
||||
/*
|
||||
* Check for a parsing error.
|
||||
*
|
||||
* Note that due to WP's JSON compatibility functions, json_last_error
|
||||
* might not be defined: https://core.trac.wordpress.org/ticket/27799
|
||||
*/
|
||||
if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->params['JSON'] = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the request body parameters.
|
||||
*
|
||||
* Parses out URL-encoded bodies for request methods that aren't supported
|
||||
* natively by PHP. In PHP 5.x, only POST has these parsed automatically.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function parse_body_params() {
|
||||
if ( $this->parsed_body ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->parsed_body = true;
|
||||
|
||||
/*
|
||||
* Check that we got URL-encoded. Treat a missing content-type as
|
||||
* URL-encoded for maximum compatibility.
|
||||
*/
|
||||
$content_type = $this->get_content_type();
|
||||
|
||||
if ( ! empty( $content_type ) && 'application/x-www-form-urlencoded' !== $content_type['value'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
parse_str( $this->get_body(), $params );
|
||||
|
||||
/*
|
||||
* Amazingly, parse_str follows magic quote rules. Sigh.
|
||||
*
|
||||
* NOTE: Do not refactor to use `wp_unslash`.
|
||||
*/
|
||||
if ( get_magic_quotes_gpc() ) {
|
||||
$params = stripslashes_deep( $params );
|
||||
}
|
||||
|
||||
/*
|
||||
* Add to the POST parameters stored internally. If a user has already
|
||||
* set these manually (via `set_body_params`), don't override them.
|
||||
*/
|
||||
$this->params['POST'] = array_merge( $params, $this->params['POST'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the route that matched the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Route matching regex.
|
||||
*/
|
||||
public function get_route() {
|
||||
return $this->route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the route that matched the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $route Route matching regex.
|
||||
*/
|
||||
public function set_route( $route ) {
|
||||
$this->route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attributes for the request.
|
||||
*
|
||||
* These are the options for the route that was matched.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Attributes for the request.
|
||||
*/
|
||||
public function get_attributes() {
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes for the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $attributes Attributes for the request.
|
||||
*/
|
||||
public function set_attributes( $attributes ) {
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes (where possible) the params on the request.
|
||||
*
|
||||
* This is primarily based off the sanitize_callback param on each registered
|
||||
* argument.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return true|null True if there are no parameters to sanitize, null otherwise.
|
||||
*/
|
||||
public function sanitize_params() {
|
||||
|
||||
$attributes = $this->get_attributes();
|
||||
|
||||
// No arguments set, skip sanitizing.
|
||||
if ( empty( $attributes['args'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$order = $this->get_parameter_order();
|
||||
|
||||
foreach ( $order as $type ) {
|
||||
if ( empty( $this->params[ $type ] ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $this->params[ $type ] as $key => $value ) {
|
||||
// Check if this param has a sanitize_callback added.
|
||||
if ( isset( $attributes['args'][ $key ] ) && ! empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) {
|
||||
$this->params[ $type ][ $key ] = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key );
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this request is valid according to its attributes.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool|WP_Error True if there are no parameters to validate or if all pass validation,
|
||||
* WP_Error if required parameters are missing.
|
||||
*/
|
||||
public function has_valid_params() {
|
||||
|
||||
$attributes = $this->get_attributes();
|
||||
$required = array();
|
||||
|
||||
// No arguments set, skip validation.
|
||||
if ( empty( $attributes['args'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ( $attributes['args'] as $key => $arg ) {
|
||||
|
||||
$param = $this->get_param( $key );
|
||||
if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) {
|
||||
$required[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $required ) ) {
|
||||
return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the validation callbacks for each registered arg.
|
||||
*
|
||||
* This is done after required checking as required checking is cheaper.
|
||||
*/
|
||||
$invalid_params = array();
|
||||
|
||||
foreach ( $attributes['args'] as $key => $arg ) {
|
||||
|
||||
$param = $this->get_param( $key );
|
||||
|
||||
if ( null !== $param && ! empty( $arg['validate_callback'] ) ) {
|
||||
$valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key );
|
||||
|
||||
if ( false === $valid_check ) {
|
||||
$invalid_params[ $key ] = __( 'Invalid param.' );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $valid_check ) ) {
|
||||
$invalid_params[] = sprintf( '%s (%s)', $key, $valid_check->get_error_message() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $invalid_params ) {
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', $invalid_params ) ), array( 'status' => 400, 'params' => $invalid_params ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a parameter is set.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $offset Parameter name.
|
||||
* @return bool Whether the parameter is set.
|
||||
*/
|
||||
public function offsetExists( $offset ) {
|
||||
$order = $this->get_parameter_order();
|
||||
|
||||
foreach ( $order as $type ) {
|
||||
if ( isset( $this->params[ $type ][ $offset ] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a parameter from the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $offset Parameter name.
|
||||
* @return mixed|null Value if set, null otherwise.
|
||||
*/
|
||||
public function offsetGet( $offset ) {
|
||||
return $this->get_param( $offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter on the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $offset Parameter name.
|
||||
* @param mixed $value Parameter value.
|
||||
*/
|
||||
public function offsetSet( $offset, $value ) {
|
||||
$this->set_param( $offset, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a parameter from the request.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $offset Parameter name.
|
||||
*/
|
||||
public function offsetUnset( $offset ) {
|
||||
$order = $this->get_parameter_order();
|
||||
|
||||
// Remove the offset from every group.
|
||||
foreach ( $order as $type ) {
|
||||
unset( $this->params[ $type ][ $offset ] );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API: WP_REST_Response class
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST_API
|
||||
* @since 4.4.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Core class used to implement a REST response object.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see WP_HTTP_Response
|
||||
*/
|
||||
class WP_REST_Response extends WP_HTTP_Response {
|
||||
|
||||
/**
|
||||
* Links related to the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $links = array();
|
||||
|
||||
/**
|
||||
* The route that was to create the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $matched_route = '';
|
||||
|
||||
/**
|
||||
* The handler that was used to create the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access protected
|
||||
* @var null|array
|
||||
*/
|
||||
protected $matched_handler = null;
|
||||
|
||||
/**
|
||||
* Adds a link to the response.
|
||||
*
|
||||
* @internal The $rel parameter is first, as this looks nicer when sending multiple.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5988
|
||||
* @link http://www.iana.org/assignments/link-relations/link-relations.xml
|
||||
*
|
||||
* @param string $rel Link relation. Either an IANA registered type,
|
||||
* or an absolute URL.
|
||||
* @param string $href Target URI for the link.
|
||||
* @param array $attributes Optional. Link parameters to send along with the URL. Default empty array.
|
||||
*/
|
||||
public function add_link( $rel, $href, $attributes = array() ) {
|
||||
if ( empty( $this->links[ $rel ] ) ) {
|
||||
$this->links[ $rel ] = array();
|
||||
}
|
||||
|
||||
if ( isset( $attributes['href'] ) ) {
|
||||
// Remove the href attribute, as it's used for the main URL.
|
||||
unset( $attributes['href'] );
|
||||
}
|
||||
|
||||
$this->links[ $rel ][] = array(
|
||||
'href' => $href,
|
||||
'attributes' => $attributes,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a link from the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $rel Link relation. Either an IANA registered type, or an absolute URL.
|
||||
* @param string $href Optional. Only remove links for the relation matching the given href.
|
||||
* Default null.
|
||||
*/
|
||||
public function remove_link( $rel, $href = null ) {
|
||||
if ( ! isset( $this->links[ $rel ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $href ) {
|
||||
$this->links[ $rel ] = wp_list_filter( $this->links[ $rel ], array( 'href' => $href ), 'NOT' );
|
||||
} else {
|
||||
$this->links[ $rel ] = array();
|
||||
}
|
||||
|
||||
if ( ! $this->links[ $rel ] ) {
|
||||
unset( $this->links[ $rel ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple links to the response.
|
||||
*
|
||||
* Link data should be an associative array with link relation as the key.
|
||||
* The value can either be an associative array of link attributes
|
||||
* (including `href` with the URL for the response), or a list of these
|
||||
* associative arrays.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $links Map of link relation to list of links.
|
||||
*/
|
||||
public function add_links( $links ) {
|
||||
foreach ( $links as $rel => $set ) {
|
||||
// If it's a single link, wrap with an array for consistent handling.
|
||||
if ( isset( $set['href'] ) ) {
|
||||
$set = array( $set );
|
||||
}
|
||||
|
||||
foreach ( $set as $attributes ) {
|
||||
$this->add_link( $rel, $attributes['href'], $attributes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves links for the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return array List of links.
|
||||
*/
|
||||
public function get_links() {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a single link header.
|
||||
*
|
||||
* @internal The $rel parameter is first, as this looks nicer when sending multiple.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5988
|
||||
* @link http://www.iana.org/assignments/link-relations/link-relations.xml
|
||||
*
|
||||
* @param string $rel Link relation. Either an IANA registered type, or an absolute URL.
|
||||
* @param string $link Target IRI for the link.
|
||||
* @param array $other Optional. Other parameters to send, as an assocative array.
|
||||
* Default empty array.
|
||||
*/
|
||||
public function link_header( $rel, $link, $other = array() ) {
|
||||
$header = '<' . $link . '>; rel="' . $rel . '"';
|
||||
|
||||
foreach ( $other as $key => $value ) {
|
||||
if ( 'title' === $key ) {
|
||||
$value = '"' . $value . '"';
|
||||
}
|
||||
$header .= '; ' . $key . '=' . $value;
|
||||
}
|
||||
$this->header( 'Link', $header, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the route that was used.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return string The matched route.
|
||||
*/
|
||||
public function get_matched_route() {
|
||||
return $this->matched_route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the route (regex for path) that caused the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $route Route name.
|
||||
*/
|
||||
public function set_matched_route( $route ) {
|
||||
$this->matched_route = $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the handler that was used to generate the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return null|array The handler that was used to create the response.
|
||||
*/
|
||||
public function get_matched_handler() {
|
||||
return $this->matched_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the handler that was responsible for generating the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @param array $handler The matched handler.
|
||||
*/
|
||||
public function set_matched_handler( $handler ) {
|
||||
$this->matched_handler = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the response is an error, i.e. >= 400 response code.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool Whether the response is an error.
|
||||
*/
|
||||
public function is_error() {
|
||||
return $this->get_status() >= 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a WP_Error object from the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @access public
|
||||
*
|
||||
* @return WP_Error|null WP_Error or null on not an errored response.
|
||||
*/
|
||||
public function as_error() {
|
||||
if ( ! $this->is_error() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$error = new WP_Error;
|
||||
|
||||
if ( is_array( $this->get_data() ) ) {
|
||||
foreach ( $this->get_data() as $err ) {
|
||||
$error->add( $err['code'], $err['message'], $err['data'] );
|
||||
}
|
||||
} else {
|
||||
$error->add( $this->get_status(), '', array( 'status' => $this->get_status() ) );
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,666 @@
|
|||
<?php
|
||||
/**
|
||||
* REST API functions.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST_API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers a REST API route.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
|
||||
* @param string $route The base URL for route you are adding.
|
||||
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
|
||||
* multiple methods. Default empty array.
|
||||
* @param bool $override Optional. If the route already exists, should we override it? True overrides,
|
||||
* false merges (with newer overriding if duplicate keys exist). Default false.
|
||||
*/
|
||||
function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
|
||||
|
||||
/** @var WP_REST_Server $wp_rest_server */
|
||||
global $wp_rest_server;
|
||||
|
||||
if ( isset( $args['callback'] ) ) {
|
||||
// Upgrade a single set to multiple.
|
||||
$args = array( $args );
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'methods' => 'GET',
|
||||
'callback' => null,
|
||||
'args' => array(),
|
||||
);
|
||||
foreach ( $args as $key => &$arg_group ) {
|
||||
if ( ! is_numeric( $arg_group ) ) {
|
||||
// Route option, skip here.
|
||||
continue;
|
||||
}
|
||||
|
||||
$arg_group = array_merge( $defaults, $arg_group );
|
||||
}
|
||||
|
||||
if ( $namespace ) {
|
||||
$full_route = '/' . trim( $namespace, '/' ) . '/' . trim( $route, '/' );
|
||||
} else {
|
||||
/*
|
||||
* Non-namespaced routes are not allowed, with the exception of the main
|
||||
* and namespace indexes. If you really need to register a
|
||||
* non-namespaced route, call `WP_REST_Server::register_route` directly.
|
||||
*/
|
||||
_doing_it_wrong( 'register_rest_route', 'Routes must be namespaced with plugin name and version', 'WPAPI-2.0' );
|
||||
|
||||
$full_route = '/' . trim( $route, '/' );
|
||||
}
|
||||
|
||||
$wp_rest_server->register_route( $namespace, $full_route, $args, $override );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new field on an existing WordPress object type.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @global array $wp_rest_additional_fields Holds registered fields, organized
|
||||
* by object type.
|
||||
*
|
||||
* @param string|array $object_type Object(s) the field is being registered
|
||||
* to, "post"|"term"|"comment" etc.
|
||||
* @param string $attribute The attribute name.
|
||||
* @param array $args {
|
||||
* Optional. An array of arguments used to handle the registered field.
|
||||
*
|
||||
* @type string|array|null $get_callback Optional. The callback function used to retrieve the field
|
||||
* value. Default is 'null', the field will not be returned in
|
||||
* the response.
|
||||
* @type string|array|null $update_callback Optional. The callback function used to set and update the
|
||||
* field value. Default is 'null', the value cannot be set or
|
||||
* updated.
|
||||
* @type string|array|null schema Optional. The callback function used to create the schema for
|
||||
* this field. Default is 'null', no schema entry will be returned.
|
||||
* }
|
||||
*/
|
||||
function register_api_field( $object_type, $attribute, $args = array() ) {
|
||||
|
||||
$defaults = array(
|
||||
'get_callback' => null,
|
||||
'update_callback' => null,
|
||||
'schema' => null,
|
||||
);
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
global $wp_rest_additional_fields;
|
||||
|
||||
$object_types = (array) $object_type;
|
||||
|
||||
foreach ( $object_types as $object_type ) {
|
||||
$wp_rest_additional_fields[ $object_type ][ $attribute ] = $args;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers rewrite rules for the API.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see rest_api_register_rewrites()
|
||||
* @global WP $wp Current WordPress environment instance.
|
||||
*/
|
||||
function rest_api_init() {
|
||||
rest_api_register_rewrites();
|
||||
|
||||
global $wp;
|
||||
$wp->add_query_var( 'rest_route' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds REST rewrite rules.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see add_rewrite_rule()
|
||||
*/
|
||||
function rest_api_register_rewrites() {
|
||||
add_rewrite_rule( '^' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
|
||||
add_rewrite_rule( '^' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the default REST API filters.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @internal This will live in default-filters.php
|
||||
*/
|
||||
function rest_api_default_filters() {
|
||||
// Deprecated reporting.
|
||||
add_action( 'deprecated_function_run', 'rest_handle_deprecated_function', 10, 3 );
|
||||
add_filter( 'deprecated_function_trigger_error', '__return_false' );
|
||||
add_action( 'deprecated_argument_run', 'rest_handle_deprecated_argument', 10, 3 );
|
||||
add_filter( 'deprecated_argument_trigger_error', '__return_false' );
|
||||
|
||||
// Default serving.
|
||||
add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
|
||||
add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
|
||||
|
||||
add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the REST API.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
function rest_api_loaded() {
|
||||
if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this is a REST Request.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
define( 'REST_REQUEST', true );
|
||||
|
||||
/** @var WP_REST_Server $wp_rest_server */
|
||||
global $wp_rest_server;
|
||||
|
||||
/**
|
||||
* Filter the REST Server Class.
|
||||
*
|
||||
* This filter allows you to adjust the server class used by the API, using a
|
||||
* different class to handle requests.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $class_name The name of the server class. Default 'WP_REST_Server'.
|
||||
*/
|
||||
$wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' );
|
||||
$wp_rest_server = new $wp_rest_server_class;
|
||||
|
||||
/**
|
||||
* Fires when preparing to serve an API request.
|
||||
*
|
||||
* Endpoint objects should be created and register their hooks on this action rather
|
||||
* than another action to ensure they're only loaded when needed.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param WP_REST_Server $wp_rest_server Server object.
|
||||
*/
|
||||
do_action( 'rest_api_init', $wp_rest_server );
|
||||
|
||||
// Fire off the request.
|
||||
$wp_rest_server->serve_request( $GLOBALS['wp']->query_vars['rest_route'] );
|
||||
|
||||
// We're done.
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL prefix for any API resource.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @return string Prefix.
|
||||
*/
|
||||
function rest_get_url_prefix() {
|
||||
/**
|
||||
* Filter the REST URL prefix.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $prefix URL prefix. Default 'wp-json'.
|
||||
*/
|
||||
return apply_filters( 'rest_url_prefix', 'wp-json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL to a REST endpoint on a site.
|
||||
*
|
||||
* Note: The returned URL is NOT escaped.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @todo Check if this is even necessary
|
||||
*
|
||||
* @param int $blog_id Optional. Blog ID. Default of null returns URL for current blog.
|
||||
* @param string $path Optional. REST route. Default '/'.
|
||||
* @param string $scheme Optional. Sanitization scheme. Default 'json'.
|
||||
* @return string Full URL to the endpoint.
|
||||
*/
|
||||
function get_rest_url( $blog_id = null, $path = '/', $scheme = 'json' ) {
|
||||
if ( empty( $path ) ) {
|
||||
$path = '/';
|
||||
}
|
||||
|
||||
if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
|
||||
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
|
||||
$url .= '/' . ltrim( $path, '/' );
|
||||
} else {
|
||||
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
|
||||
|
||||
$path = '/' . ltrim( $path, '/' );
|
||||
|
||||
$url = add_query_arg( 'rest_route', $path, $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the REST URL.
|
||||
*
|
||||
* Use this filter to adjust the url returned by the `get_rest_url` function.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $url REST URL.
|
||||
* @param string $path REST route.
|
||||
* @param int $blod_ig Blog ID.
|
||||
* @param string $scheme Sanitization scheme.
|
||||
*/
|
||||
return apply_filters( 'rest_url', $url, $path, $blog_id, $scheme );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL to a REST endpoint.
|
||||
*
|
||||
* Note: The returned URL is NOT escaped.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $path Optional. REST route. Default empty.
|
||||
* @param string $scheme Optional. Sanitization scheme. Default 'json'.
|
||||
* @return string Full URL to the endpoint.
|
||||
*/
|
||||
function rest_url( $path = '', $scheme = 'json' ) {
|
||||
return get_rest_url( null, $path, $scheme );
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a REST request.
|
||||
*
|
||||
* Used primarily to route internal requests through WP_REST_Server.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @global WP_REST_Server $wp_rest_server
|
||||
*
|
||||
* @param WP_REST_Request|string $request Request.
|
||||
* @return WP_REST_Response REST response.
|
||||
*/
|
||||
function rest_do_request( $request ) {
|
||||
global $wp_rest_server;
|
||||
$request = rest_ensure_request( $request );
|
||||
return $wp_rest_server->dispatch( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures request arguments are a request object (for consistency).
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param array|WP_REST_Request $request Request to check.
|
||||
* @return WP_REST_Request REST request instance.
|
||||
*/
|
||||
function rest_ensure_request( $request ) {
|
||||
if ( $request instanceof WP_REST_Request ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
return new WP_REST_Request( 'GET', '', $request );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures a REST response is a response object (for consistency).
|
||||
*
|
||||
* This implements WP_HTTP_Response, allowing usage of `set_status`/`header`/etc
|
||||
* without needing to double-check the object. Will also allow WP_Error to indicate error
|
||||
* responses, so users should immediately check for this value.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param WP_Error|WP_HTTP_Response|mixed $response Response to check.
|
||||
* @return mixed WP_Error if response generated an error, WP_HTTP_Response if response
|
||||
* is a already an instance, otherwise returns a new WP_REST_Response instance.
|
||||
*/
|
||||
function rest_ensure_response( $response ) {
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ( $response instanceof WP_HTTP_Response ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
return new WP_REST_Response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles _deprecated_function() errors.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $function Function name.
|
||||
* @param string $replacement Replacement function name.
|
||||
* @param string $version Version.
|
||||
*/
|
||||
function rest_handle_deprecated_function( $function, $replacement, $version ) {
|
||||
if ( ! empty( $replacement ) ) {
|
||||
$string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement );
|
||||
} else {
|
||||
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
|
||||
}
|
||||
|
||||
header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles _deprecated_argument() errors.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $function Function name.
|
||||
* @param string $replacement Replacement function name.
|
||||
* @param string $version Version.
|
||||
*/
|
||||
function rest_handle_deprecated_argument( $function, $replacement, $version ) {
|
||||
if ( ! empty( $replacement ) ) {
|
||||
$string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $replacement );
|
||||
} else {
|
||||
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
|
||||
}
|
||||
|
||||
header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends Cross-Origin Resource Sharing headers with API requests.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param mixed $value Response data.
|
||||
* @return mixed Response data.
|
||||
*/
|
||||
function rest_send_cors_headers( $value ) {
|
||||
$origin = get_http_origin();
|
||||
|
||||
if ( $origin ) {
|
||||
header( 'Access-Control-Allow-Origin: ' . esc_url_raw( $origin ) );
|
||||
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
|
||||
header( 'Access-Control-Allow-Credentials: true' );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles OPTIONS requests for the server.
|
||||
*
|
||||
* This is handled outside of the server code, as it doesn't obey normal route
|
||||
* mapping.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param mixed $response Current response, either response or `null` to indicate pass-through.
|
||||
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
|
||||
* @param WP_REST_Request $request The request that was used to make current response.
|
||||
* @return WP_REST_Response Modified response, either response or `null` to indicate pass-through.
|
||||
*/
|
||||
function rest_handle_options_request( $response, $handler, $request ) {
|
||||
if ( ! empty( $response ) || $request->get_method() !== 'OPTIONS' ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response = new WP_REST_Response();
|
||||
$data = array();
|
||||
|
||||
$accept = array();
|
||||
|
||||
foreach ( $handler->get_routes() as $route => $endpoints ) {
|
||||
$match = preg_match( '@^' . $route . '$@i', $request->get_route(), $args );
|
||||
|
||||
if ( ! $match ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
|
||||
$accept = array_merge( $accept, $data['methods'] );
|
||||
break;
|
||||
}
|
||||
$response->header( 'Accept', implode( ', ', $accept ) );
|
||||
|
||||
$response->set_data( $data );
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the "Allow" header to state all methods that can be sent to the current route.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param WP_REST_Response $response Current response being served.
|
||||
* @param WP_REST_Server $server ResponseHandler instance (usually WP_REST_Server).
|
||||
* @param WP_REST_Request $request The request that was used to make current response.
|
||||
* @return WP_REST_Response Current response being served.
|
||||
*/
|
||||
function rest_send_allow_header( $response, $server, $request ) {
|
||||
|
||||
$matched_route = $response->get_matched_route();
|
||||
|
||||
if ( ! $matched_route ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$routes = $server->get_routes();
|
||||
|
||||
$allowed_methods = array();
|
||||
|
||||
// Get the allowed methods across the routes.
|
||||
foreach ( $routes[ $matched_route ] as $_handler ) {
|
||||
foreach ( $_handler['methods'] as $handler_method => $value ) {
|
||||
|
||||
if ( ! empty( $_handler['permission_callback'] ) ) {
|
||||
|
||||
$permission = call_user_func( $_handler['permission_callback'], $request );
|
||||
|
||||
$allowed_methods[ $handler_method ] = true === $permission;
|
||||
} else {
|
||||
$allowed_methods[ $handler_method ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Strip out all the methods that are not allowed (false values).
|
||||
$allowed_methods = array_filter( $allowed_methods );
|
||||
|
||||
if ( $allowed_methods ) {
|
||||
$response->header( 'Allow', implode( ', ', array_map( 'strtoupper', array_keys( $allowed_methods ) ) ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the REST API URL to the WP RSD endpoint.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see get_rest_url()
|
||||
*/
|
||||
function rest_output_rsd() {
|
||||
$api_root = get_rest_url();
|
||||
|
||||
if ( empty( $api_root ) ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<api name="WP-API" blogID="1" preferred="false" apiLink="<?php echo esc_url( $api_root ); ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the REST API link tag into page header.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see get_rest_url()
|
||||
*/
|
||||
function rest_output_link_wp_head() {
|
||||
$api_root = get_rest_url();
|
||||
|
||||
if ( empty( $api_root ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo "<link rel='https://github.com/WP-API/WP-API' href='" . esc_url( $api_root ) . "' />\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a Link header for the REST API.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
function rest_output_link_header() {
|
||||
if ( headers_sent() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$api_root = get_rest_url();
|
||||
|
||||
if ( empty( $api_root ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
header( 'Link: <' . esc_url_raw( $api_root ) . '>; rel="https://github.com/WP-API/WP-API"', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for errors when using cookie-based authentication.
|
||||
*
|
||||
* WordPress' built-in cookie authentication is always active
|
||||
* for logged in users. However, the API has to check nonces
|
||||
* for each request to ensure users are not vulnerable to CSRF.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @global mixed $wp_rest_auth_cookie
|
||||
*
|
||||
* @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it,
|
||||
* or another value if not.
|
||||
* @return WP_Error|mixed|bool WP_Error if the cookie is invalid, the $result, otherwise true.
|
||||
*/
|
||||
function rest_cookie_check_errors( $result ) {
|
||||
if ( ! empty( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
global $wp_rest_auth_cookie;
|
||||
|
||||
/*
|
||||
* Is cookie authentication being used? (If we get an auth
|
||||
* error, but we're still logged in, another authentication
|
||||
* must have been used).
|
||||
*/
|
||||
if ( true !== $wp_rest_auth_cookie && is_user_logged_in() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Determine if there is a nonce.
|
||||
$nonce = null;
|
||||
|
||||
if ( isset( $_REQUEST['_wp_rest_nonce'] ) ) {
|
||||
$nonce = $_REQUEST['_wp_rest_nonce'];
|
||||
} elseif ( isset( $_SERVER['HTTP_X_WP_NONCE'] ) ) {
|
||||
$nonce = $_SERVER['HTTP_X_WP_NONCE'];
|
||||
}
|
||||
|
||||
if ( null === $nonce ) {
|
||||
// No nonce at all, so act as if it's an unauthenticated request.
|
||||
wp_set_current_user( 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check the nonce.
|
||||
$result = wp_verify_nonce( $nonce, 'wp_rest' );
|
||||
|
||||
if ( ! $result ) {
|
||||
return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects cookie authentication status.
|
||||
*
|
||||
* Collects errors from wp_validate_auth_cookie for use by rest_cookie_check_errors.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see current_action()
|
||||
* @global mixed $wp_rest_auth_cookie
|
||||
*/
|
||||
function rest_cookie_collect_status() {
|
||||
global $wp_rest_auth_cookie;
|
||||
|
||||
$status_type = current_action();
|
||||
|
||||
if ( 'auth_cookie_valid' !== $status_type ) {
|
||||
$wp_rest_auth_cookie = substr( $status_type, 12 );
|
||||
return;
|
||||
}
|
||||
|
||||
$wp_rest_auth_cookie = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an RFC3339 timestamp into a DateTime.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $date RFC3339 timestamp.
|
||||
* @param bool $force_utc Optional. Whether to force UTC timezone instead of using
|
||||
* the timestamp's timezone. Default false.
|
||||
* @return DateTime DateTime instance.
|
||||
*/
|
||||
function rest_parse_date( $date, $force_utc = false ) {
|
||||
if ( $force_utc ) {
|
||||
$date = preg_replace( '/[+-]\d+:?\d+$/', '+00:00', $date );
|
||||
}
|
||||
|
||||
$regex = '#^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}(?::\d{2})?)?$#';
|
||||
|
||||
if ( ! preg_match( $regex, $date, $matches ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strtotime( $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a local date with its GMT equivalent, in MySQL datetime format.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @see rest_parse_date()
|
||||
*
|
||||
* @param string $date RFC3339 timestamp.
|
||||
* @param bool $force_utc Whether a UTC timestamp should be forced. Default false.
|
||||
* @return array|null Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s),
|
||||
* null on failure.
|
||||
*/
|
||||
function rest_get_date_with_gmt( $date, $force_utc = false ) {
|
||||
$date = rest_parse_date( $date, $force_utc );
|
||||
|
||||
if ( empty( $date ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$utc = date( 'Y-m-d H:i:s', $date );
|
||||
$local = get_date_from_gmt( $utc );
|
||||
|
||||
return array( $local, $utc );
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-alpha-34927';
|
||||
$wp_version = '4.4-alpha-34928';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
|
@ -154,6 +154,7 @@ require( ABSPATH . WPINC . '/widgets.php' );
|
|||
require( ABSPATH . WPINC . '/nav-menu.php' );
|
||||
require( ABSPATH . WPINC . '/nav-menu-template.php' );
|
||||
require( ABSPATH . WPINC . '/admin-bar.php' );
|
||||
require( ABSPATH . WPINC . '/rest-api.php' );
|
||||
|
||||
// Load multisite-specific files.
|
||||
if ( is_multisite() ) {
|
||||
|
|
Loading…
Reference in New Issue