PHPCS passing abstract-wc-rest-controller.php

This commit is contained in:
Gerhard Potgieter 2018-03-05 14:52:49 +02:00
parent 7f2362aab1
commit 5dcfeac7c1
1 changed files with 50 additions and 22 deletions

View File

@ -1,4 +1,10 @@
<?php
/**
* REST Controller
*
* @class WC_REST_Controller
* @package WooCommerce/Abstracts
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
@ -7,8 +13,6 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* Abstract Rest Controller Class
*
* @author WooThemes
* @category API
* @package WooCommerce/Abstracts
* @extends WP_REST_Controller
* @version 2.6.0
@ -109,7 +113,11 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* @return array Of WP_Error or WP_REST_Response.
*/
public function batch_items( $request ) {
/** @var WP_REST_Server $wp_rest_server */
/**
* REST Server
*
* @var WP_REST_Server $wp_rest_server
*/
global $wp_rest_server;
// Get the request params.
@ -143,7 +151,11 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
if ( is_wp_error( $_response ) ) {
$response['create'][] = array(
'id' => 0,
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
'error' => array(
'code' => $_response->get_error_code(),
'message' => $_response->get_error_message(),
'data' => $_response->get_error_data(),
),
);
} else {
$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
@ -160,7 +172,11 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
if ( is_wp_error( $_response ) ) {
$response['update'][] = array(
'id' => $item['id'],
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
'error' => array(
'code' => $_response->get_error_code(),
'message' => $_response->get_error_message(),
'data' => $_response->get_error_data(),
),
);
} else {
$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
@ -177,13 +193,20 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
}
$_item = new WP_REST_Request( 'DELETE' );
$_item->set_query_params( array( 'id' => $id, 'force' => true ) );
$_item->set_query_params( array(
'id' => $id,
'force' => true,
) );
$_response = $this->delete_item( $_item );
if ( is_wp_error( $_response ) ) {
$response['delete'][] = array(
'id' => $id,
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
'error' => array(
'code' => $_response->get_error_code(),
'message' => $_response->get_error_message(),
'data' => $_response->get_error_data(),
),
);
} else {
$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
@ -198,8 +221,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate a text value for a text based setting.
*
* @since 3.0.0
* @param string $value
* @param array $setting
* @param string $value Value.
* @param array $setting Setting.
* @return string
*/
public function validate_setting_text_field( $value, $setting ) {
@ -211,8 +234,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate select based settings.
*
* @since 3.0.0
* @param string $value
* @param array $setting
* @param string $value Value.
* @param array $setting Setting.
* @return string|WP_Error
*/
public function validate_setting_select_field( $value, $setting ) {
@ -227,8 +250,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate multiselect based settings.
*
* @since 3.0.0
* @param array $values
* @param array $setting
* @param array $values Values.
* @param array $setting Setting.
* @return array|WP_Error
*/
public function validate_setting_multiselect_field( $values, $setting ) {
@ -254,8 +277,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate image_width based settings.
*
* @since 3.0.0
* @param array $values
* @param array $setting
* @param array $values Values.
* @param array $setting Setting.
* @return string|WP_Error
*/
public function validate_setting_image_width_field( $values, $setting ) {
@ -280,8 +303,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate radio based settings.
*
* @since 3.0.0
* @param string $value
* @param array $setting
* @param string $value Value.
* @param array $setting Setting.
* @return string|WP_Error
*/
public function validate_setting_radio_field( $value, $setting ) {
@ -292,8 +315,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate checkbox based settings.
*
* @since 3.0.0
* @param string $value
* @param array $setting
* @param string $value Value.
* @param array $setting Setting.
* @return string|WP_Error
*/
public function validate_setting_checkbox_field( $value, $setting ) {
@ -311,8 +334,8 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
* Validate textarea based settings.
*
* @since 3.0.0
* @param string $value
* @param array $setting
* @param string $value Value.
* @param array $setting Setting.
* @return string
*/
public function validate_setting_textarea_field( $value, $setting ) {
@ -320,7 +343,12 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
return wp_kses( trim( stripslashes( $value ) ),
array_merge(
array(
'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true ),
'iframe' => array(
'src' => true,
'style' => true,
'id' => true,
'class' => true,
),
),
wp_kses_allowed_html( 'post' )
)