2016-03-07 16:46:58 +00:00
< ? php
/**
2017-03-23 22:52:35 +00:00
* REST API Setting Options controller
2017-02-11 14:51:13 +00:00
*
2016-03-30 17:29:57 +00:00
* Handles requests to the / settings / $group / $setting endpoints .
2016-03-07 16:46:58 +00:00
*
* @ author WooThemes
* @ category API
* @ package WooCommerce / API
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-03-07 16:46:58 +00:00
*/
2017-02-11 14:51:13 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
/**
2017-03-23 22:52:35 +00:00
* REST API Setting Options controller class .
2017-02-11 14:51:13 +00:00
*
* @ package WooCommerce / API
* @ extends WC_REST_Controller
*/
2017-03-23 20:48:37 +00:00
class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
2016-03-07 16:46:58 +00:00
2016-04-04 17:34:14 +00:00
/**
* WP REST API namespace / version .
*/
2017-02-09 17:06:13 +00:00
protected $namespace = 'wc/v2' ;
2016-04-04 17:34:14 +00:00
2016-06-16 20:48:58 +00:00
/**
* Route base .
*
* @ var string
*/
2017-03-23 22:56:56 +00:00
protected $rest_base = 'settings/(?P<group_id>[\w-]+)' ;
2016-06-16 20:48:58 +00:00
2016-03-07 16:46:58 +00:00
/**
* Register routes .
2016-07-19 18:24:05 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-03-07 16:46:58 +00:00
*/
public function register_routes () {
2017-03-23 22:52:35 +00:00
register_rest_route ( $this -> namespace , '/' . $this -> rest_base , array (
2017-01-26 20:06:18 +00:00
'args' => array (
'group' => array (
'description' => __ ( 'Settings group ID.' , 'woocommerce' ),
'type' => 'string' ,
),
),
2016-06-07 01:06:02 +00:00
array (
'methods' => WP_REST_Server :: READABLE ,
'callback' => array ( $this , 'get_items' ),
2016-06-16 20:48:58 +00:00
'permission_callback' => array ( $this , 'get_items_permissions_check' ),
2016-06-07 01:06:02 +00:00
),
'schema' => array ( $this , 'get_public_item_schema' ),
) );
2017-03-23 23:45:19 +00:00
register_rest_route ( $this -> namespace , '/' . $this -> rest_base . '/batch' , array (
2017-01-26 20:06:18 +00:00
'args' => array (
'group' => array (
'description' => __ ( 'Settings group ID.' , 'woocommerce' ),
'type' => 'string' ,
),
),
2016-06-07 22:53:52 +00:00
array (
'methods' => WP_REST_Server :: EDITABLE ,
2017-03-23 23:45:19 +00:00
'callback' => array ( $this , 'batch_items' ),
2016-06-16 20:48:58 +00:00
'permission_callback' => array ( $this , 'update_items_permissions_check' ),
2016-06-07 22:53:52 +00:00
'args' => $this -> get_endpoint_args_for_item_schema ( WP_REST_Server :: EDITABLE ),
),
2017-03-23 23:45:19 +00:00
'schema' => array ( $this , 'get_public_batch_schema' ),
2016-06-07 22:53:52 +00:00
) );
2017-03-23 23:45:19 +00:00
register_rest_route ( $this -> namespace , '/' . $this -> rest_base . '/(?P<id>[\w-]+)' , array (
2017-01-26 19:22:57 +00:00
'args' => array (
2017-01-26 20:06:18 +00:00
'group' => array (
'description' => __ ( 'Settings group ID.' , 'woocommerce' ),
'type' => 'string' ,
),
2017-03-23 23:45:19 +00:00
'id' => array (
'description' => __ ( 'Unique identifier for the resource.' , 'woocommerce' ),
'type' => 'string' ,
),
),
array (
'methods' => WP_REST_Server :: READABLE ,
'callback' => array ( $this , 'get_item' ),
'permission_callback' => array ( $this , 'get_items_permissions_check' ),
2016-03-23 19:36:59 +00:00
),
2016-03-24 21:01:22 +00:00
array (
'methods' => WP_REST_Server :: EDITABLE ,
2017-03-23 23:45:19 +00:00
'callback' => array ( $this , 'update_item' ),
2016-06-16 20:48:58 +00:00
'permission_callback' => array ( $this , 'update_items_permissions_check' ),
2016-03-24 21:01:22 +00:00
'args' => $this -> get_endpoint_args_for_item_schema ( WP_REST_Server :: EDITABLE ),
),
2017-03-23 23:45:19 +00:00
'schema' => array ( $this , 'get_public_item_schema' ),
2016-03-07 20:44:07 +00:00
) );
2016-03-07 16:46:58 +00:00
}
2016-03-24 21:01:22 +00:00
/**
* Return a single setting .
2016-07-19 18:24:05 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-03-24 21:01:22 +00:00
* @ param WP_REST_Request $request
* @ return WP_Error | WP_REST_Response
*/
2016-04-04 17:34:14 +00:00
public function get_item ( $request ) {
2017-03-23 23:05:16 +00:00
$setting = $this -> get_setting ( $request [ 'group_id' ], $request [ 'id' ] );
2016-06-06 23:00:09 +00:00
2016-03-24 21:01:22 +00:00
if ( is_wp_error ( $setting ) ) {
return $setting ;
2016-03-07 20:44:07 +00:00
}
2016-06-06 23:00:09 +00:00
$response = $this -> prepare_item_for_response ( $setting , $request );
return rest_ensure_response ( $response );
2016-03-24 21:01:22 +00:00
}
2016-03-07 20:44:07 +00:00
2016-06-07 01:06:02 +00:00
/**
* Return all settings in a group .
2016-07-19 18:24:05 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-07 01:06:02 +00:00
* @ param WP_REST_Request $request
* @ return WP_Error | WP_REST_Response
*/
public function get_items ( $request ) {
2017-03-23 23:05:16 +00:00
$settings = $this -> get_group_settings ( $request [ 'group_id' ] );
2016-06-07 01:06:02 +00:00
if ( is_wp_error ( $settings ) ) {
return $settings ;
}
2016-06-07 15:22:35 +00:00
$data = array ();
foreach ( $settings as $setting_obj ) {
$setting = $this -> prepare_item_for_response ( $setting_obj , $request );
$setting = $this -> prepare_response_for_collection ( $setting );
2016-09-07 22:05:45 +00:00
if ( $this -> is_setting_type_valid ( $setting [ 'type' ] ) ) {
$data [] = $setting ;
}
2016-06-07 15:22:35 +00:00
}
return rest_ensure_response ( $data );
2016-06-07 01:06:02 +00:00
}
2016-06-07 00:50:11 +00:00
/**
* Get all settings in a group .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-07 00:50:11 +00:00
* @ param string $group_id Group ID .
* @ return array | WP_Error
*/
public function get_group_settings ( $group_id ) {
if ( empty ( $group_id ) ) {
2016-07-19 18:24:05 +00:00
return new WP_Error ( 'rest_setting_setting_group_invalid' , __ ( 'Invalid setting group.' , 'woocommerce' ), array ( 'status' => 404 ) );
2016-06-07 00:50:11 +00:00
}
$settings = apply_filters ( 'woocommerce_settings-' . $group_id , array () );
if ( empty ( $settings ) ) {
2016-07-19 18:24:05 +00:00
return new WP_Error ( 'rest_setting_setting_group_invalid' , __ ( 'Invalid setting group.' , 'woocommerce' ), array ( 'status' => 404 ) );
2016-06-07 00:50:11 +00:00
}
$filtered_settings = array ();
foreach ( $settings as $setting ) {
2016-09-07 22:05:45 +00:00
$option_key = $setting [ 'option_key' ];
$setting = $this -> filter_setting ( $setting );
2016-09-08 22:14:40 +00:00
$default = isset ( $setting [ 'default' ] ) ? $setting [ 'default' ] : '' ;
2016-09-07 22:05:45 +00:00
// Get the option value
if ( is_array ( $option_key ) ) {
$option = get_option ( $option_key [ 0 ] );
2016-09-08 22:14:40 +00:00
$setting [ 'value' ] = isset ( $option [ $option_key [ 1 ] ] ) ? $option [ $option_key [ 1 ] ] : $default ;
2016-09-07 22:05:45 +00:00
} else {
2016-09-08 22:14:40 +00:00
$admin_setting_value = WC_Admin_Settings :: get_option ( $option_key );
$setting [ 'value' ] = empty ( $admin_setting_value ) ? $default : $admin_setting_value ;
2016-06-07 00:50:11 +00:00
}
2016-09-08 22:14:40 +00:00
if ( 'multi_select_countries' === $setting [ 'type' ] ) {
$setting [ 'options' ] = WC () -> countries -> get_countries ();
$setting [ 'type' ] = 'multiselect' ;
2017-05-15 17:21:06 +00:00
} elseif ( 'single_select_country' === $setting [ 'type' ] ) {
$setting [ 'type' ] = 'select' ;
$setting [ 'options' ] = $this -> get_countries_and_states ();
2016-09-08 22:14:40 +00:00
}
2016-09-07 22:05:45 +00:00
$filtered_settings [] = $setting ;
2016-06-07 00:50:11 +00:00
}
return $filtered_settings ;
}
2017-05-15 17:21:06 +00:00
/**
* Returns a list of countries and states for use in the base location setting .
*
* @ since 3.0 . 7
* @ return array Array of states and countries .
*/
private function get_countries_and_states () {
$countries = WC () -> countries -> get_countries ();
if ( ! $countries ) {
return array ();
}
$output = array ();
foreach ( $countries as $key => $value ) {
if ( $states = WC () -> countries -> get_states ( $key ) ) {
foreach ( $states as $state_key => $state_value ) {
$output [ $key . ':' . $state_key ] = $value . ' - ' . $state_value ;
}
} else {
$output [ $key ] = $value ;
}
}
return $output ;
}
2016-03-24 21:01:22 +00:00
/**
2016-06-06 23:00:09 +00:00
* Get setting data .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-07 00:50:11 +00:00
* @ param string $group_id Group ID .
2016-06-06 23:00:09 +00:00
* @ param string $setting_id Setting ID .
* @ return stdClass | WP_Error
*/
2016-06-07 00:50:11 +00:00
public function get_setting ( $group_id , $setting_id ) {
if ( empty ( $setting_id ) ) {
2016-06-06 23:00:09 +00:00
return new WP_Error ( 'rest_setting_setting_invalid' , __ ( 'Invalid setting.' , 'woocommerce' ), array ( 'status' => 404 ) );
}
2016-06-07 00:50:11 +00:00
$settings = $this -> get_group_settings ( $group_id );
if ( is_wp_error ( $settings ) ) {
return $settings ;
}
2016-06-06 23:00:09 +00:00
$array_key = array_keys ( wp_list_pluck ( $settings , 'id' ), $setting_id );
if ( empty ( $array_key ) ) {
return new WP_Error ( 'rest_setting_setting_invalid' , __ ( 'Invalid setting.' , 'woocommerce' ), array ( 'status' => 404 ) );
}
$setting = $settings [ $array_key [ 0 ] ];
if ( ! $this -> is_setting_type_valid ( $setting [ 'type' ] ) ) {
return new WP_Error ( 'rest_setting_setting_invalid' , __ ( 'Invalid setting.' , 'woocommerce' ), array ( 'status' => 404 ) );
}
return $setting ;
}
2016-06-07 22:53:52 +00:00
/**
* Bulk create , update and delete items .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-07 22:53:52 +00:00
* @ param WP_REST_Request $request Full details about the request .
* @ return array Of WP_Error or WP_REST_Response .
*/
public function batch_items ( $request ) {
// Get the request params.
$items = array_filter ( $request -> get_params () );
/*
* Since our batch settings update is group - specific and matches based on the route ,
* we inject the URL parameters ( containing group ) into the batch items
*/
if ( ! empty ( $items [ 'update' ] ) ) {
$to_update = array ();
foreach ( $items [ 'update' ] as $item ) {
$to_update [] = array_merge ( $request -> get_url_params (), $item );
}
$request = new WP_REST_Request ( $request -> get_method () );
$request -> set_body_params ( array ( 'update' => $to_update ) );
}
return parent :: batch_items ( $request );
}
2016-06-06 23:00:09 +00:00
/**
* Update a single setting in a group .
2017-02-11 14:51:13 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-03-24 21:01:22 +00:00
* @ param WP_REST_Request $request
* @ return WP_Error | WP_REST_Response
*/
2016-04-04 19:09:32 +00:00
public function update_item ( $request ) {
2017-03-23 23:05:16 +00:00
$setting = $this -> get_setting ( $request [ 'group_id' ], $request [ 'id' ] );
2016-06-06 23:00:09 +00:00
2016-03-24 21:01:22 +00:00
if ( is_wp_error ( $setting ) ) {
return $setting ;
2016-03-07 20:44:07 +00:00
}
2016-09-08 22:14:40 +00:00
if ( is_callable ( array ( $this , 'validate_setting_' . $setting [ 'type' ] . '_field' ) ) ) {
$value = $this -> { 'validate_setting_' . $setting [ 'type' ] . '_field' }( $request [ 'value' ], $setting );
} else {
$value = $this -> validate_setting_text_field ( $request [ 'value' ], $setting );
}
if ( is_wp_error ( $value ) ) {
return $value ;
}
2016-09-07 22:05:45 +00:00
if ( is_array ( $setting [ 'option_key' ] ) ) {
2016-09-08 22:14:40 +00:00
$setting [ 'value' ] = $value ;
2016-09-07 22:05:45 +00:00
$option_key = $setting [ 'option_key' ];
$prev = get_option ( $option_key [ 0 ] );
$prev [ $option_key [ 1 ] ] = $request [ 'value' ];
update_option ( $option_key [ 0 ], $prev );
} else {
$update_data = array ();
2016-09-08 22:14:40 +00:00
$update_data [ $setting [ 'option_key' ] ] = $value ;
$setting [ 'value' ] = $value ;
2016-09-07 22:05:45 +00:00
WC_Admin_Settings :: save_fields ( array ( $setting ), $update_data );
}
2016-06-06 23:00:09 +00:00
2016-06-13 15:16:30 +00:00
$response = $this -> prepare_item_for_response ( $setting , $request );
2016-03-24 21:01:22 +00:00
2016-06-06 23:00:09 +00:00
return rest_ensure_response ( $response );
2016-03-24 21:01:22 +00:00
}
/**
2016-06-06 23:00:09 +00:00
* Prepare a single setting object for response .
2016-06-06 17:59:54 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-06 23:00:09 +00:00
* @ param object $item Setting object .
2016-06-06 17:59:54 +00:00
* @ param WP_REST_Request $request Request object .
* @ return WP_REST_Response $response Response data .
2016-03-07 18:24:03 +00:00
*/
2016-06-06 23:00:09 +00:00
public function prepare_item_for_response ( $item , $request ) {
2016-09-07 22:05:45 +00:00
unset ( $item [ 'option_key' ] );
$data = $this -> filter_setting ( $item );
$data = $this -> add_additional_fields_to_object ( $data , $request );
$data = $this -> filter_response_by_context ( $data , empty ( $request [ 'context' ] ) ? 'view' : $request [ 'context' ] );
2016-06-07 15:22:35 +00:00
$response = rest_ensure_response ( $data );
2017-03-23 23:05:16 +00:00
$response -> add_links ( $this -> prepare_links ( $data [ 'id' ], $request [ 'group_id' ] ) );
2016-06-07 15:22:35 +00:00
return $response ;
}
/**
* Prepare links for the request .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-07 15:22:35 +00:00
* @ param string $setting_id Setting ID .
* @ param string $group_id Group ID .
* @ return array Links for the given setting .
*/
protected function prepare_links ( $setting_id , $group_id ) {
2017-03-23 22:56:56 +00:00
$base = str_replace ( '(?P<group_id>[\w-]+)' , $group_id , $this -> rest_base );
2016-06-07 15:22:35 +00:00
$links = array (
'self' => array (
2017-03-23 22:52:35 +00:00
'href' => rest_url ( sprintf ( '/%s/%s/%s' , $this -> namespace , $base , $setting_id ) ),
2016-06-07 15:22:35 +00:00
),
'collection' => array (
2017-03-23 22:52:35 +00:00
'href' => rest_url ( sprintf ( '/%s/%s' , $this -> namespace , $base ) ),
2016-06-07 15:22:35 +00:00
),
);
return $links ;
2016-03-24 21:01:22 +00:00
}
2016-06-16 20:48:58 +00:00
/**
* Makes sure the current user has access to READ the settings APIs .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-16 20:48:58 +00:00
* @ param WP_REST_Request $request Full data about the request .
* @ return WP_Error | boolean
*/
public function get_items_permissions_check ( $request ) {
if ( ! wc_rest_check_manager_permissions ( 'settings' , 'read' ) ) {
return new WP_Error ( 'woocommerce_rest_cannot_view' , __ ( 'Sorry, you cannot list resources.' , 'woocommerce' ), array ( 'status' => rest_authorization_required_code () ) );
}
return true ;
}
/**
* Makes sure the current user has access to WRITE the settings APIs .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-16 20:48:58 +00:00
* @ param WP_REST_Request $request Full data about the request .
* @ return WP_Error | boolean
*/
public function update_items_permissions_check ( $request ) {
if ( ! wc_rest_check_manager_permissions ( 'settings' , 'edit' ) ) {
2016-08-08 21:52:46 +00:00
return new WP_Error ( 'woocommerce_rest_cannot_edit' , __ ( 'Sorry, you cannot edit this resource.' , 'woocommerce' ), array ( 'status' => rest_authorization_required_code () ) );
2016-06-16 20:48:58 +00:00
}
return true ;
}
/**
* Filters out bad values from the settings array / filter so we
* only return known values via the API .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-16 20:48:58 +00:00
* @ param array $setting
* @ return array
*/
public function filter_setting ( $setting ) {
$setting = array_intersect_key (
$setting ,
array_flip ( array_filter ( array_keys ( $setting ), array ( $this , 'allowed_setting_keys' ) ) )
);
if ( empty ( $setting [ 'options' ] ) ) {
unset ( $setting [ 'options' ] );
}
2016-09-08 22:14:40 +00:00
if ( 'image_width' === $setting [ 'type' ] ) {
$setting = $this -> cast_image_width ( $setting );
}
return $setting ;
}
/**
* For image_width , Crop can return " 0 " instead of false -- so we want
* to make sure we return these consistently the same we accept them .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-09-08 22:14:40 +00:00
* @ param array $setting
* @ return array
*/
public function cast_image_width ( $setting ) {
foreach ( array ( 'default' , 'value' ) as $key ) {
if ( isset ( $setting [ $key ] ) ) {
$setting [ $key ][ 'width' ] = intval ( $setting [ $key ][ 'width' ] );
$setting [ $key ][ 'height' ] = intval ( $setting [ $key ][ 'height' ] );
2016-09-09 16:39:09 +00:00
$setting [ $key ][ 'crop' ] = ( bool ) $setting [ $key ][ 'crop' ];
2016-09-08 22:14:40 +00:00
}
}
2016-06-16 20:48:58 +00:00
return $setting ;
}
/**
* Callback for allowed keys for each setting response .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-06-16 20:48:58 +00:00
* @ param string $key Key to check
* @ return boolean
*/
public function allowed_setting_keys ( $key ) {
return in_array ( $key , array (
2016-08-27 03:04:10 +00:00
'id' ,
'label' ,
'description' ,
'default' ,
'tip' ,
'placeholder' ,
'type' ,
'options' ,
'value' ,
2016-09-07 22:05:45 +00:00
'option_key' ,
2016-06-16 20:48:58 +00:00
) );
}
/**
* Boolean for if a setting type is a valid supported setting type .
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2017-02-11 14:51:13 +00:00
* @ param string $type
* @ return bool
2016-06-16 20:48:58 +00:00
*/
public function is_setting_type_valid ( $type ) {
return in_array ( $type , array (
2017-02-11 14:51:13 +00:00
'text' , // Validates with validate_setting_text_field.
'email' , // Validates with validate_setting_text_field.
'number' , // Validates with validate_setting_text_field.
'color' , // Validates with validate_setting_text_field.
'password' , // Validates with validate_setting_text_field.
'textarea' , // Validates with validate_setting_textarea_field.
'select' , // Validates with validate_setting_select_field.
'multiselect' , // Validates with validate_setting_multiselect_field.
'radio' , // Validates with validate_setting_radio_field (-> validate_setting_select_field).
'checkbox' , // Validates with validate_setting_checkbox_field.
'image_width' , // Validates with validate_setting_image_width_field.
2016-06-16 20:48:58 +00:00
) );
}
2016-03-24 21:01:22 +00:00
/**
* Get the settings schema , conforming to JSON Schema .
2016-06-06 17:59:54 +00:00
*
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-03-24 21:01:22 +00:00
* @ return array
*/
2016-06-06 17:59:54 +00:00
public function get_item_schema () {
2016-03-24 21:01:22 +00:00
$schema = array (
'$schema' => 'http://json-schema.org/draft-04/schema#' ,
2016-09-07 22:05:45 +00:00
'title' => 'setting' ,
2016-03-24 21:01:22 +00:00
'type' => 'object' ,
'properties' => array (
'id' => array (
'description' => __ ( 'A unique identifier for the setting.' , 'woocommerce' ),
'type' => 'string' ,
'arg_options' => array (
'sanitize_callback' => 'sanitize_title' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
'label' => array (
2017-03-22 13:51:52 +00:00
'description' => __ ( 'A human readable label for the setting used in interfaces.' , 'woocommerce' ),
2016-03-24 21:01:22 +00:00
'type' => 'string' ,
'arg_options' => array (
'sanitize_callback' => 'sanitize_text_field' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
'description' => array (
2017-03-22 13:51:52 +00:00
'description' => __ ( 'A human readable description for the setting used in interfaces.' , 'woocommerce' ),
2016-03-23 19:36:59 +00:00
'type' => 'string' ,
2016-03-24 21:01:22 +00:00
'arg_options' => array (
'sanitize_callback' => 'sanitize_text_field' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
2016-08-29 17:19:28 +00:00
'value' => array (
'description' => __ ( 'Setting value.' , 'woocommerce' ),
'type' => 'mixed' ,
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
2016-08-29 17:19:28 +00:00
),
2016-03-24 21:01:22 +00:00
'default' => array (
'description' => __ ( 'Default value for the setting.' , 'woocommerce' ),
'type' => 'mixed' ,
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
'tip' => array (
2017-03-22 13:51:52 +00:00
'description' => __ ( 'Additional help text shown to the user about the setting.' , 'woocommerce' ),
2016-03-24 21:01:22 +00:00
'type' => 'string' ,
'arg_options' => array (
'sanitize_callback' => 'sanitize_text_field' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
'placeholder' => array (
'description' => __ ( 'Placeholder text to be displayed in text inputs.' , 'woocommerce' ),
'type' => 'string' ,
'arg_options' => array (
2016-03-23 19:36:59 +00:00
'sanitize_callback' => 'sanitize_text_field' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-23 19:36:59 +00:00
),
2016-03-24 21:01:22 +00:00
'type' => array (
2017-03-21 20:47:28 +00:00
'description' => __ ( 'Type of setting.' , 'woocommerce' ),
2016-03-24 21:01:22 +00:00
'type' => 'string' ,
'arg_options' => array (
'sanitize_callback' => 'sanitize_text_field' ,
),
2016-08-31 21:16:52 +00:00
'context' => array ( 'view' , 'edit' ),
2017-03-21 20:47:28 +00:00
'enum' => array ( 'text' , 'email' , 'number' , 'color' , 'password' , 'textarea' , 'select' , 'multiselect' , 'radio' , 'image_width' , 'checkbox' ),
2016-08-31 21:16:52 +00:00
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
'options' => array (
2017-01-26 20:33:39 +00:00
'description' => __ ( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.' , 'woocommerce' ),
2017-01-26 20:58:55 +00:00
'type' => 'object' ,
2017-01-26 20:33:39 +00:00
'context' => array ( 'view' , 'edit' ),
'readonly' => true ,
2016-03-24 21:01:22 +00:00
),
2016-03-07 20:44:07 +00:00
),
);
return $this -> add_additional_fields_schema ( $schema );
2016-03-07 18:24:03 +00:00
}
2016-03-07 16:46:58 +00:00
}