2016-07-21 16:26:02 +00:00
< ? php
/**
* REST API WC System Status controller
*
2016-07-27 21:06:14 +00:00
* Handles requests to the / system_status endpoint .
2016-07-21 16:26:02 +00:00
*
* @ author WooThemes
* @ category API
* @ package WooCommerce / API
2017-03-15 16:36:53 +00:00
* @ since 3.0 . 0
2016-07-21 16:26:02 +00:00
*/
if ( ! defined ( 'ABSPATH' ) ) {
exit ;
}
/**
* @ package WooCommerce / API
* @ extends WC_REST_Controller
*/
class WC_REST_System_Status_Controller extends WC_REST_Controller {
/**
* Endpoint namespace .
*
* @ var string
*/
2017-02-09 17:06:13 +00:00
protected $namespace = 'wc/v2' ;
2016-07-21 16:26:02 +00:00
/**
* Route base .
*
* @ var string
*/
2016-07-27 21:06:14 +00:00
protected $rest_base = 'system_status' ;
2016-07-21 16:26:02 +00:00
/**
2016-08-09 17:14:47 +00:00
* Register the route for / system_status
2016-07-21 16:26:02 +00:00
*/
public function register_routes () {
2016-12-07 11:36:46 +00:00
register_rest_route ( $this -> namespace , '/' . $this -> rest_base , array (
2016-07-21 16:26:02 +00:00
array (
'methods' => WP_REST_Server :: READABLE ,
'callback' => array ( $this , 'get_items' ),
2016-12-07 11:36:46 +00:00
'permission_callback' => array ( $this , 'get_items_permissions_check' ),
2016-07-21 16:26:02 +00:00
'args' => $this -> get_collection_params (),
),
'schema' => array ( $this , 'get_public_item_schema' ),
) );
}
2016-12-07 11:36:46 +00:00
/**
2016-07-27 20:59:16 +00:00
* Check whether a given request has permission to view system status .
2016-07-21 16:26:02 +00:00
*
* @ param WP_REST_Request $request Full details about the request .
* @ return WP_Error | boolean
*/
public function get_items_permissions_check ( $request ) {
2016-12-07 11:36:46 +00:00
if ( ! wc_rest_check_manager_permissions ( 'system_status' , 'read' ) ) {
return new WP_Error ( 'woocommerce_rest_cannot_view' , __ ( 'Sorry, you cannot list resources.' , 'woocommerce' ), array ( 'status' => rest_authorization_required_code () ) );
2016-07-21 16:26:02 +00:00
}
return true ;
}
2016-12-07 11:36:46 +00:00
/**
2016-07-21 16:26:02 +00:00
* Get a system status info , by section .
*
* @ param WP_REST_Request $request Full details about the request .
* @ return WP_Error | WP_REST_Response
*/
public function get_items ( $request ) {
$schema = $this -> get_item_schema ();
$mappings = $this -> get_item_mappings ();
$response = array ();
foreach ( $mappings as $section => $values ) {
2016-07-27 20:59:16 +00:00
foreach ( $values as $key => $value ) {
2016-07-21 16:26:02 +00:00
if ( isset ( $schema [ 'properties' ][ $section ][ 'properties' ][ $key ][ 'type' ] ) ) {
settype ( $values [ $key ], $schema [ 'properties' ][ $section ][ 'properties' ][ $key ][ 'type' ] );
}
}
2016-12-07 11:36:46 +00:00
settype ( $values , $schema [ 'properties' ][ $section ][ 'type' ] );
2016-07-21 16:26:02 +00:00
$response [ $section ] = $values ;
}
2017-01-10 06:06:09 +00:00
$response = $this -> prepare_item_for_response ( $response , $request );
2016-07-21 16:26:02 +00:00
return rest_ensure_response ( $response );
}
2016-12-07 11:36:46 +00:00
/**
2016-07-21 16:26:02 +00:00
* Get the system status schema , conforming to JSON Schema .
*
* @ return array
*/
public function get_item_schema () {
$schema = array (
'$schema' => 'http://json-schema.org/draft-04/schema#' ,
2016-07-27 21:06:14 +00:00
'title' => 'system_status' ,
2016-07-21 16:26:02 +00:00
'type' => 'object' ,
'properties' => array (
'environment' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Environment.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'object' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
'properties' => array (
'home_url' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Home URL.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2016-12-07 11:36:46 +00:00
'format' => 'uri' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'site_url' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Site URL.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
'format' => 'uri' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wc_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WooCommerce version.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'log_directory' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Log directory.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'log_directory_writable' => array (
'description' => __ ( 'Is log directory writable?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wp_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WordPress version.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wp_multisite' => array (
'description' => __ ( 'Is WordPress multisite?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wp_memory_limit' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WordPress memory limit.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wp_debug_mode' => array (
'description' => __ ( 'Is WordPress debug mode active?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'wp_cron' => array (
'description' => __ ( 'Are WordPress cron jobs enabled?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'language' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WordPress language.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'server_info' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Server info.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'php_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'PHP version.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'php_post_max_size' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'PHP post max size.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'php_max_execution_time' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'PHP max execution time.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'php_max_input_vars' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'PHP max input vars.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
'curl_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'cURL version.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-12-07 11:36:46 +00:00
),
2016-07-21 16:26:02 +00:00
'suhosin_installed' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is SUHOSIN installed?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'max_upload_size' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Max upload size.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'mysql_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'MySQL version.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'default_timezone' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Default timezone.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'fsockopen_or_curl_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is fsockopen/cURL enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'soapclient_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is SoapClient class enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'domdocument_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is DomDocument class enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'gzip_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is GZip enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'mbstring_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Is mbstring enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'remote_post_successful' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Remote POST successful?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'remote_post_response' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Remote POST response.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'remote_get_successful' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Remote GET successful?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'remote_get_response' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Remote GET response.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
),
),
'database' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Database.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'object' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
'properties' => array (
'wc_database_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WC database version.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'database_prefix' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Database prefix.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'maxmind_geoip_database' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'MaxMind GeoIP database.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'database_tables' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Database tables.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'array' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2017-01-26 19:22:57 +00:00
'items' => array (
'type' => 'string' ,
),
2016-07-21 16:26:02 +00:00
),
2016-08-27 01:46:45 +00:00
),
2016-07-21 16:26:02 +00:00
),
'active_plugins' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Active plugins.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'array' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2017-01-26 19:22:57 +00:00
'items' => array (
'type' => 'string' ,
),
2016-07-21 16:26:02 +00:00
),
'theme' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Theme.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'object' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
'properties' => array (
'name' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Theme name.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Theme version.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
2016-08-03 17:44:20 +00:00
'version_latest' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Latest version of theme.' , 'woocommerce' ),
2016-08-03 17:44:20 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-08-03 17:44:20 +00:00
),
2016-07-21 16:26:02 +00:00
'author_url' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Theme author URL.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
'format' => 'uri' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'is_child_theme' => array (
2016-07-27 20:59:16 +00:00
'description' => __ ( 'Is this theme a child theme?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'has_woocommerce_support' => array (
2016-07-27 20:59:16 +00:00
'description' => __ ( 'Does the theme declare WooCommerce support?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
2016-08-03 17:44:20 +00:00
'has_woocommerce_file' => array (
'description' => __ ( 'Does the theme have a woocommerce.php file?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-08-03 17:44:20 +00:00
),
'has_outdated_templates' => array (
'description' => __ ( 'Does this theme have outdated templates?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-08-03 17:44:20 +00:00
),
2016-07-21 16:26:02 +00:00
'overrides' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Template overrides.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'array' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2017-01-26 19:22:57 +00:00
'items' => array (
'type' => 'string' ,
),
2016-07-21 16:26:02 +00:00
),
'parent_name' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Parent theme name.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'parent_version' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Parent theme version.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'parent_author_url' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Parent theme author URL.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
'format' => 'uri' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
2016-08-27 01:46:45 +00:00
),
2016-07-21 16:26:02 +00:00
),
'settings' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Settings.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'object' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
'properties' => array (
'api_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'REST API enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'force_ssl' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'SSL forced?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'currency' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Currency.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'currency_symbol' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Currency symbol.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'currency_position' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Currency position.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'thousand_separator' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Thousand separator.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'decimal_separator' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Decimal separator.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'string' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'number_of_decimals' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Number of decimals.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'integer' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'geolocation_enabled' => array (
2016-10-12 10:16:30 +00:00
'description' => __ ( 'Geolocation enabled?' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-07-21 16:26:02 +00:00
),
'taxonomies' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Taxonomy terms for product/order statuses.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'array' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2017-01-26 19:22:57 +00:00
'items' => array (
'type' => 'string' ,
),
2016-07-21 16:26:02 +00:00
),
2017-04-10 14:51:14 +00:00
'product_visibility_terms' => array (
'description' => __ ( 'Terms in the product visibility taxonomy.' , 'woocommerce' ),
'type' => 'array' ,
'context' => array ( 'view' ),
'readonly' => true ,
'items' => array (
'type' => 'string' ,
),
),
2016-08-27 01:46:45 +00:00
),
2016-07-21 16:26:02 +00:00
),
2016-11-10 00:19:12 +00:00
'security' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'Security.' , 'woocommerce' ),
2016-12-07 11:36:46 +00:00
'type' => 'object' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-11-10 00:19:12 +00:00
'properties' => array (
'secure_connection' => array (
'description' => __ ( 'Is the connection to your store secure?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-11-10 00:19:12 +00:00
),
'hide_errors' => array (
'description' => __ ( 'Hide errors from visitors?' , 'woocommerce' ),
'type' => 'boolean' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2016-11-10 00:19:12 +00:00
),
),
),
2016-07-27 20:59:16 +00:00
'pages' => array (
2017-03-24 03:48:41 +00:00
'description' => __ ( 'WooCommerce pages.' , 'woocommerce' ),
2016-07-21 16:26:02 +00:00
'type' => 'array' ,
2017-03-24 03:43:46 +00:00
'context' => array ( 'view' ),
2017-03-24 03:41:39 +00:00
'readonly' => true ,
2017-01-26 19:22:57 +00:00
'items' => array (
'type' => 'string' ,
),
2016-07-21 16:26:02 +00:00
),
2016-08-27 01:46:45 +00:00
),
2016-07-21 16:26:02 +00:00
);
return $this -> add_additional_fields_schema ( $schema );
}
2016-12-07 11:36:46 +00:00
/**
2016-07-27 20:59:16 +00:00
* Return an array of sections and the data associated with each .
2016-07-21 16:26:02 +00:00
*
* @ return array
*/
public function get_item_mappings () {
return array (
'environment' => $this -> get_environment_info (),
'database' => $this -> get_database_info (),
'active_plugins' => $this -> get_active_plugins (),
'theme' => $this -> get_theme_info (),
'settings' => $this -> get_settings (),
2016-11-10 00:19:12 +00:00
'security' => $this -> get_security_info (),
2016-07-27 20:59:16 +00:00
'pages' => $this -> get_pages (),
2016-07-21 16:26:02 +00:00
);
}
/**
* Get array of environment information . Includes thing like software
* versions , and various server settings .
*
* @ return array
*/
public function get_environment_info () {
global $wpdb ;
// Figure out cURL version, if installed.
$curl_version = '' ;
if ( function_exists ( 'curl_version' ) ) {
2016-12-07 11:36:46 +00:00
$curl_version = curl_version ();
$curl_version = $curl_version [ 'version' ] . ', ' . $curl_version [ 'ssl_version' ];
}
2016-07-21 16:26:02 +00:00
// WP memory limit
2016-12-07 11:36:46 +00:00
$wp_memory_limit = wc_let_to_num ( WP_MEMORY_LIMIT );
if ( function_exists ( 'memory_get_usage' ) ) {
$wp_memory_limit = max ( $wp_memory_limit , wc_let_to_num ( @ ini_get ( 'memory_limit' ) ) );
}
2016-07-21 16:26:02 +00:00
// Test POST requests
$post_response = wp_safe_remote_post ( 'https://www.paypal.com/cgi-bin/webscr' , array (
2017-04-20 14:45:52 +00:00
'timeout' => 10 ,
2016-07-21 16:26:02 +00:00
'user-agent' => 'WooCommerce/' . WC () -> version ,
'httpversion' => '1.1' ,
'body' => array (
2016-08-27 01:46:45 +00:00
'cmd' => '_notify-validate' ,
),
2016-07-21 16:26:02 +00:00
) );
$post_response_successful = false ;
if ( ! is_wp_error ( $post_response ) && $post_response [ 'response' ][ 'code' ] >= 200 && $post_response [ 'response' ][ 'code' ] < 300 ) {
$post_response_successful = true ;
}
// Test GET requests
$get_response = wp_safe_remote_get ( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite () ? '1' : '0' ) );
$get_response_successful = false ;
if ( ! is_wp_error ( $post_response ) && $post_response [ 'response' ][ 'code' ] >= 200 && $post_response [ 'response' ][ 'code' ] < 300 ) {
$get_response_successful = true ;
}
// Return all environment info. Described by JSON Schema.
return array (
2016-12-07 11:36:46 +00:00
'home_url' => get_option ( 'home' ),
'site_url' => get_option ( 'siteurl' ),
'version' => WC () -> version ,
'log_directory' => WC_LOG_DIR ,
'log_directory_writable' => ( @ fopen ( WC_LOG_DIR . 'test-log.log' , 'a' ) ? true : false ),
'wp_version' => get_bloginfo ( 'version' ),
'wp_multisite' => is_multisite (),
'wp_memory_limit' => $wp_memory_limit ,
'wp_debug_mode' => ( defined ( 'WP_DEBUG' ) && WP_DEBUG ),
'wp_cron' => ! ( defined ( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
'language' => get_locale (),
'server_info' => $_SERVER [ 'SERVER_SOFTWARE' ],
'php_version' => phpversion (),
'php_post_max_size' => wc_let_to_num ( ini_get ( 'post_max_size' ) ),
'php_max_execution_time' => ini_get ( 'max_execution_time' ),
'php_max_input_vars' => ini_get ( 'max_input_vars' ),
'curl_version' => $curl_version ,
2016-07-21 16:26:02 +00:00
'suhosin_installed' => extension_loaded ( 'suhosin' ),
'max_upload_size' => wp_max_upload_size (),
'mysql_version' => ( ! empty ( $wpdb -> is_mysql ) ? $wpdb -> db_version () : '' ),
'default_timezone' => date_default_timezone_get (),
'fsockopen_or_curl_enabled' => ( function_exists ( 'fsockopen' ) || function_exists ( 'curl_init' ) ),
'soapclient_enabled' => class_exists ( 'SoapClient' ),
'domdocument_enabled' => class_exists ( 'DOMDocument' ),
'gzip_enabled' => is_callable ( 'gzopen' ),
'mbstring_enabled' => extension_loaded ( 'mbstring' ),
'remote_post_successful' => $post_response_successful ,
'remote_post_response' => ( is_wp_error ( $post_response ) ? $post_response -> get_error_message () : $post_response [ 'response' ][ 'code' ] ),
'remote_get_successful' => $get_response_successful ,
'remote_get_response' => ( is_wp_error ( $get_response ) ? $get_response -> get_error_message () : $get_response [ 'response' ][ 'code' ] ),
2016-12-07 11:36:46 +00:00
);
2016-07-21 16:26:02 +00:00
}
/**
* Get array of database information . Version , prefix , and table existence .
*
* @ return array
*/
public function get_database_info () {
global $wpdb ;
// WC Core tables to check existence of
2016-08-23 09:16:38 +00:00
$tables = apply_filters ( 'woocommerce_database_tables' , array (
2016-07-21 16:26:02 +00:00
'woocommerce_sessions' ,
'woocommerce_api_keys' ,
'woocommerce_attribute_taxonomies' ,
'woocommerce_downloadable_product_permissions' ,
'woocommerce_order_items' ,
'woocommerce_order_itemmeta' ,
'woocommerce_tax_rates' ,
'woocommerce_tax_rate_locations' ,
'woocommerce_shipping_zones' ,
'woocommerce_shipping_zone_locations' ,
'woocommerce_shipping_zone_methods' ,
'woocommerce_payment_tokens' ,
'woocommerce_payment_tokenmeta' ,
2016-08-23 09:16:38 +00:00
) );
2016-07-21 16:26:02 +00:00
if ( get_option ( 'db_version' ) < 34370 ) {
$tables [] = 'woocommerce_termmeta' ;
}
$table_exists = array ();
foreach ( $tables as $table ) {
$table_exists [ $table ] = ( $wpdb -> get_var ( $wpdb -> prepare ( " SHOW TABLES LIKE %s; " , $wpdb -> prefix . $table ) ) === $wpdb -> prefix . $table );
}
// Return all database info. Described by JSON Schema.
return array (
'wc_database_version' => get_option ( 'woocommerce_db_version' ),
'database_prefix' => $wpdb -> prefix ,
'maxmind_geoip_database' => WC_Geolocation :: get_local_database_path (),
'database_tables' => $table_exists ,
);
}
/**
* Get a list of plugins active on the site .
*
* @ return array
*/
public function get_active_plugins () {
require_once ( ABSPATH . 'wp-admin/includes/plugin.php' );
// Get both site plugins and network plugins
$active_plugins = ( array ) get_option ( 'active_plugins' , array () );
if ( is_multisite () ) {
$network_activated_plugins = array_keys ( get_site_option ( 'active_sitewide_plugins' , array () ) );
$active_plugins = array_merge ( $active_plugins , $network_activated_plugins );
}
$active_plugins_data = array ();
2017-05-02 22:04:26 +00:00
$available_updates = get_plugin_updates ();
2016-07-21 16:26:02 +00:00
foreach ( $active_plugins as $plugin ) {
2016-12-22 14:29:54 +00:00
$data = get_plugin_data ( WP_PLUGIN_DIR . '/' . $plugin );
$dirname = dirname ( $plugin );
$version_latest = '' ;
$slug = explode ( '/' , $plugin );
$slug = explode ( '.' , end ( $slug ) );
$slug = $slug [ 0 ];
if ( 'woocommerce' !== $slug && ( strstr ( $data [ 'PluginURI' ], 'woothemes.com' ) || strstr ( $data [ 'PluginURI' ], 'woocommerce.com' ) ) ) {
2016-08-03 17:44:20 +00:00
if ( false === ( $version_data = get_transient ( md5 ( $plugin ) . '_version_data' ) ) ) {
$changelog = wp_safe_remote_get ( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' );
$cl_lines = explode ( " \n " , wp_remote_retrieve_body ( $changelog ) );
if ( ! empty ( $cl_lines ) ) {
foreach ( $cl_lines as $line_num => $cl_line ) {
if ( preg_match ( '/^[0-9]/' , $cl_line ) ) {
$date = str_replace ( '.' , '-' , trim ( substr ( $cl_line , 0 , strpos ( $cl_line , '-' ) ) ) );
$version = preg_replace ( '~[^0-9,.]~' , '' , stristr ( $cl_line , " version " ) );
$update = trim ( str_replace ( " * " , " " , $cl_lines [ $line_num + 1 ] ) );
$version_data = array ( 'date' => $date , 'version' => $version , 'update' => $update , 'changelog' => $changelog );
set_transient ( md5 ( $plugin ) . '_version_data' , $version_data , DAY_IN_SECONDS );
break ;
}
}
}
}
2016-12-22 14:29:54 +00:00
$version_latest = $version_data [ 'version' ];
2017-05-02 22:04:26 +00:00
} elseif ( isset ( $available_updates [ $plugin ] -> update -> new_version ) ) {
$version_latest = $available_updates [ $plugin ] -> update -> new_version ;
2016-08-03 17:44:20 +00:00
}
2016-07-21 16:26:02 +00:00
// convert plugin data to json response format.
$active_plugins_data [] = array (
2016-08-03 17:44:20 +00:00
'plugin' => $plugin ,
'name' => $data [ 'Name' ],
'version' => $data [ 'Version' ],
2016-12-22 14:29:54 +00:00
'version_latest' => $version_latest ,
2016-08-03 17:44:20 +00:00
'url' => $data [ 'PluginURI' ],
'author_name' => $data [ 'AuthorName' ],
'author_url' => esc_url_raw ( $data [ 'AuthorURI' ] ),
'network_activated' => $data [ 'Network' ],
2016-07-21 16:26:02 +00:00
);
}
return $active_plugins_data ;
}
/**
* Get info on the current active theme , info on parent theme ( if presnet )
* and a list of template overrides .
*
* @ return array
*/
public function get_theme_info () {
$active_theme = wp_get_theme ();
// Get parent theme info if this theme is a child theme, otherwise
// pass empty info in the response.
2016-07-27 20:59:16 +00:00
if ( is_child_theme () ) {
2016-07-21 16:26:02 +00:00
$parent_theme = wp_get_theme ( $active_theme -> Template );
$parent_theme_info = array (
2016-08-03 17:44:20 +00:00
'parent_name' => $parent_theme -> Name ,
'parent_version' => $parent_theme -> Version ,
'parent_version_latest' => WC_Admin_Status :: get_latest_theme_version ( $parent_theme ),
'parent_author_url' => $parent_theme -> { 'Author URI' },
2016-07-21 16:26:02 +00:00
);
} else {
2016-08-03 17:44:20 +00:00
$parent_theme_info = array ( 'parent_name' => '' , 'parent_version' => '' , 'parent_version_latest' => '' , 'parent_author_url' => '' );
2016-07-21 16:26:02 +00:00
}
/**
* Scan the theme directory for all WC templates to see if our theme
* overrides any of them .
*/
2016-08-03 17:44:20 +00:00
$override_files = array ();
$outdated_templates = false ;
$scan_files = WC_Admin_Status :: scan_template_files ( WC () -> plugin_path () . '/templates/' );
2016-07-21 16:26:02 +00:00
foreach ( $scan_files as $file ) {
if ( file_exists ( get_stylesheet_directory () . '/' . $file ) ) {
$theme_file = get_stylesheet_directory () . '/' . $file ;
2016-08-26 10:02:57 +00:00
} elseif ( file_exists ( get_stylesheet_directory () . '/' . WC () -> template_path () . $file ) ) {
$theme_file = get_stylesheet_directory () . '/' . WC () -> template_path () . $file ;
2016-07-21 16:26:02 +00:00
} elseif ( file_exists ( get_template_directory () . '/' . $file ) ) {
$theme_file = get_template_directory () . '/' . $file ;
2016-08-26 10:02:57 +00:00
} elseif ( file_exists ( get_template_directory () . '/' . WC () -> template_path () . $file ) ) {
$theme_file = get_template_directory () . '/' . WC () -> template_path () . $file ;
2016-07-21 16:26:02 +00:00
} else {
$theme_file = false ;
}
if ( ! empty ( $theme_file ) ) {
2016-08-03 17:44:20 +00:00
$core_version = WC_Admin_Status :: get_file_version ( WC () -> plugin_path () . '/templates/' . $file );
$theme_version = WC_Admin_Status :: get_file_version ( $theme_file );
if ( $core_version && ( empty ( $theme_version ) || version_compare ( $theme_version , $core_version , '<' ) ) ) {
if ( ! $outdated_templates ) {
$outdated_templates = true ;
}
}
2016-08-27 06:14:06 +00:00
$override_files [] = array (
2016-08-03 17:44:20 +00:00
'file' => str_replace ( WP_CONTENT_DIR . '/themes/' , '' , $theme_file ),
'version' => $theme_version ,
'core_version' => $core_version ,
);
2016-07-21 16:26:02 +00:00
}
}
$active_theme_info = array (
'name' => $active_theme -> Name ,
'version' => $active_theme -> Version ,
2016-08-03 17:44:20 +00:00
'version_latest' => WC_Admin_Status :: get_latest_theme_version ( $active_theme ),
2016-07-21 16:26:02 +00:00
'author_url' => esc_url_raw ( $active_theme -> { 'Author URI' } ),
'is_child_theme' => is_child_theme (),
'has_woocommerce_support' => ( current_theme_supports ( 'woocommerce' ) || in_array ( $active_theme -> template , wc_get_core_supported_themes () ) ),
2016-08-03 17:44:20 +00:00
'has_woocommerce_file' => ( file_exists ( get_stylesheet_directory () . '/woocommerce.php' ) || file_exists ( get_template_directory () . '/woocommerce.php' ) ),
'has_outdated_templates' => $outdated_templates ,
2016-07-21 16:26:02 +00:00
'overrides' => $override_files ,
);
return array_merge ( $active_theme_info , $parent_theme_info );
}
/**
* Get some setting values for the site that are useful for debugging
* purposes . For full settings access , use the settings api .
*
* @ return array
*/
public function get_settings () {
// Get a list of terms used for product/order taxonomies
$term_response = array ();
$terms = get_terms ( 'product_type' , array ( 'hide_empty' => 0 ) );
foreach ( $terms as $term ) {
$term_response [ $term -> slug ] = strtolower ( $term -> name );
}
2017-04-10 14:51:14 +00:00
// Get a list of terms used for product visibility.
$product_visibility_terms = array ();
$terms = get_terms ( 'product_visibility' , array ( 'hide_empty' => 0 ) );
foreach ( $terms as $term ) {
$product_visibility_terms [ $term -> slug ] = strtolower ( $term -> name );
}
2016-07-21 16:26:02 +00:00
// Return array of useful settings for debugging.
return array (
2017-04-10 14:51:14 +00:00
'api_enabled' => 'yes' === get_option ( 'woocommerce_api_enabled' ),
'force_ssl' => 'yes' === get_option ( 'woocommerce_force_ssl_checkout' ),
'currency' => get_woocommerce_currency (),
'currency_symbol' => get_woocommerce_currency_symbol (),
'currency_position' => get_option ( 'woocommerce_currency_pos' ),
'thousand_separator' => wc_get_price_thousand_separator (),
'decimal_separator' => wc_get_price_decimal_separator (),
'number_of_decimals' => wc_get_price_decimals (),
'geolocation_enabled' => in_array ( get_option ( 'woocommerce_default_customer_address' ), array ( 'geolocation_ajax' , 'geolocation' ) ),
'taxonomies' => $term_response ,
'product_visibility_terms' => $product_visibility_terms ,
2016-07-21 16:26:02 +00:00
);
}
2016-11-10 00:19:12 +00:00
/**
* Returns security tips .
*
* @ return array
*/
public function get_security_info () {
2017-04-05 17:23:50 +00:00
$check_page = 0 < wc_get_page_id ( 'shop' ) ? get_permalink ( wc_get_page_id ( 'shop' ) ) : get_home_url ();
2016-11-10 00:19:12 +00:00
return array (
2017-04-05 09:03:41 +00:00
'secure_connection' => 'https' === substr ( $check_page , 0 , 5 ),
2016-11-10 00:19:12 +00:00
'hide_errors' => ! ( defined ( 'WP_DEBUG' ) && defined ( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval ( ini_get ( 'display_errors' ) ),
);
}
2016-07-21 16:26:02 +00:00
/**
* Returns a mini - report on WC pages and if they are configured correctly :
* Present , visible , and including the correct shortcode .
*
* @ return array
*/
2016-07-27 20:59:16 +00:00
public function get_pages () {
2016-07-21 16:26:02 +00:00
// WC pages to check against
$check_pages = array (
2016-10-12 10:16:30 +00:00
_x ( 'Shop base' , 'Page setting' , 'woocommerce' ) => array (
2016-07-21 16:26:02 +00:00
'option' => 'woocommerce_shop_page_id' ,
'shortcode' => '' ,
),
_x ( 'Cart' , 'Page setting' , 'woocommerce' ) => array (
'option' => 'woocommerce_cart_page_id' ,
'shortcode' => '[' . apply_filters ( 'woocommerce_cart_shortcode_tag' , 'woocommerce_cart' ) . ']' ,
),
_x ( 'Checkout' , 'Page setting' , 'woocommerce' ) => array (
'option' => 'woocommerce_checkout_page_id' ,
'shortcode' => '[' . apply_filters ( 'woocommerce_checkout_shortcode_tag' , 'woocommerce_checkout' ) . ']' ,
),
2016-10-12 10:16:30 +00:00
_x ( 'My account' , 'Page setting' , 'woocommerce' ) => array (
2016-07-21 16:26:02 +00:00
'option' => 'woocommerce_myaccount_page_id' ,
'shortcode' => '[' . apply_filters ( 'woocommerce_my_account_shortcode_tag' , 'woocommerce_my_account' ) . ']' ,
),
);
$pages_output = array ();
foreach ( $check_pages as $page_name => $values ) {
$errors = array ();
$page_id = get_option ( $values [ 'option' ] );
$page_set = $page_exists = $page_visible = false ;
$shortcode_present = $shortcode_required = false ;
// Page checks
if ( $page_id ) {
$page_set = true ;
}
if ( get_post ( $page_id ) ) {
$page_exists = true ;
}
if ( 'publish' === get_post_status ( $page_id ) ) {
$page_visible = true ;
}
// Shortcode checks
if ( $values [ 'shortcode' ] && get_post ( $page_id ) ) {
$shortcode_required = true ;
$page = get_post ( $page_id );
if ( strstr ( $page -> post_content , $values [ 'shortcode' ] ) ) {
$shortcode_present = true ;
}
}
// Wrap up our findings into an output array
$pages_output [] = array (
2016-11-10 00:19:12 +00:00
'page_name' => $page_name ,
'page_id' => $page_id ,
'page_set' => $page_set ,
'page_exists' => $page_exists ,
'page_visible' => $page_visible ,
'shortcode' => $values [ 'shortcode' ],
'shortcode_required' => $shortcode_required ,
'shortcode_present' => $shortcode_present ,
2016-07-21 16:26:02 +00:00
);
}
return $pages_output ;
}
/**
* Get any query params needed .
*
* @ return array
*/
public function get_collection_params () {
return array (
'context' => $this -> get_context_param ( array ( 'default' => 'view' ) ),
);
}
2017-01-10 06:06:09 +00:00
/**
* Prepare the system status response
*
* @ param array $system_status
* @ param WP_REST_Request $request Request object .
* @ return WP_REST_Response $response Response data .
*/
public function prepare_item_for_response ( $system_status , $request ) {
$data = $this -> add_additional_fields_to_object ( $system_status , $request );
$data = $this -> filter_response_by_context ( $data , 'view' );
$response = rest_ensure_response ( $data );
/**
* Filter the system status returned from the REST API .
*
* @ param WP_REST_Response $response The response object .
* @ param mixed $system_status System status
* @ param WP_REST_Request $request Request object .
*/
return apply_filters ( 'woocommerce_rest_prepare_system_status' , $response , $system_status , $request );
}
2016-07-21 16:26:02 +00:00
}