WC_REST_System_Status_Controller

The WooCommerce WC REST System Status Controller class.

Defined (1)

The class is defined in the following location(s).

/includes/api/class-wc-rest-system-status-controller.php  
  1. class WC_REST_System_Status_Controller extends WC_REST_Controller { 
  2.  
  3. /** 
  4. * Endpoint namespace. 
  5. * @var string 
  6. */ 
  7. protected $namespace = 'wc/v2'; 
  8.  
  9. /** 
  10. * Route base. 
  11. * @var string 
  12. */ 
  13. protected $rest_base = 'system_status'; 
  14.  
  15. /** 
  16. * Register the route for /system_status 
  17. */ 
  18. public function register_routes() { 
  19. register_rest_route( $this->namespace, '/' . $this->rest_base, array( 
  20. array( 
  21. 'methods' => WP_REST_Server::READABLE,  
  22. 'callback' => array( $this, 'get_items' ),  
  23. 'permission_callback' => array( $this, 'get_items_permissions_check' ),  
  24. 'args' => $this->get_collection_params(),  
  25. ),  
  26. 'schema' => array( $this, 'get_public_item_schema' ),  
  27. ) ); 
  28.  
  29. /** 
  30. * Check whether a given request has permission to view system status. 
  31. * @param WP_REST_Request $request Full details about the request. 
  32. * @return WP_Error|boolean 
  33. */ 
  34. public function get_items_permissions_check( $request ) { 
  35. if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { 
  36. return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); 
  37. return true; 
  38.  
  39. /** 
  40. * Get a system status info, by section. 
  41. * @param WP_REST_Request $request Full details about the request. 
  42. * @return WP_Error|WP_REST_Response 
  43. */ 
  44. public function get_items( $request ) { 
  45. $schema = $this->get_item_schema(); 
  46. $mappings = $this->get_item_mappings(); 
  47. $response = array(); 
  48.  
  49. foreach ( $mappings as $section => $values ) { 
  50. foreach ( $values as $key => $value ) { 
  51. if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { 
  52. settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); 
  53. settype( $values, $schema['properties'][ $section ]['type'] ); 
  54. $response[ $section ] = $values; 
  55.  
  56. $response = $this->prepare_item_for_response( $response, $request ); 
  57.  
  58. return rest_ensure_response( $response ); 
  59.  
  60. /** 
  61. * Get the system status schema, conforming to JSON Schema. 
  62. * @return array 
  63. */ 
  64. public function get_item_schema() { 
  65. $schema = array( 
  66. '$schema' => 'http://json-schema.org/draft-04/schema#',  
  67. 'title' => 'system_status',  
  68. 'type' => 'object',  
  69. 'properties' => array( 
  70. 'environment' => array( 
  71. 'description' => __( 'Environment.', 'woocommerce' ),  
  72. 'type' => 'object',  
  73. 'context' => array( 'view' ),  
  74. 'readonly' => true,  
  75. 'properties' => array( 
  76. 'home_url' => array( 
  77. 'description' => __( 'Home URL.', 'woocommerce' ),  
  78. 'type' => 'string',  
  79. 'format' => 'uri',  
  80. 'context' => array( 'view' ),  
  81. 'readonly' => true,  
  82. ),  
  83. 'site_url' => array( 
  84. 'description' => __( 'Site URL.', 'woocommerce' ),  
  85. 'type' => 'string',  
  86. 'format' => 'uri',  
  87. 'context' => array( 'view' ),  
  88. 'readonly' => true,  
  89. ),  
  90. 'wc_version' => array( 
  91. 'description' => __( 'WooCommerce version.', 'woocommerce' ),  
  92. 'type' => 'string',  
  93. 'context' => array( 'view' ),  
  94. 'readonly' => true,  
  95. ),  
  96. 'log_directory' => array( 
  97. 'description' => __( 'Log directory.', 'woocommerce' ),  
  98. 'type' => 'string',  
  99. 'context' => array( 'view' ),  
  100. 'readonly' => true,  
  101. ),  
  102. 'log_directory_writable' => array( 
  103. 'description' => __( 'Is log directory writable?', 'woocommerce' ),  
  104. 'type' => 'boolean',  
  105. 'context' => array( 'view' ),  
  106. 'readonly' => true,  
  107. ),  
  108. 'wp_version' => array( 
  109. 'description' => __( 'WordPress version.', 'woocommerce' ),  
  110. 'type' => 'string',  
  111. 'context' => array( 'view' ),  
  112. 'readonly' => true,  
  113. ),  
  114. 'wp_multisite' => array( 
  115. 'description' => __( 'Is WordPress multisite?', 'woocommerce' ),  
  116. 'type' => 'boolean',  
  117. 'context' => array( 'view' ),  
  118. 'readonly' => true,  
  119. ),  
  120. 'wp_memory_limit' => array( 
  121. 'description' => __( 'WordPress memory limit.', 'woocommerce' ),  
  122. 'type' => 'integer',  
  123. 'context' => array( 'view' ),  
  124. 'readonly' => true,  
  125. ),  
  126. 'wp_debug_mode' => array( 
  127. 'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ),  
  128. 'type' => 'boolean',  
  129. 'context' => array( 'view' ),  
  130. 'readonly' => true,  
  131. ),  
  132. 'wp_cron' => array( 
  133. 'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ),  
  134. 'type' => 'boolean',  
  135. 'context' => array( 'view' ),  
  136. 'readonly' => true,  
  137. ),  
  138. 'language' => array( 
  139. 'description' => __( 'WordPress language.', 'woocommerce' ),  
  140. 'type' => 'string',  
  141. 'context' => array( 'view' ),  
  142. 'readonly' => true,  
  143. ),  
  144. 'server_info' => array( 
  145. 'description' => __( 'Server info.', 'woocommerce' ),  
  146. 'type' => 'string',  
  147. 'context' => array( 'view' ),  
  148. 'readonly' => true,  
  149. ),  
  150. 'php_version' => array( 
  151. 'description' => __( 'PHP version.', 'woocommerce' ),  
  152. 'type' => 'string',  
  153. 'context' => array( 'view' ),  
  154. 'readonly' => true,  
  155. ),  
  156. 'php_post_max_size' => array( 
  157. 'description' => __( 'PHP post max size.', 'woocommerce' ),  
  158. 'type' => 'integer',  
  159. 'context' => array( 'view' ),  
  160. 'readonly' => true,  
  161. ),  
  162. 'php_max_execution_time' => array( 
  163. 'description' => __( 'PHP max execution time.', 'woocommerce' ),  
  164. 'type' => 'integer',  
  165. 'context' => array( 'view' ),  
  166. 'readonly' => true,  
  167. ),  
  168. 'php_max_input_vars' => array( 
  169. 'description' => __( 'PHP max input vars.', 'woocommerce' ),  
  170. 'type' => 'integer',  
  171. 'context' => array( 'view' ),  
  172. 'readonly' => true,  
  173. ),  
  174. 'curl_version' => array( 
  175. 'description' => __( 'cURL version.', 'woocommerce' ),  
  176. 'type' => 'string',  
  177. 'context' => array( 'view' ),  
  178. 'readonly' => true,  
  179. ),  
  180. 'suhosin_installed' => array( 
  181. 'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ),  
  182. 'type' => 'boolean',  
  183. 'context' => array( 'view' ),  
  184. 'readonly' => true,  
  185. ),  
  186. 'max_upload_size' => array( 
  187. 'description' => __( 'Max upload size.', 'woocommerce' ),  
  188. 'type' => 'integer',  
  189. 'context' => array( 'view' ),  
  190. 'readonly' => true,  
  191. ),  
  192. 'mysql_version' => array( 
  193. 'description' => __( 'MySQL version.', 'woocommerce' ),  
  194. 'type' => 'string',  
  195. 'context' => array( 'view' ),  
  196. 'readonly' => true,  
  197. ),  
  198. 'default_timezone' => array( 
  199. 'description' => __( 'Default timezone.', 'woocommerce' ),  
  200. 'type' => 'string',  
  201. 'context' => array( 'view' ),  
  202. 'readonly' => true,  
  203. ),  
  204. 'fsockopen_or_curl_enabled' => array( 
  205. 'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ),  
  206. 'type' => 'boolean',  
  207. 'context' => array( 'view' ),  
  208. 'readonly' => true,  
  209. ),  
  210. 'soapclient_enabled' => array( 
  211. 'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ),  
  212. 'type' => 'boolean',  
  213. 'context' => array( 'view' ),  
  214. 'readonly' => true,  
  215. ),  
  216. 'domdocument_enabled' => array( 
  217. 'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ),  
  218. 'type' => 'boolean',  
  219. 'context' => array( 'view' ),  
  220. 'readonly' => true,  
  221. ),  
  222. 'gzip_enabled' => array( 
  223. 'description' => __( 'Is GZip enabled?', 'woocommerce' ),  
  224. 'type' => 'boolean',  
  225. 'context' => array( 'view' ),  
  226. 'readonly' => true,  
  227. ),  
  228. 'mbstring_enabled' => array( 
  229. 'description' => __( 'Is mbstring enabled?', 'woocommerce' ),  
  230. 'type' => 'boolean',  
  231. 'context' => array( 'view' ),  
  232. 'readonly' => true,  
  233. ),  
  234. 'remote_post_successful' => array( 
  235. 'description' => __( 'Remote POST successful?', 'woocommerce' ),  
  236. 'type' => 'boolean',  
  237. 'context' => array( 'view' ),  
  238. 'readonly' => true,  
  239. ),  
  240. 'remote_post_response' => array( 
  241. 'description' => __( 'Remote POST response.', 'woocommerce' ),  
  242. 'type' => 'string',  
  243. 'context' => array( 'view' ),  
  244. 'readonly' => true,  
  245. ),  
  246. 'remote_get_successful' => array( 
  247. 'description' => __( 'Remote GET successful?', 'woocommerce' ),  
  248. 'type' => 'boolean',  
  249. 'context' => array( 'view' ),  
  250. 'readonly' => true,  
  251. ),  
  252. 'remote_get_response' => array( 
  253. 'description' => __( 'Remote GET response.', 'woocommerce' ),  
  254. 'type' => 'string',  
  255. 'context' => array( 'view' ),  
  256. 'readonly' => true,  
  257. ),  
  258. ),  
  259. ),  
  260. 'database' => array( 
  261. 'description' => __( 'Database.', 'woocommerce' ),  
  262. 'type' => 'object',  
  263. 'context' => array( 'view' ),  
  264. 'readonly' => true,  
  265. 'properties' => array( 
  266. 'wc_database_version' => array( 
  267. 'description' => __( 'WC database version.', 'woocommerce' ),  
  268. 'type' => 'string',  
  269. 'context' => array( 'view' ),  
  270. 'readonly' => true,  
  271. ),  
  272. 'database_prefix' => array( 
  273. 'description' => __( 'Database prefix.', 'woocommerce' ),  
  274. 'type' => 'string',  
  275. 'context' => array( 'view' ),  
  276. 'readonly' => true,  
  277. ),  
  278. 'maxmind_geoip_database' => array( 
  279. 'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ),  
  280. 'type' => 'string',  
  281. 'context' => array( 'view' ),  
  282. 'readonly' => true,  
  283. ),  
  284. 'database_tables' => array( 
  285. 'description' => __( 'Database tables.', 'woocommerce' ),  
  286. 'type' => 'array',  
  287. 'context' => array( 'view' ),  
  288. 'readonly' => true,  
  289. 'items' => array( 
  290. 'type' => 'string',  
  291. ),  
  292. ),  
  293. ),  
  294. ),  
  295. 'active_plugins' => array( 
  296. 'description' => __( 'Active plugins.', 'woocommerce' ),  
  297. 'type' => 'array',  
  298. 'context' => array( 'view' ),  
  299. 'readonly' => true,  
  300. 'items' => array( 
  301. 'type' => 'string',  
  302. ),  
  303. ),  
  304. 'theme' => array( 
  305. 'description' => __( 'Theme.', 'woocommerce' ),  
  306. 'type' => 'object',  
  307. 'context' => array( 'view' ),  
  308. 'readonly' => true,  
  309. 'properties' => array( 
  310. 'name' => array( 
  311. 'description' => __( 'Theme name.', 'woocommerce' ),  
  312. 'type' => 'string',  
  313. 'context' => array( 'view' ),  
  314. 'readonly' => true,  
  315. ),  
  316. 'version' => array( 
  317. 'description' => __( 'Theme version.', 'woocommerce' ),  
  318. 'type' => 'string',  
  319. 'context' => array( 'view' ),  
  320. 'readonly' => true,  
  321. ),  
  322. 'version_latest' => array( 
  323. 'description' => __( 'Latest version of theme.', 'woocommerce' ),  
  324. 'type' => 'string',  
  325. 'context' => array( 'view' ),  
  326. 'readonly' => true,  
  327. ),  
  328. 'author_url' => array( 
  329. 'description' => __( 'Theme author URL.', 'woocommerce' ),  
  330. 'type' => 'string',  
  331. 'format' => 'uri',  
  332. 'context' => array( 'view' ),  
  333. 'readonly' => true,  
  334. ),  
  335. 'is_child_theme' => array( 
  336. 'description' => __( 'Is this theme a child theme?', 'woocommerce' ),  
  337. 'type' => 'boolean',  
  338. 'context' => array( 'view' ),  
  339. 'readonly' => true,  
  340. ),  
  341. 'has_woocommerce_support' => array( 
  342. 'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ),  
  343. 'type' => 'boolean',  
  344. 'context' => array( 'view' ),  
  345. 'readonly' => true,  
  346. ),  
  347. 'has_woocommerce_file' => array( 
  348. 'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ),  
  349. 'type' => 'boolean',  
  350. 'context' => array( 'view' ),  
  351. 'readonly' => true,  
  352. ),  
  353. 'has_outdated_templates' => array( 
  354. 'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ),  
  355. 'type' => 'boolean',  
  356. 'context' => array( 'view' ),  
  357. 'readonly' => true,  
  358. ),  
  359. 'overrides' => array( 
  360. 'description' => __( 'Template overrides.', 'woocommerce' ),  
  361. 'type' => 'array',  
  362. 'context' => array( 'view' ),  
  363. 'readonly' => true,  
  364. 'items' => array( 
  365. 'type' => 'string',  
  366. ),  
  367. ),  
  368. 'parent_name' => array( 
  369. 'description' => __( 'Parent theme name.', 'woocommerce' ),  
  370. 'type' => 'string',  
  371. 'context' => array( 'view' ),  
  372. 'readonly' => true,  
  373. ),  
  374. 'parent_version' => array( 
  375. 'description' => __( 'Parent theme version.', 'woocommerce' ),  
  376. 'type' => 'string',  
  377. 'context' => array( 'view' ),  
  378. 'readonly' => true,  
  379. ),  
  380. 'parent_author_url' => array( 
  381. 'description' => __( 'Parent theme author URL.', 'woocommerce' ),  
  382. 'type' => 'string',  
  383. 'format' => 'uri',  
  384. 'context' => array( 'view' ),  
  385. 'readonly' => true,  
  386. ),  
  387. ),  
  388. ),  
  389. 'settings' => array( 
  390. 'description' => __( 'Settings.', 'woocommerce' ),  
  391. 'type' => 'object',  
  392. 'context' => array( 'view' ),  
  393. 'readonly' => true,  
  394. 'properties' => array( 
  395. 'api_enabled' => array( 
  396. 'description' => __( 'REST API enabled?', 'woocommerce' ),  
  397. 'type' => 'boolean',  
  398. 'context' => array( 'view' ),  
  399. 'readonly' => true,  
  400. ),  
  401. 'force_ssl' => array( 
  402. 'description' => __( 'SSL forced?', 'woocommerce' ),  
  403. 'type' => 'boolean',  
  404. 'context' => array( 'view' ),  
  405. 'readonly' => true,  
  406. ),  
  407. 'currency' => array( 
  408. 'description' => __( 'Currency.', 'woocommerce' ),  
  409. 'type' => 'string',  
  410. 'context' => array( 'view' ),  
  411. 'readonly' => true,  
  412. ),  
  413. 'currency_symbol' => array( 
  414. 'description' => __( 'Currency symbol.', 'woocommerce' ),  
  415. 'type' => 'string',  
  416. 'context' => array( 'view' ),  
  417. 'readonly' => true,  
  418. ),  
  419. 'currency_position' => array( 
  420. 'description' => __( 'Currency position.', 'woocommerce' ),  
  421. 'type' => 'string',  
  422. 'context' => array( 'view' ),  
  423. 'readonly' => true,  
  424. ),  
  425. 'thousand_separator' => array( 
  426. 'description' => __( 'Thousand separator.', 'woocommerce' ),  
  427. 'type' => 'string',  
  428. 'context' => array( 'view' ),  
  429. 'readonly' => true,  
  430. ),  
  431. 'decimal_separator' => array( 
  432. 'description' => __( 'Decimal separator.', 'woocommerce' ),  
  433. 'type' => 'string',  
  434. 'context' => array( 'view' ),  
  435. 'readonly' => true,  
  436. ),  
  437. 'number_of_decimals' => array( 
  438. 'description' => __( 'Number of decimals.', 'woocommerce' ),  
  439. 'type' => 'integer',  
  440. 'context' => array( 'view' ),  
  441. 'readonly' => true,  
  442. ),  
  443. 'geolocation_enabled' => array( 
  444. 'description' => __( 'Geolocation enabled?', 'woocommerce' ),  
  445. 'type' => 'boolean',  
  446. 'context' => array( 'view' ),  
  447. 'readonly' => true,  
  448. ),  
  449. 'taxonomies' => array( 
  450. 'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ),  
  451. 'type' => 'array',  
  452. 'context' => array( 'view' ),  
  453. 'readonly' => true,  
  454. 'items' => array( 
  455. 'type' => 'string',  
  456. ),  
  457. ),  
  458. 'product_visibility_terms' => array( 
  459. 'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ),  
  460. 'type' => 'array',  
  461. 'context' => array( 'view' ),  
  462. 'readonly' => true,  
  463. 'items' => array( 
  464. 'type' => 'string',  
  465. ),  
  466. ),  
  467. ),  
  468. ),  
  469. 'security' => array( 
  470. 'description' => __( 'Security.', 'woocommerce' ),  
  471. 'type' => 'object',  
  472. 'context' => array( 'view' ),  
  473. 'readonly' => true,  
  474. 'properties' => array( 
  475. 'secure_connection' => array( 
  476. 'description' => __( 'Is the connection to your store secure?', 'woocommerce' ),  
  477. 'type' => 'boolean',  
  478. 'context' => array( 'view' ),  
  479. 'readonly' => true,  
  480. ),  
  481. 'hide_errors' => array( 
  482. 'description' => __( 'Hide errors from visitors?', 'woocommerce' ),  
  483. 'type' => 'boolean',  
  484. 'context' => array( 'view' ),  
  485. 'readonly' => true,  
  486. ),  
  487. ),  
  488. ),  
  489. 'pages' => array( 
  490. 'description' => __( 'WooCommerce pages.', 'woocommerce' ),  
  491. 'type' => 'array',  
  492. 'context' => array( 'view' ),  
  493. 'readonly' => true,  
  494. 'items' => array( 
  495. 'type' => 'string',  
  496. ),  
  497. ),  
  498. ),  
  499. ); 
  500.  
  501. return $this->add_additional_fields_schema( $schema ); 
  502.  
  503. /** 
  504. * Return an array of sections and the data associated with each. 
  505. * @return array 
  506. */ 
  507. public function get_item_mappings() { 
  508. return array( 
  509. 'environment' => $this->get_environment_info(),  
  510. 'database' => $this->get_database_info(),  
  511. 'active_plugins' => $this->get_active_plugins(),  
  512. 'theme' => $this->get_theme_info(),  
  513. 'settings' => $this->get_settings(),  
  514. 'security' => $this->get_security_info(),  
  515. 'pages' => $this->get_pages(),  
  516. ); 
  517.  
  518. /** 
  519. * Get array of environment information. Includes thing like software 
  520. * versions, and various server settings. 
  521. * @return array 
  522. */ 
  523. public function get_environment_info() { 
  524. global $wpdb; 
  525.  
  526. // Figure out cURL version, if installed. 
  527. $curl_version = ''; 
  528. if ( function_exists( 'curl_version' ) ) { 
  529. $curl_version = curl_version(); 
  530. $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; 
  531.  
  532. // WP memory limit 
  533. $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); 
  534. if ( function_exists( 'memory_get_usage' ) ) { 
  535. $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); 
  536.  
  537. // Test POST requests 
  538. $post_response = wp_safe_remote_post( 'https://www.paypal.com/cgi-bin/webscr', array( 
  539. 'timeout' => 10,  
  540. 'user-agent' => 'WooCommerce/' . WC()->version,  
  541. 'httpversion' => '1.1',  
  542. 'body' => array( 
  543. 'cmd' => '_notify-validate',  
  544. ),  
  545. ) ); 
  546. $post_response_successful = false; 
  547. if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) { 
  548. $post_response_successful = true; 
  549.  
  550. // Test GET requests 
  551. $get_response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); 
  552. $get_response_successful = false; 
  553. if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) { 
  554. $get_response_successful = true; 
  555.  
  556. // Return all environment info. Described by JSON Schema. 
  557. return array( 
  558. 'home_url' => get_option( 'home' ),  
  559. 'site_url' => get_option( 'siteurl' ),  
  560. 'version' => WC()->version,  
  561. 'log_directory' => WC_LOG_DIR,  
  562. 'log_directory_writable' => ( @fopen( WC_LOG_DIR . 'test-log.log', 'a' ) ? true : false ),  
  563. 'wp_version' => get_bloginfo( 'version' ),  
  564. 'wp_multisite' => is_multisite(),  
  565. 'wp_memory_limit' => $wp_memory_limit,  
  566. 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),  
  567. 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),  
  568. 'language' => get_locale(),  
  569. 'server_info' => $_SERVER['SERVER_SOFTWARE'],  
  570. 'php_version' => phpversion(),  
  571. 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ),  
  572. 'php_max_execution_time' => ini_get( 'max_execution_time' ),  
  573. 'php_max_input_vars' => ini_get( 'max_input_vars' ),  
  574. 'curl_version' => $curl_version,  
  575. 'suhosin_installed' => extension_loaded( 'suhosin' ),  
  576. 'max_upload_size' => wp_max_upload_size(),  
  577. 'mysql_version' => ( ! empty( $wpdb->is_mysql ) ? $wpdb->db_version() : '' ),  
  578. 'default_timezone' => date_default_timezone_get(),  
  579. 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),  
  580. 'soapclient_enabled' => class_exists( 'SoapClient' ),  
  581. 'domdocument_enabled' => class_exists( 'DOMDocument' ),  
  582. 'gzip_enabled' => is_callable( 'gzopen' ),  
  583. 'mbstring_enabled' => extension_loaded( 'mbstring' ),  
  584. 'remote_post_successful' => $post_response_successful,  
  585. 'remote_post_response' => ( is_wp_error( $post_response ) ? $post_response->get_error_message() : $post_response['response']['code'] ),  
  586. 'remote_get_successful' => $get_response_successful,  
  587. 'remote_get_response' => ( is_wp_error( $get_response ) ? $get_response->get_error_message() : $get_response['response']['code'] ),  
  588. ); 
  589.  
  590. /** 
  591. * Get array of database information. Version, prefix, and table existence. 
  592. * @return array 
  593. */ 
  594. public function get_database_info() { 
  595. global $wpdb; 
  596.  
  597. // WC Core tables to check existence of 
  598. $tables = apply_filters( 'woocommerce_database_tables', array( 
  599. 'woocommerce_sessions',  
  600. 'woocommerce_api_keys',  
  601. 'woocommerce_attribute_taxonomies',  
  602. 'woocommerce_downloadable_product_permissions',  
  603. 'woocommerce_order_items',  
  604. 'woocommerce_order_itemmeta',  
  605. 'woocommerce_tax_rates',  
  606. 'woocommerce_tax_rate_locations',  
  607. 'woocommerce_shipping_zones',  
  608. 'woocommerce_shipping_zone_locations',  
  609. 'woocommerce_shipping_zone_methods',  
  610. 'woocommerce_payment_tokens',  
  611. 'woocommerce_payment_tokenmeta',  
  612. ) ); 
  613.  
  614. if ( get_option( 'db_version' ) < 34370 ) { 
  615. $tables[] = 'woocommerce_termmeta'; 
  616. $table_exists = array(); 
  617. foreach ( $tables as $table ) { 
  618. $table_exists[ $table ] = ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s;", $wpdb->prefix . $table ) ) === $wpdb->prefix . $table ); 
  619.  
  620. // Return all database info. Described by JSON Schema. 
  621. return array( 
  622. 'wc_database_version' => get_option( 'woocommerce_db_version' ),  
  623. 'database_prefix' => $wpdb->prefix,  
  624. 'maxmind_geoip_database' => WC_Geolocation::get_local_database_path(),  
  625. 'database_tables' => $table_exists,  
  626. ); 
  627.  
  628. /** 
  629. * Get a list of plugins active on the site. 
  630. * @return array 
  631. */ 
  632. public function get_active_plugins() { 
  633. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  634.  
  635. // Get both site plugins and network plugins 
  636. $active_plugins = (array) get_option( 'active_plugins', array() ); 
  637. if ( is_multisite() ) { 
  638. $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); 
  639. $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); 
  640.  
  641. $active_plugins_data = array(); 
  642. $available_updates = get_plugin_updates(); 
  643.  
  644. foreach ( $active_plugins as $plugin ) { 
  645. $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); 
  646. $dirname = dirname( $plugin ); 
  647. $version_latest = ''; 
  648. $slug = explode( '/', $plugin ); 
  649. $slug = explode( '.', end( $slug ) ); 
  650. $slug = $slug[0]; 
  651.  
  652. if ( 'woocommerce' !== $slug && ( strstr( $data['PluginURI'], 'woothemes.com' ) || strstr( $data['PluginURI'], 'woocommerce.com' ) ) ) { 
  653. if ( false === ( $version_data = get_transient( md5( $plugin ) . '_version_data' ) ) ) { 
  654. $changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' ); 
  655. $cl_lines = explode( "\n", wp_remote_retrieve_body( $changelog ) ); 
  656. if ( ! empty( $cl_lines ) ) { 
  657. foreach ( $cl_lines as $line_num => $cl_line ) { 
  658. if ( preg_match( '/^[0-9]/', $cl_line ) ) { 
  659. $date = str_replace( '.' , '-' , trim( substr( $cl_line , 0 , strpos( $cl_line , '-' ) ) ) ); 
  660. $version = preg_replace( '~[^0-9, .]~' , '' , stristr( $cl_line , "version" ) ); 
  661. $update = trim( str_replace( "*" , "" , $cl_lines[ $line_num + 1 ] ) ); 
  662. $version_data = array( 'date' => $date , 'version' => $version , 'update' => $update , 'changelog' => $changelog ); 
  663. set_transient( md5( $plugin ) . '_version_data', $version_data, DAY_IN_SECONDS ); 
  664. break; 
  665. $version_latest = $version_data['version']; 
  666. } elseif ( isset( $available_updates[ $plugin ]->update->new_version ) ) { 
  667. $version_latest = $available_updates[ $plugin ]->update->new_version; 
  668.  
  669. // convert plugin data to json response format. 
  670. $active_plugins_data[] = array( 
  671. 'plugin' => $plugin,  
  672. 'name' => $data['Name'],  
  673. 'version' => $data['Version'],  
  674. 'version_latest' => $version_latest,  
  675. 'url' => $data['PluginURI'],  
  676. 'author_name' => $data['AuthorName'],  
  677. 'author_url' => esc_url_raw( $data['AuthorURI'] ),  
  678. 'network_activated' => $data['Network'],  
  679. ); 
  680.  
  681. return $active_plugins_data; 
  682.  
  683. /** 
  684. * Get info on the current active theme, info on parent theme (if presnet) 
  685. * and a list of template overrides. 
  686. * @return array 
  687. */ 
  688. public function get_theme_info() { 
  689. $active_theme = wp_get_theme(); 
  690.  
  691. // Get parent theme info if this theme is a child theme, otherwise 
  692. // pass empty info in the response. 
  693. if ( is_child_theme() ) { 
  694. $parent_theme = wp_get_theme( $active_theme->Template ); 
  695. $parent_theme_info = array( 
  696. 'parent_name' => $parent_theme->Name,  
  697. 'parent_version' => $parent_theme->Version,  
  698. 'parent_version_latest' => WC_Admin_Status::get_latest_theme_version( $parent_theme ),  
  699. 'parent_author_url' => $parent_theme->{'Author URI'},  
  700. ); 
  701. } else { 
  702. $parent_theme_info = array( 'parent_name' => '', 'parent_version' => '', 'parent_version_latest' => '', 'parent_author_url' => '' ); 
  703.  
  704. /** 
  705. * Scan the theme directory for all WC templates to see if our theme 
  706. * overrides any of them. 
  707. */ 
  708. $override_files = array(); 
  709. $outdated_templates = false; 
  710. $scan_files = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); 
  711. foreach ( $scan_files as $file ) { 
  712. if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { 
  713. $theme_file = get_stylesheet_directory() . '/' . $file; 
  714. } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { 
  715. $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; 
  716. } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { 
  717. $theme_file = get_template_directory() . '/' . $file; 
  718. } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { 
  719. $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; 
  720. } else { 
  721. $theme_file = false; 
  722.  
  723. if ( ! empty( $theme_file ) ) { 
  724. $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); 
  725. $theme_version = WC_Admin_Status::get_file_version( $theme_file ); 
  726. if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { 
  727. if ( ! $outdated_templates ) { 
  728. $outdated_templates = true; 
  729. $override_files[] = array( 
  730. 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ),  
  731. 'version' => $theme_version,  
  732. 'core_version' => $core_version,  
  733. ); 
  734.  
  735. $active_theme_info = array( 
  736. 'name' => $active_theme->Name,  
  737. 'version' => $active_theme->Version,  
  738. 'version_latest' => WC_Admin_Status::get_latest_theme_version( $active_theme ),  
  739. 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ),  
  740. 'is_child_theme' => is_child_theme(),  
  741. 'has_woocommerce_support' => ( current_theme_supports( 'woocommerce' ) || in_array( $active_theme->template, wc_get_core_supported_themes() ) ),  
  742. 'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ),  
  743. 'has_outdated_templates' => $outdated_templates,  
  744. 'overrides' => $override_files,  
  745. ); 
  746.  
  747. return array_merge( $active_theme_info, $parent_theme_info ); 
  748.  
  749. /** 
  750. * Get some setting values for the site that are useful for debugging 
  751. * purposes. For full settings access, use the settings api. 
  752. * @return array 
  753. */ 
  754. public function get_settings() { 
  755. // Get a list of terms used for product/order taxonomies 
  756. $term_response = array(); 
  757. $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); 
  758. foreach ( $terms as $term ) { 
  759. $term_response[ $term->slug ] = strtolower( $term->name ); 
  760.  
  761. // Get a list of terms used for product visibility. 
  762. $product_visibility_terms = array(); 
  763. $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); 
  764. foreach ( $terms as $term ) { 
  765. $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); 
  766.  
  767. // Return array of useful settings for debugging. 
  768. return array( 
  769. 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ),  
  770. 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ),  
  771. 'currency' => get_woocommerce_currency(),  
  772. 'currency_symbol' => get_woocommerce_currency_symbol(),  
  773. 'currency_position' => get_option( 'woocommerce_currency_pos' ),  
  774. 'thousand_separator' => wc_get_price_thousand_separator(),  
  775. 'decimal_separator' => wc_get_price_decimal_separator(),  
  776. 'number_of_decimals' => wc_get_price_decimals(),  
  777. 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ),  
  778. 'taxonomies' => $term_response,  
  779. 'product_visibility_terms' => $product_visibility_terms,  
  780. ); 
  781.  
  782. /** 
  783. * Returns security tips. 
  784. * @return array 
  785. */ 
  786. public function get_security_info() { 
  787. $check_page = 0 < wc_get_page_id( 'shop' ) ? get_permalink( wc_get_page_id( 'shop' ) ) : get_home_url(); 
  788. return array( 
  789. 'secure_connection' => 'https' === substr( $check_page, 0, 5 ),  
  790. 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ),  
  791. ); 
  792.  
  793. /** 
  794. * Returns a mini-report on WC pages and if they are configured correctly: 
  795. * Present, visible, and including the correct shortcode. 
  796. * @return array 
  797. */ 
  798. public function get_pages() { 
  799. // WC pages to check against 
  800. $check_pages = array( 
  801. _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( 
  802. 'option' => 'woocommerce_shop_page_id',  
  803. 'shortcode' => '',  
  804. ),  
  805. _x( 'Cart', 'Page setting', 'woocommerce' ) => array( 
  806. 'option' => 'woocommerce_cart_page_id',  
  807. 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']',  
  808. ),  
  809. _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( 
  810. 'option' => 'woocommerce_checkout_page_id',  
  811. 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']',  
  812. ),  
  813. _x( 'My account', 'Page setting', 'woocommerce' ) => array( 
  814. 'option' => 'woocommerce_myaccount_page_id',  
  815. 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']',  
  816. ),  
  817. ); 
  818.  
  819. $pages_output = array(); 
  820. foreach ( $check_pages as $page_name => $values ) { 
  821. $errors = array(); 
  822. $page_id = get_option( $values['option'] ); 
  823. $page_set = $page_exists = $page_visible = false; 
  824. $shortcode_present = $shortcode_required = false; 
  825.  
  826. // Page checks 
  827. if ( $page_id ) { 
  828. $page_set = true; 
  829. if ( get_post( $page_id ) ) { 
  830. $page_exists = true; 
  831. if ( 'publish' === get_post_status( $page_id ) ) { 
  832. $page_visible = true; 
  833.  
  834. // Shortcode checks 
  835. if ( $values['shortcode'] && get_post( $page_id ) ) { 
  836. $shortcode_required = true; 
  837. $page = get_post( $page_id ); 
  838. if ( strstr( $page->post_content, $values['shortcode'] ) ) { 
  839. $shortcode_present = true; 
  840.  
  841. // Wrap up our findings into an output array 
  842. $pages_output[] = array( 
  843. 'page_name' => $page_name,  
  844. 'page_id' => $page_id,  
  845. 'page_set' => $page_set,  
  846. 'page_exists' => $page_exists,  
  847. 'page_visible' => $page_visible,  
  848. 'shortcode' => $values['shortcode'],  
  849. 'shortcode_required' => $shortcode_required,  
  850. 'shortcode_present' => $shortcode_present,  
  851. ); 
  852.  
  853. return $pages_output; 
  854.  
  855. /** 
  856. * Get any query params needed. 
  857. * @return array 
  858. */ 
  859. public function get_collection_params() { 
  860. return array( 
  861. 'context' => $this->get_context_param( array( 'default' => 'view' ) ),  
  862. ); 
  863.  
  864. /** 
  865. * Prepare the system status response 
  866. * @param array $system_status 
  867. * @param WP_REST_Request $request Request object. 
  868. * @return WP_REST_Response $response Response data. 
  869. */ 
  870. public function prepare_item_for_response( $system_status, $request ) { 
  871. $data = $this->add_additional_fields_to_object( $system_status, $request ); 
  872. $data = $this->filter_response_by_context( $data, 'view' ); 
  873.  
  874. $response = rest_ensure_response( $data ); 
  875.  
  876. /** 
  877. * Filter the system status returned from the REST API. 
  878. * @param WP_REST_Response $response The response object. 
  879. * @param mixed $system_status System status 
  880. * @param WP_REST_Request $request Request object. 
  881. */ 
  882. return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request );