Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -17,7 +17,10 @@ define( 'REST_API_VERSION', '2.0' );
/**
* Registers a REST API route.
*
* Note: Do not use before the {@see 'rest_api_init'} hook.
*
* @since 4.4.0
* @since 5.1.0 Added a _doing_it_wrong() notice when not called on or after the rest_api_init hook.
*
* @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.
@ -36,11 +39,23 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
*/
_doing_it_wrong( 'register_rest_route', __( 'Routes must be namespaced with plugin or theme name and version.' ), '4.4.0' );
return false;
} else if ( empty( $route ) ) {
} elseif ( empty( $route ) ) {
_doing_it_wrong( 'register_rest_route', __( 'Route must be specified.' ), '4.4.0' );
return false;
}
if ( ! did_action( 'rest_api_init' ) ) {
_doing_it_wrong(
'register_rest_route',
sprintf(
/* translators: %s: rest_api_init */
__( 'REST API routes must be registered on the %s action.' ),
'<code>rest_api_init</code>'
),
'5.1.0'
);
}
if ( isset( $args['args'] ) ) {
$common_args = $args['args'];
unset( $args['args'] );
@ -54,9 +69,9 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
}
$defaults = array(
'methods' => 'GET',
'callback' => null,
'args' => array(),
'methods' => 'GET',
'callback' => null,
'args' => array(),
);
foreach ( $args as $key => &$arg_group ) {
if ( ! is_numeric( $key ) ) {
@ -64,7 +79,7 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
continue;
}
$arg_group = array_merge( $defaults, $arg_group );
$arg_group = array_merge( $defaults, $arg_group );
$arg_group['args'] = array_merge( $common_args, $arg_group['args'] );
}
@ -141,10 +156,10 @@ function rest_api_init() {
function rest_api_register_rewrites() {
global $wp_rewrite;
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' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$','index.php?rest_route=/','top' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?','index.php?rest_route=/$matches[1]','top' );
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' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top' );
add_rewrite_rule( '^' . $wp_rewrite->index . '/' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top' );
}
/**
@ -198,7 +213,6 @@ function create_initial_rest_routes() {
$autosaves_controller = new WP_REST_Autosaves_Controller( $post_type->name );
$autosaves_controller->register_routes();
}
}
// Post types.
@ -446,7 +460,7 @@ function rest_get_server() {
* @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;
$wp_rest_server = new $wp_rest_server_class;
/**
* Fires when preparing to serve an API request.
@ -598,7 +612,7 @@ function rest_handle_options_request( $response, $handler, $request ) {
}
$response = new WP_REST_Response();
$data = array();
$data = array();
foreach ( $handler->get_routes() as $route => $endpoints ) {
$match = preg_match( '@^' . $route . '$@i', $request->get_route() );
@ -680,7 +694,7 @@ function rest_filter_response_fields( $response, $server, $request ) {
$data = $response->get_data();
$fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
$fields = wp_parse_list( $request['_fields'] );
if ( 0 === count( $fields ) ) {
return $response;
@ -896,9 +910,9 @@ function rest_get_date_with_gmt( $date, $is_utc = false ) {
// cases.
if ( ! $is_utc && ! $has_timezone ) {
$local = date( 'Y-m-d H:i:s', $date );
$utc = get_gmt_from_date( $local );
$utc = get_gmt_from_date( $local );
} else {
$utc = date( 'Y-m-d H:i:s', $date );
$utc = date( 'Y-m-d H:i:s', $date );
$local = get_date_from_gmt( $utc );
}
@ -1011,7 +1025,7 @@ function rest_is_ip_address( $ip ) {
*/
function rest_sanitize_boolean( $value ) {
// String values are translated to `true`; make sure 'false' is false.
if ( is_string( $value ) ) {
if ( is_string( $value ) ) {
$value = strtolower( $value );
if ( in_array( $value, array( 'false', '0' ), true ) ) {
$value = false;
@ -1019,7 +1033,7 @@ function rest_sanitize_boolean( $value ) {
}
// Everything else will map nicely to boolean.
return (boolean) $value;
return (bool) $value;
}
/**
@ -1110,8 +1124,8 @@ function rest_get_avatar_sizes() {
*/
function rest_validate_value_from_schema( $value, $args, $param = '' ) {
if ( 'array' === $args['type'] ) {
if ( ! is_array( $value ) ) {
$value = preg_split( '/[\s,]+/', $value );
if ( ! is_null( $value ) ) {
$value = wp_parse_list( $value );
}
if ( ! wp_is_numeric_array( $value ) ) {
/* translators: 1: parameter, 2: type name */
@ -1175,18 +1189,18 @@ function rest_validate_value_from_schema( $value, $args, $param = '' ) {
if ( isset( $args['format'] ) ) {
switch ( $args['format'] ) {
case 'date-time' :
case 'date-time':
if ( ! rest_parse_date( $value ) ) {
return new WP_Error( 'rest_invalid_date', __( 'Invalid date.' ) );
}
break;
case 'email' :
case 'email':
if ( ! is_email( $value ) ) {
return new WP_Error( 'rest_invalid_email', __( 'Invalid email address.' ) );
}
break;
case 'ip' :
case 'ip':
if ( ! rest_is_ip_address( $value ) ) {
/* translators: %s: IP address */
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) );
@ -1254,9 +1268,7 @@ function rest_sanitize_value_from_schema( $value, $args ) {
if ( empty( $args['items'] ) ) {
return (array) $value;
}
if ( ! is_array( $value ) ) {
$value = preg_split( '/[\s,]+/', $value );
}
$value = wp_parse_list( $value );
foreach ( $value as $index => $v ) {
$value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] );
}
@ -1299,19 +1311,19 @@ function rest_sanitize_value_from_schema( $value, $args ) {
if ( isset( $args['format'] ) ) {
switch ( $args['format'] ) {
case 'date-time' :
case 'date-time':
return sanitize_text_field( $value );
case 'email' :
case 'email':
/*
* sanitize_email() validates, which would be unexpected.
*/
return sanitize_text_field( $value );
case 'uri' :
case 'uri':
return esc_url_raw( $value );
case 'ip' :
case 'ip':
return sanitize_text_field( $value );
}
}