Skip to content

Commit

Permalink
Updated WP-API vendor files
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed May 11, 2016
1 parent 2b1d4ec commit 5b916de
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 30 deletions.
49 changes: 30 additions & 19 deletions includes/vendor/class-wp-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

/**
* @version 2.0-beta12
* @version 2.0-beta13
*/
abstract class WP_REST_Controller {

Expand All @@ -27,7 +27,7 @@ abstract class WP_REST_Controller {
* Register the routes for the objects of the controller.
*/
public function register_routes() {
_doing_it_wrong( 'WP_REST_Controller::register_routes', 'The register_routes() method must be overriden', 'WPAPI-2.0' );
_doing_it_wrong( 'WP_REST_Controller::register_routes', __( 'The register_routes() method must be overriden', 'woocommerce' ), 'WPAPI-2.0' );
}

/**
Expand All @@ -37,7 +37,7 @@ public function register_routes() {
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -47,7 +47,7 @@ public function get_items_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -57,7 +57,7 @@ public function get_items( $request ) {
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -67,7 +67,7 @@ public function get_item_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -77,7 +77,7 @@ public function get_item( $request ) {
* @return WP_Error|boolean
*/
public function create_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -87,7 +87,7 @@ public function create_item_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function create_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -97,7 +97,7 @@ public function create_item( $request ) {
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -107,7 +107,7 @@ public function update_item_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -117,7 +117,7 @@ public function update_item( $request ) {
* @return WP_Error|boolean
*/
public function delete_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -127,7 +127,7 @@ public function delete_item_permissions_check( $request ) {
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -137,7 +137,7 @@ public function delete_item( $request ) {
* @return WP_Error|object $prepared_item
*/
protected function prepare_item_for_database( $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -148,7 +148,7 @@ protected function prepare_item_for_database( $request ) {
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $item, $request ) {
return new WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be over-ridden in subclass.", __METHOD__ ), array( 'status' => 405 ) );
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
}

/**
Expand All @@ -163,7 +163,14 @@ public function prepare_response_for_collection( $response ) {
}

$data = (array) $response->get_data();
$links = WP_REST_Server::get_response_links( $response );
$server = rest_get_server();

if ( method_exists( $server, 'get_compact_response_links' ) ) {
$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
} else {
$links = call_user_func( array( $server, 'get_response_links' ), $response );
}

if ( ! empty( $links ) ) {
$data['_links'] = $links;
}
Expand Down Expand Up @@ -243,15 +250,15 @@ public function get_collection_params() {
return array(
'context' => $this->get_context_param(),
'page' => array(
'description' => 'Current page of the collection.',
'description' => __( 'Current page of the collection.', 'woocommerce' ),
'type' => 'integer',
'default' => 1,
'sanitize_callback' => 'absint',
'validate_callback' => 'rest_validate_request_arg',
'minimum' => 1,
),
'per_page' => array(
'description' => 'Maximum number of items to be returned in result set.',
'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
'type' => 'integer',
'default' => 10,
'minimum' => 1,
Expand All @@ -260,7 +267,7 @@ public function get_collection_params() {
'validate_callback' => 'rest_validate_request_arg',
),
'search' => array(
'description' => 'Limit results to those matching a string.',
'description' => __( 'Limit results to those matching a string.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
Expand All @@ -278,7 +285,7 @@ public function get_collection_params() {
*/
public function get_context_param( $args = array() ) {
$param_details = array(
'description' => 'Scope under which the request is made; determines fields present in response.',
'description' => __( 'Scope under which the request is made; determines fields present in response.', 'woocommerce' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
Expand Down Expand Up @@ -446,6 +453,10 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE
'sanitize_callback' => 'rest_sanitize_request_arg',
);

if ( isset( $params['description'] ) ) {
$endpoint_args[ $field_id ]['description'] = $params['description'];
}

if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
$endpoint_args[ $field_id ]['default'] = $params['default'];
}
Expand Down
99 changes: 88 additions & 11 deletions includes/vendor/wp-rest-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,83 @@
exit;
}

/**
* core-integration.php
*/

if ( ! function_exists( 'wp_parse_slug_list' ) ) {
/**
* Clean up an array, comma- or space-separated list of slugs.
*
* @since
*
* @param array|string $list List of slugs.
* @return array Sanitized array of slugs.
*/
function wp_parse_slug_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', $list );
}

foreach ( $list as $key => $value ) {
$list[ $key ] = sanitize_title( $value );
}

return array_unique( $list );
}
}

if ( ! function_exists( 'rest_get_server' ) ) {
/**
* Retrieves the current REST server instance.
*
* Instantiates a new instance if none exists already.
*
* @since 4.5.0
*
* @global WP_REST_Server $wp_rest_server REST server instance.
*
* @return WP_REST_Server REST server instance.
*/
function rest_get_server() {
/* @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;

if ( empty( $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 );
}

return $wp_rest_server;
}
}

/**
* plugin.php
*/

if ( ! function_exists( 'rest_authorization_required_code' ) ) {
/**
* Returns a contextual HTTP error code for authorization failure.
Expand Down Expand Up @@ -89,16 +166,16 @@ function rest_validate_request_arg( $value, $request, $param ) {

if ( ! empty( $args['enum'] ) ) {
if ( ! in_array( $value, $args['enum'] ) ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not one of %2$s', 'woocommerce' ), $param, implode( ', ', $args['enum'] ) ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not one of %s', 'woocommerce' ), $param, implode( ', ', $args['enum'] ) ) );
}
}

if ( 'integer' === $args['type'] && ! is_numeric( $value ) ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s', 'woocommerce' ), $param, 'integer' ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not of type %s', 'woocommerce' ), $param, 'integer' ) );
}

if ( 'string' === $args['type'] && ! is_string( $value ) ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s', 'woocommerce' ), $param, 'string' ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not of type %s', 'woocommerce' ), $param, 'string' ) );
}

if ( isset( $args['format'] ) ) {
Expand All @@ -120,32 +197,32 @@ function rest_validate_request_arg( $value, $request, $param ) {
if ( in_array( $args['type'], array( 'numeric', 'integer' ) ) && ( isset( $args['minimum'] ) || isset( $args['maximum'] ) ) ) {
if ( isset( $args['minimum'] ) && ! isset( $args['maximum'] ) ) {
if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$s (exclusive)', 'woocommerce' ), $param, $args['minimum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be greater than %d (exclusive)', 'woocommerce' ), $param, $args['minimum'] ) );
} else if ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$s (inclusive)', 'woocommerce' ), $param, $args['minimum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be greater than %d (inclusive)', 'woocommerce' ), $param, $args['minimum'] ) );
}
} else if ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) {
if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$s (exclusive)', 'woocommerce' ), $param, $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be less than %d (exclusive)', 'woocommerce' ), $param, $args['maximum'] ) );
} else if ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$s (inclusive)', 'woocommerce' ), $param, $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be less than %d (inclusive)', 'woocommerce' ), $param, $args['maximum'] ) );
}
} else if ( isset( $args['maximum'] ) && isset( $args['minimum'] ) ) {
if ( ! empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) {
if ( $value >= $args['maximum'] || $value <= $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$s (exclusive) and %3$s (exclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be between %d (exclusive) and %d (exclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
}
} else if ( empty( $args['exclusiveMinimum'] ) && ! empty( $args['exclusiveMaximum'] ) ) {
if ( $value >= $args['maximum'] || $value < $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$s (inclusive) and %3$s (exclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be between %d (inclusive) and %d (exclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
}
} else if ( ! empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) {
if ( $value > $args['maximum'] || $value <= $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$s (exclusive) and %3$s (inclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be between %d (exclusive) and %d (inclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
}
} else if ( empty( $args['exclusiveMinimum'] ) && empty( $args['exclusiveMaximum'] ) ) {
if ( $value > $args['maximum'] || $value < $args['minimum'] ) {
return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be between %2$s (inclusive) and %3$s (inclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
return new WP_Error( 'rest_invalid_param', sprintf( __( '%s must be between %d (inclusive) and %d (inclusive)', 'woocommerce' ), $param, $args['minimum'], $args['maximum'] ) );
}
}
}
Expand Down

0 comments on commit 5b916de

Please sign in to comment.