Commit 6ff9602f3bc for woocommerce
commit 6ff9602f3bca0781b5593d7146ef4e3aa51904d3
Author: Christopher Hertel <mail@christopher-hertel.de>
Date: Thu Nov 19 12:39:39 2026 +0100
Add a system status read ability without server details (#70963)
* Add a system-status-get ability without server details
Woo AI's system-status-get passes the raw status report through its REST
bridge: the log directory, database prefix, every table name and size,
plugin URLs and remote-call responses. Core now offers an allowlisted
read: WooCommerce and database versions, order storage, installed
plugins (name, version, author), enabled WooCommerce features, the
theme, the WooCommerce pages, the security checks and post counts.
WordPress, PHP and database server versions stay with
core/get-environment-info.
The theme is read locally, because the status controller looks up the
latest version on WordPress.org. Outdated template overrides reuse the
Site Health check, which is now public and internal.
* Read template overrides through Site Health and fix the empty input schema
run_test() is already public, so SiteHealth keeps its private helper. An empty
properties array encoded as a JSON list, which MCP clients cannot compile.
* Report page content checks and environment flags in system-status-get
Adds whether each WooCommerce page holds its shortcode or block, and the cron,
debug, object cache, memory, upload and log directory checks, read directly so
the status controller's remote test requests never run. Tests cover outdated
template overrides and child themes.
* Check only output values for the database prefix
Field names such as wp_cron share the default wp_ prefix.
* Match system-status-get to the templates WooCommerce loads and to the visitor error setting
- has_outdated_templates now uses the Status report's own scan, moved into
WC_REST_System_Status_V2_Controller::get_template_overrides(), so filtered
and legacy template overrides count. Site Health's check missed both.
- hide_errors reads WP_DEBUG_DISPLAY, then the configured display_errors,
because WordPress turns display_errors off for JSON requests.
- Plugin and drop-in names, versions and authors are plain text; headers can
carry links and other HTML.
- The pages description says Cart and Checkout need exactly one of the
shortcode or block.
* Harden system-status-get plugin headers, hide_errors and the template scan
- Decode plugin header entities before stripping tags, so an encoded link
cannot come back as HTML.
- Fall back to ini_get() when ini_get_all() is disabled, and describe
hide_errors as reading the PHP configuration, not runtime overrides.
- Skip wc_get_template results that are not a path instead of throwing.
diff --git a/plugins/woocommerce/changelog/wooai-1704-system-status-get b/plugins/woocommerce/changelog/wooai-1704-system-status-get
new file mode 100644
index 00000000000..8d41692146b
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooai-1704-system-status-get
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add an ability that reads the store's system status without server paths or database details.
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
index 8e1d3aa73aa..aefbd532ece 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
@@ -1505,65 +1505,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
);
}
- /**
- * Scan the theme directory for all WC templates to see if our theme
- * overrides any of them.
- */
- $override_files = array();
- $outdated_templates = false;
- $scan_files = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' );
-
- // Include *-product_<cat|tag> templates for backwards compatibility.
- $scan_files[] = 'content-product_cat.php';
- $scan_files[] = 'taxonomy-product_cat.php';
- $scan_files[] = 'taxonomy-product_tag.php';
-
- $wc_templates_dir = WC()->plugin_path() . '/templates/';
-
- foreach ( $scan_files as $file ) {
- $located = wc_locate_template( $file, WC()->template_path(), $wc_templates_dir );
-
- /**
- * Allow 3rd party plugins to filter the template file location.
- *
- * @param string $located The located template path.
- * @param string $file The template file name.
- * @param array $args Template arguments.
- * @param string $template_path The template path.
- * @param string $default_path The default path.
- *
- * @since 2.1.0
- */
- $located = apply_filters( 'wc_get_template', $located, $file, array(), WC()->template_path(), $wc_templates_dir );
-
- // Check if the template is overridden (located outside WC core templates dir).
- $override_file = false;
- if ( 0 !== strpos( $located, $wc_templates_dir ) && file_exists( $located ) ) {
- $override_file = $located;
- }
-
- if ( ! empty( $override_file ) ) {
- $core_file = $file;
-
- // Update *-product_<cat|tag> template name before searching in core.
- if ( false !== strpos( $core_file, '-product_cat' ) || false !== strpos( $core_file, '-product_tag' ) ) {
- $core_file = str_replace( '_', '-', $core_file );
- }
-
- $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $core_file );
- $override_version = WC_Admin_Status::get_file_version( $override_file );
- if ( $core_version && '' !== $override_version && version_compare( $override_version, $core_version, '<' ) ) {
- if ( ! $outdated_templates ) {
- $outdated_templates = true;
- }
- }
- $override_files[] = array(
- 'file' => str_replace( ABSPATH, '', $override_file ),
- 'version' => $override_version,
- 'core_version' => $core_version,
- );
- }
- }
+ $templates = $this->get_template_overrides();
$active_theme_info = array(
'name' => $active_theme->name,
@@ -1574,8 +1516,8 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
'is_block_theme' => wp_is_block_theme(),
'has_woocommerce_support' => current_theme_supports( 'woocommerce' ),
'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ),
- 'has_outdated_templates' => $outdated_templates,
- 'overrides' => $override_files,
+ 'has_outdated_templates' => $templates['has_outdated_templates'],
+ 'overrides' => $templates['overrides'],
);
$theme_info = array_merge( $active_theme_info, $parent_theme_info );
@@ -1585,6 +1527,79 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
return $theme_info;
}
+ /**
+ * Scan the template files WooCommerce would load, after the template filters, for theme overrides.
+ *
+ * @since 11.4.0
+ *
+ * @return array{overrides: array<int, array<string, string>>, has_outdated_templates: bool}
+ */
+ public function get_template_overrides(): array {
+ $override_files = array();
+ $outdated_templates = false;
+ $scan_files = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' );
+
+ // Include *-product_<cat|tag> templates for backwards compatibility.
+ $scan_files[] = 'content-product_cat.php';
+ $scan_files[] = 'taxonomy-product_cat.php';
+ $scan_files[] = 'taxonomy-product_tag.php';
+
+ $wc_templates_dir = WC()->plugin_path() . '/templates/';
+
+ foreach ( $scan_files as $file ) {
+ $located = wc_locate_template( $file, WC()->template_path(), $wc_templates_dir );
+
+ /**
+ * Allow 3rd party plugins to filter the template file location.
+ *
+ * @param string $located The located template path.
+ * @param string $file The template file name.
+ * @param array $args Template arguments.
+ * @param string $template_path The template path.
+ * @param string $default_path The default path.
+ *
+ * @since 2.1.0
+ */
+ $located = apply_filters( 'wc_get_template', $located, $file, array(), WC()->template_path(), $wc_templates_dir );
+ if ( ! is_string( $located ) || '' === $located ) {
+ continue;
+ }
+
+ // Check if the template is overridden (located outside WC core templates dir).
+ $override_file = false;
+ if ( 0 !== strpos( $located, $wc_templates_dir ) && file_exists( $located ) ) {
+ $override_file = $located;
+ }
+
+ if ( ! empty( $override_file ) ) {
+ $core_file = $file;
+
+ // Update *-product_<cat|tag> template name before searching in core.
+ if ( false !== strpos( $core_file, '-product_cat' ) || false !== strpos( $core_file, '-product_tag' ) ) {
+ $core_file = str_replace( '_', '-', $core_file );
+ }
+
+ $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $core_file );
+ $override_version = WC_Admin_Status::get_file_version( $override_file );
+ if ( $core_version && '' !== $override_version && version_compare( $override_version, $core_version, '<' ) ) {
+ if ( ! $outdated_templates ) {
+ $outdated_templates = true;
+ }
+ }
+ $override_files[] = array(
+ 'file' => str_replace( ABSPATH, '', $override_file ),
+ 'version' => $override_version,
+ 'core_version' => $core_version,
+ );
+ }
+ }
+
+ return array(
+ 'overrides' => $override_files,
+ 'has_outdated_templates' => $outdated_templates,
+ );
+ }
+
/**
* Clear the system status theme cache
*/
diff --git a/plugins/woocommerce/src/Internal/Abilities/AbilitiesLoader.php b/plugins/woocommerce/src/Internal/Abilities/AbilitiesLoader.php
index b757236a6d4..a007998196d 100644
--- a/plugins/woocommerce/src/Internal/Abilities/AbilitiesLoader.php
+++ b/plugins/woocommerce/src/Internal/Abilities/AbilitiesLoader.php
@@ -40,6 +40,7 @@ use Automattic\WooCommerce\Internal\Abilities\Domain\ShippingZoneCreate;
use Automattic\WooCommerce\Internal\Abilities\Domain\ShippingZoneMethodCreate;
use Automattic\WooCommerce\Internal\Abilities\Domain\ShippingZoneMethodUpdate;
use Automattic\WooCommerce\Internal\Abilities\Domain\ShippingZonesQuery;
+use Automattic\WooCommerce\Internal\Abilities\Domain\SystemStatusGet;
use Automattic\WooCommerce\Internal\Abilities\Domain\SystemStatusToolRun;
use Automattic\WooCommerce\Internal\Abilities\Domain\SystemStatusToolsQuery;
use Automattic\WooCommerce\Internal\Abilities\Domain\TaxRatesQuery;
@@ -97,6 +98,7 @@ class AbilitiesLoader {
ReportAbility::class,
RunCheckAbility::class,
ShippingZonesQuery::class,
+ SystemStatusGet::class,
SystemStatusToolsQuery::class,
SystemStatusToolRun::class,
ShippingZoneCreate::class,
diff --git a/plugins/woocommerce/src/Internal/Abilities/Domain/SystemStatusGet.php b/plugins/woocommerce/src/Internal/Abilities/Domain/SystemStatusGet.php
new file mode 100644
index 00000000000..54737b2c2e8
--- /dev/null
+++ b/plugins/woocommerce/src/Internal/Abilities/Domain/SystemStatusGet.php
@@ -0,0 +1,428 @@
+<?php
+/**
+ * System status get ability definition file.
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\Internal\Abilities\Domain;
+
+use Automattic\WooCommerce\Abilities\AbilityDefinition;
+use Automattic\WooCommerce\Utilities\FeaturesUtil;
+use Automattic\WooCommerce\Utilities\LoggingUtil;
+use Automattic\WooCommerce\Utilities\OrderUtil;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * An allowlisted part of the system status report. Server paths, the database
+ * prefix, table names, URLs and remote call results have no field.
+ */
+class SystemStatusGet extends AbstractDomainAbility implements AbilityDefinition {
+
+ /**
+ * Ability ID, stable once released.
+ *
+ * @return string
+ *
+ * @since 11.4.0
+ */
+ public static function get_name(): string {
+ return 'woocommerce/system-status-get';
+ }
+
+ /**
+ * Read-only, shop-manager-level registration.
+ *
+ * @return array
+ *
+ * @since 11.4.0
+ */
+ public static function get_registration_args(): array {
+ return array(
+ 'label' => __( 'Get system status', 'woocommerce' ),
+ 'description' => __(
+ 'Get the WooCommerce and database versions, order storage, environment checks, installed plugins, enabled WooCommerce features, the theme, the store pages, security checks and post counts. WordPress, PHP and database server versions come from core/get-environment-info.',
+ 'woocommerce'
+ ),
+ 'category' => 'woocommerce',
+ 'input_schema' => array(
+ 'type' => 'object',
+ 'default' => array(),
+ 'additionalProperties' => false,
+ ),
+ 'output_schema' => self::get_entity_output_schema( 'system_status', self::get_status_schema() ),
+ 'execute_callback' => array( __CLASS__, 'execute' ),
+ 'permission_callback' => array( __CLASS__, 'can_read_system_status' ),
+ 'meta' => array(
+ 'show_in_rest' => true,
+ 'mcp' => array(
+ 'public' => true,
+ 'type' => 'tool',
+ ),
+ 'annotations' => array(
+ 'readonly' => true,
+ 'idempotent' => true,
+ 'destructive' => false,
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Plugin lists come from the status controller's hourly transients.
+ *
+ * @return array
+ *
+ * @since 11.4.0
+ */
+ public static function execute(): array {
+ $controller = new \WC_REST_System_Status_Controller();
+ $dropins_mu = $controller->get_dropins_mu_plugins();
+ $security = $controller->get_security_info();
+
+ return array(
+ 'system_status' => array(
+ 'woocommerce_version' => (string) WC()->version,
+ 'woocommerce_db_version' => (string) get_option( 'woocommerce_db_version', '' ),
+ 'order_storage' => OrderUtil::custom_orders_table_usage_is_enabled() ? 'hpos' : 'posts',
+ 'environment' => self::get_environment(),
+ 'active_plugins' => self::format_plugins( $controller->get_active_plugins() ),
+ 'inactive_plugins' => self::format_plugins( $controller->get_inactive_plugins() ),
+ 'mu_plugins' => self::format_plugins( $dropins_mu['mu_plugins'] ?? array() ),
+ 'dropins' => self::format_dropins( $dropins_mu['dropins'] ?? array() ),
+ 'enabled_features' => self::get_enabled_features(),
+ 'theme' => self::get_theme( $controller ),
+ 'pages' => self::format_pages( $controller->get_pages() ),
+ 'security' => array(
+ 'secure_connection' => (bool) ( $security['secure_connection'] ?? false ),
+ 'hide_errors' => ! self::shows_errors_to_visitors(),
+ ),
+ 'post_type_counts' => self::get_post_type_counts( $controller ),
+ ),
+ );
+ }
+
+ /**
+ * Same check as the system status REST endpoint.
+ *
+ * @return bool
+ *
+ * @since 11.4.0
+ */
+ public static function can_read_system_status(): bool {
+ return (bool) wc_rest_check_manager_permissions( 'system_status', 'read' );
+ }
+
+ /**
+ * Keeps only name, version and author; the report also carries plugin and author URLs.
+ *
+ * @param mixed $plugins Plugin rows from the status controller.
+ * @return array<int, array<string, string>>
+ */
+ private static function format_plugins( $plugins ): array {
+ if ( ! is_array( $plugins ) ) {
+ return array();
+ }
+
+ $items = array();
+ foreach ( array_filter( $plugins, 'is_array' ) as $plugin ) {
+ $items[] = array(
+ 'plugin' => (string) ( $plugin['plugin'] ?? '' ),
+ 'name' => self::to_text( $plugin['name'] ?? '' ),
+ 'version' => self::to_text( $plugin['version'] ?? '' ),
+ 'author' => self::to_text( $plugin['author_name'] ?? '' ),
+ );
+ }
+ return $items;
+ }
+
+ /**
+ * Drop-ins have no version or author in the report.
+ *
+ * @param mixed $dropins Drop-in rows from the status controller.
+ * @return array<int, array<string, string>>
+ */
+ private static function format_dropins( $dropins ): array {
+ if ( ! is_array( $dropins ) ) {
+ return array();
+ }
+
+ $items = array();
+ foreach ( array_filter( $dropins, 'is_array' ) as $dropin ) {
+ $items[] = array(
+ 'plugin' => (string) ( $dropin['plugin'] ?? '' ),
+ 'name' => self::to_text( $dropin['name'] ?? '' ),
+ );
+ }
+ return $items;
+ }
+
+ /**
+ * Plugin headers can carry HTML, links included, either literal or entity-encoded.
+ *
+ * @param mixed $value Header value.
+ * @return string
+ */
+ private static function to_text( $value ): string {
+ return wp_strip_all_tags( html_entity_decode( (string) $value, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) );
+ }
+
+ /**
+ * Deprecated features are left out even when their option is still on.
+ *
+ * @return string[]
+ */
+ private static function get_enabled_features(): array {
+ $features = array();
+ foreach ( FeaturesUtil::get_features( true, true ) as $id => $feature ) {
+ if ( ! empty( $feature['is_enabled'] ) && empty( $feature['deprecated_since'] ) ) {
+ $features[] = (string) $id;
+ }
+ }
+ sort( $features );
+ return $features;
+ }
+
+ /**
+ * Read directly: the status controller's environment section also makes two remote test requests.
+ *
+ * @return array<string, mixed>
+ */
+ private static function get_environment(): array {
+ $memory_limit = (string) ini_get( 'memory_limit' );
+
+ return array(
+ 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
+ 'wp_debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
+ 'external_object_cache' => (bool) wp_using_ext_object_cache(),
+ 'memory_limit' => '-1' === $memory_limit ? -1 : wp_convert_hr_to_bytes( $memory_limit ),
+ 'max_upload_size' => (int) wp_max_upload_size(),
+ 'log_directory_writable' => wp_is_writable( LoggingUtil::get_log_directory( false ) ),
+ );
+ }
+
+ /**
+ * Read locally: the status controller's theme section looks up the latest theme version on WordPress.org.
+ *
+ * @param \WC_REST_System_Status_Controller $controller Status controller.
+ * @return array<string, mixed>
+ */
+ private static function get_theme( \WC_REST_System_Status_Controller $controller ): array {
+ $theme = wp_get_theme();
+ $info = array(
+ 'name' => (string) $theme->get( 'Name' ),
+ 'version' => (string) $theme->get( 'Version' ),
+ 'is_block_theme' => $theme->is_block_theme(),
+ 'has_woocommerce_support' => current_theme_supports( 'woocommerce' ),
+ 'has_outdated_templates' => $controller->get_template_overrides()['has_outdated_templates'],
+ );
+
+ $parent = $theme->parent();
+ if ( $parent ) {
+ $info['parent_name'] = (string) $parent->get( 'Name' );
+ $info['parent_version'] = (string) $parent->get( 'Version' );
+ }
+
+ return $info;
+ }
+
+ /**
+ * Request-independent: WordPress turns display_errors off for JSON requests, so the configured value is read instead.
+ *
+ * @return bool
+ */
+ private static function shows_errors_to_visitors(): bool {
+ $debug_display = defined( 'WP_DEBUG_DISPLAY' ) ? constant( 'WP_DEBUG_DISPLAY' ) : null;
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG && null !== $debug_display ) {
+ return (bool) $debug_display;
+ }
+
+ $ini = function_exists( 'ini_get_all' ) ? ini_get_all( null, true ) : false;
+ $configured = is_array( $ini ) ? ( $ini['display_errors']['global_value'] ?? '' ) : ini_get( 'display_errors' );
+ return in_array( strtolower( (string) $configured ), array( '1', 'on', 'true', 'yes', 'stdout' ), true );
+ }
+
+ /**
+ * Leaves out page IDs and the names of the expected shortcode and block.
+ *
+ * @param mixed $pages Page rows from the status controller.
+ * @return array<int, array<string, mixed>>
+ */
+ private static function format_pages( $pages ): array {
+ if ( ! is_array( $pages ) ) {
+ return array();
+ }
+
+ $items = array();
+ foreach ( array_filter( $pages, 'is_array' ) as $page ) {
+ $items[] = array(
+ 'name' => (string) ( $page['page_name'] ?? '' ),
+ 'set' => (bool) ( $page['page_set'] ?? false ),
+ 'exists' => (bool) ( $page['page_exists'] ?? false ),
+ 'visible' => (bool) ( $page['page_visible'] ?? false ),
+ 'shortcode_required' => (bool) ( $page['shortcode_required'] ?? false ),
+ 'shortcode_present' => (bool) ( $page['shortcode_present'] ?? false ),
+ 'block_required' => (bool) ( $page['block_required'] ?? false ),
+ 'block_present' => (bool) ( $page['block_present'] ?? false ),
+ );
+ }
+ return $items;
+ }
+
+ /**
+ * An object, so an empty list still encodes as a JSON object.
+ *
+ * @param \WC_REST_System_Status_Controller $controller Status controller.
+ * @return object
+ */
+ private static function get_post_type_counts( \WC_REST_System_Status_Controller $controller ): object {
+ $counts = array();
+ foreach ( $controller->get_post_type_counts() as $row ) {
+ $counts[ (string) $row->type ] = (int) $row->count;
+ }
+ return (object) $counts;
+ }
+
+ /**
+ * Closed at every level, so no report field can reach the output unlisted.
+ *
+ * @return array
+ */
+ private static function get_status_schema(): array {
+ $string = array( 'type' => 'string' );
+ $plugin = array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'plugin' => array(
+ 'type' => 'string',
+ 'description' => __( 'Plugin file, relative to the plugins directory.', 'woocommerce' ),
+ ),
+ 'name' => $string,
+ 'version' => $string,
+ 'author' => $string,
+ ),
+ 'additionalProperties' => false,
+ );
+
+ return array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'woocommerce_version' => $string,
+ 'woocommerce_db_version' => $string,
+ 'order_storage' => array(
+ 'type' => 'string',
+ 'enum' => array( 'hpos', 'posts' ),
+ ),
+ 'environment' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'wp_cron' => array(
+ 'type' => 'boolean',
+ 'description' => __( 'Whether WP-Cron runs on page loads; false when DISABLE_WP_CRON is set.', 'woocommerce' ),
+ ),
+ 'wp_debug_mode' => array( 'type' => 'boolean' ),
+ 'external_object_cache' => array( 'type' => 'boolean' ),
+ 'memory_limit' => array(
+ 'type' => 'integer',
+ 'description' => __( 'PHP memory limit in bytes, which WordPress raises to WP_MEMORY_LIMIT; -1 for no limit.', 'woocommerce' ),
+ ),
+ 'max_upload_size' => array(
+ 'type' => 'integer',
+ 'description' => __( 'Bytes.', 'woocommerce' ),
+ ),
+ 'log_directory_writable' => array( 'type' => 'boolean' ),
+ ),
+ 'additionalProperties' => false,
+ ),
+ 'active_plugins' => array(
+ 'type' => 'array',
+ 'items' => $plugin,
+ ),
+ 'inactive_plugins' => array(
+ 'type' => 'array',
+ 'items' => $plugin,
+ ),
+ 'mu_plugins' => array(
+ 'type' => 'array',
+ 'items' => $plugin,
+ ),
+ 'dropins' => array(
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'plugin' => $string,
+ 'name' => $string,
+ ),
+ 'additionalProperties' => false,
+ ),
+ ),
+ 'enabled_features' => array(
+ 'type' => 'array',
+ 'items' => $string,
+ ),
+ 'theme' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'name' => $string,
+ 'version' => $string,
+ 'is_block_theme' => array( 'type' => 'boolean' ),
+ 'has_woocommerce_support' => array( 'type' => 'boolean' ),
+ 'has_outdated_templates' => array(
+ 'type' => 'boolean',
+ 'description' => __( 'Whether the theme overrides a WooCommerce template with an older version of it.', 'woocommerce' ),
+ ),
+ 'parent_name' => array(
+ 'type' => 'string',
+ 'description' => __( 'Only for a child theme.', 'woocommerce' ),
+ ),
+ 'parent_version' => array(
+ 'type' => 'string',
+ 'description' => __( 'Only for a child theme.', 'woocommerce' ),
+ ),
+ ),
+ 'additionalProperties' => false,
+ ),
+ 'pages' => array(
+ 'type' => 'array',
+ 'description' => __( 'The WooCommerce pages: whether each is assigned in settings, exists, is published, and has the content it needs. Where both shortcode_required and block_required are true, the page needs exactly one of the shortcode or block; both present is a problem.', 'woocommerce' ),
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'name' => $string,
+ 'set' => array( 'type' => 'boolean' ),
+ 'exists' => array( 'type' => 'boolean' ),
+ 'visible' => array( 'type' => 'boolean' ),
+ 'shortcode_required' => array( 'type' => 'boolean' ),
+ 'shortcode_present' => array( 'type' => 'boolean' ),
+ 'block_required' => array( 'type' => 'boolean' ),
+ 'block_present' => array( 'type' => 'boolean' ),
+ ),
+ 'additionalProperties' => false,
+ ),
+ ),
+ 'security' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'secure_connection' => array(
+ 'type' => 'boolean',
+ 'description' => __( 'Whether the shop page URL uses HTTPS.', 'woocommerce' ),
+ ),
+ 'hide_errors' => array(
+ 'type' => 'boolean',
+ 'description' => __( 'Whether the configuration hides PHP errors from visitors: WP_DEBUG_DISPLAY when WP_DEBUG is on, otherwise display_errors in the PHP configuration. An ini_set() override at runtime is not seen.', 'woocommerce' ),
+ ),
+ ),
+ 'additionalProperties' => false,
+ ),
+ 'post_type_counts' => array(
+ 'type' => 'object',
+ 'description' => __( 'Number of posts of each post type, in every status.', 'woocommerce' ),
+ 'additionalProperties' => array( 'type' => 'integer' ),
+ ),
+ ),
+ 'additionalProperties' => false,
+ );
+ }
+}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
index e8c00d3843c..b93862cf6da 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/AbilitiesLoaderTest.php
@@ -66,6 +66,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
'woocommerce/shipping-zone-create',
'woocommerce/shipping-zone-method-create',
'woocommerce/shipping-zone-method-update',
+ 'woocommerce/system-status-get',
'woocommerce/tax-rates-query',
'woocommerce/system-status-tools-query',
'woocommerce/system-status-tool-run',
@@ -362,6 +363,11 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
'idempotent' => true,
'destructive' => false,
),
+ 'woocommerce/system-status-get' => array(
+ 'readonly' => true,
+ 'idempotent' => true,
+ 'destructive' => false,
+ ),
'woocommerce/customers-query' => array(
'readonly' => true,
'idempotent' => true,
@@ -1178,6 +1184,10 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
'woocommerce/payment-gateways-query',
array(),
),
+ 'system-status-get' => array(
+ 'woocommerce/system-status-get',
+ array(),
+ ),
'customers-query' => array(
'woocommerce/customers-query',
array(),
@@ -1276,6 +1286,7 @@ class AbilitiesLoaderTest extends \WC_Unit_Test_Case {
'enabled' => true,
),
),
+ 'system-status-get' => array( 'woocommerce/system-status-get', array() ),
'customers-query' => array( 'woocommerce/customers-query', array() ),
'shipping-zones-query' => array( 'woocommerce/shipping-zones-query', array() ),
'shipping-zone-method-update' => array(
diff --git a/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/SystemStatusGetTest.php b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/SystemStatusGetTest.php
new file mode 100644
index 00000000000..9e9ad815541
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/Abilities/Domain/SystemStatusGetTest.php
@@ -0,0 +1,379 @@
+<?php
+/**
+ * SystemStatusGetTest class file.
+ */
+
+declare( strict_types=1 );
+
+namespace Automattic\WooCommerce\Tests\Internal\Abilities\Domain;
+
+use Automattic\WooCommerce\Internal\Abilities\AbilitiesLoader;
+
+/**
+ * Tests for the system-status-get ability.
+ */
+class SystemStatusGetTest extends \WC_Unit_Test_Case {
+
+ /**
+ * Administrator used as the current user.
+ *
+ * @var int
+ */
+ private static $administrator_id;
+
+ /**
+ * Init action count restored in tearDown.
+ *
+ * @var int|null
+ */
+ private $original_init_count;
+
+ /**
+ * Create the administrator once for the class.
+ *
+ * @param \WP_UnitTest_Factory $factory WordPress unit test factory.
+ */
+ public static function wpSetUpBeforeClass( $factory ): void {
+ self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
+ }
+
+ /**
+ * Start each test from an empty abilities registry, so the abilities register again.
+ */
+ public function setUp(): void {
+ global $wp_actions;
+
+ if ( ! function_exists( 'wp_register_ability' ) ) {
+ require_once WC_ABSPATH . 'vendor/wordpress/abilities-api/includes/bootstrap.php';
+ }
+
+ // The Abilities API registry refuses to initialize before `init` has fired.
+ $this->original_init_count = $wp_actions['init'] ?? null;
+ $wp_actions['init'] = max( 1, (int) ( $wp_actions['init'] ?? 0 ) ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+
+ parent::setUp();
+
+ wc_get_container()->get( AbilitiesLoader::class )->init();
+ self::reset_registries();
+ wp_set_current_user( self::$administrator_id );
+ }
+
+ /**
+ * Leave the registries and the init count as the next test expects them.
+ */
+ public function tearDown(): void {
+ global $wp_actions;
+
+ try {
+ self::reset_registries();
+ } finally {
+ parent::tearDown();
+ }
+
+ if ( null !== $this->original_init_count ) {
+ $wp_actions['init'] = $this->original_init_count; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ } else {
+ unset( $wp_actions['init'] ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ }
+ }
+
+ /**
+ * Drop every registered ability, so the next read registers them again.
+ */
+ private static function reset_registries(): void {
+ global $wp_actions;
+
+ foreach ( array( 'WP_Abilities_Registry', 'WP_Ability_Categories_Registry' ) as $registry ) {
+ if ( class_exists( $registry ) ) {
+ $instance = new \ReflectionProperty( $registry, 'instance' );
+ $instance->setAccessible( true );
+ $instance->setValue( null, null );
+ }
+ }
+ unset( $wp_actions['wp_abilities_api_init'], $wp_actions['wp_abilities_api_categories_init'] );
+ }
+
+ /**
+ * Run the ability as the current user; execute() also validates the output against the output schema.
+ *
+ * @return mixed|\WP_Error
+ */
+ private function get_status() {
+ $ability = wp_get_ability( 'woocommerce/system-status-get' );
+ $this->assertNotNull( $ability, 'The ability should be registered.' );
+
+ return $ability->execute( array() );
+ }
+
+ /**
+ * @testdox Should return every allowlisted field, valid against the output schema.
+ */
+ public function test_returns_the_allowlisted_fields(): void {
+ $result = $this->get_status();
+
+ $this->assertNotWPError( $result );
+ $this->assertSame(
+ array( 'woocommerce_version', 'woocommerce_db_version', 'order_storage', 'environment', 'active_plugins', 'inactive_plugins', 'mu_plugins', 'dropins', 'enabled_features', 'theme', 'pages', 'security', 'post_type_counts' ),
+ array_keys( $result['system_status'] )
+ );
+ $this->assertSame( WC()->version, $result['system_status']['woocommerce_version'] );
+ $this->assertIsObject( $result['system_status']['post_type_counts'], 'Post type counts should encode as a JSON object.' );
+ }
+
+ /**
+ * @testdox Should leave out log paths, server paths, the database prefix, table names and URLs.
+ */
+ public function test_output_has_no_server_details(): void {
+ global $wpdb;
+
+ set_transient(
+ 'wc_system_status_active_plugins',
+ array(
+ array(
+ 'plugin' => 'canary/canary.php',
+ 'name' => 'Canary',
+ 'version' => '1.0.0',
+ 'version_latest' => '1.0.0',
+ 'url' => 'https://canary.example/plugin',
+ 'author_name' => 'Canary Co',
+ 'author_url' => 'https://canary.example/author',
+ 'network_activated' => false,
+ ),
+ )
+ );
+
+ $result = $this->get_status();
+ $json = (string) wp_json_encode( $result, JSON_UNESCAPED_SLASHES );
+
+ $this->assertNotWPError( $result );
+ $this->assertContains( 'Canary', array_column( $result['system_status']['active_plugins'], 'name' ) );
+ $this->assertStringNotContainsString( 'canary.example', $json, 'Plugin and author URLs should be left out.' );
+ $this->assertStringNotContainsString( 'http', $json, 'No URL should reach the output.' );
+ $this->assertStringNotContainsString( untrailingslashit( ABSPATH ), $json, 'Server paths should be left out.' );
+ $this->assertStringNotContainsString( untrailingslashit( WC_LOG_DIR ), $json, 'The log directory should be left out.' );
+ // Field names such as wp_cron share the default wp_ prefix, so only values are checked for it.
+ $values = array();
+ array_walk_recursive(
+ $result,
+ static function ( $value ) use ( &$values ) {
+ if ( is_string( $value ) ) {
+ $values[] = $value;
+ }
+ }
+ );
+ $this->assertStringNotContainsString( $wpdb->prefix, implode( "\n", $values ), 'The database prefix and table names should be left out.' );
+ }
+
+ /**
+ * @testdox Should report a published checkout page with its block as set, existing, visible and complete, without its ID.
+ */
+ public function test_pages_report_setup_without_ids(): void {
+ $page_id = self::factory()->post->create(
+ array(
+ 'post_type' => 'page',
+ 'post_status' => 'publish',
+ 'post_content' => '<!-- wp:woocommerce/checkout /-->',
+ )
+ );
+ update_option( 'woocommerce_checkout_page_id', $page_id );
+
+ $result = $this->get_status();
+ $pages = array_column( $result['system_status']['pages'], null, 'name' );
+
+ $this->assertArrayHasKey( 'Checkout', $pages );
+ $this->assertTrue( $pages['Checkout']['set'] );
+ $this->assertTrue( $pages['Checkout']['exists'] );
+ $this->assertTrue( $pages['Checkout']['visible'] );
+ $this->assertTrue( $pages['Checkout']['block_present'] );
+ $this->assertFalse( $pages['Checkout']['shortcode_present'] );
+ $this->assertArrayNotHasKey( 'page_id', $pages['Checkout'] );
+ }
+
+ /**
+ * @testdox Should leave out the parent theme fields when the theme is not a child theme.
+ */
+ public function test_theme_without_parent_omits_parent_fields(): void {
+ $this->assertFalse( is_child_theme(), 'The test site should run a theme without a parent.' );
+
+ $theme = $this->get_status()['system_status']['theme'];
+
+ $this->assertSame( wp_get_theme()->get( 'Name' ), $theme['name'] );
+ $this->assertArrayNotHasKey( 'parent_name', $theme );
+ $this->assertArrayNotHasKey( 'parent_version', $theme );
+ }
+
+ /**
+ * @testdox Should report outdated templates when the theme overrides a template with an older version.
+ */
+ public function test_reports_outdated_template_override(): void {
+ $theme_dir = get_temp_dir() . 'wc-system-status-' . wp_generate_password( 8, false );
+ wp_mkdir_p( $theme_dir . '/woocommerce/cart' );
+ file_put_contents( $theme_dir . '/woocommerce/cart/cart.php', "<?php\n/**\n * @version 1.0.0\n */\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
+ $use_theme_dir = static fn() => $theme_dir;
+ add_filter( 'stylesheet_directory', $use_theme_dir );
+ wp_set_template_globals();
+
+ try {
+ $theme = $this->get_status()['system_status']['theme'];
+ } finally {
+ remove_filter( 'stylesheet_directory', $use_theme_dir );
+ wp_set_template_globals();
+ unlink( $theme_dir . '/woocommerce/cart/cart.php' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
+ rmdir( $theme_dir . '/woocommerce/cart' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ rmdir( $theme_dir . '/woocommerce' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ rmdir( $theme_dir ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ }
+
+ $this->assertTrue( $theme['has_outdated_templates'] );
+ }
+
+ /**
+ * @testdox Should report outdated templates when a plugin points WooCommerce to an older template through wc_get_template.
+ */
+ public function test_reports_outdated_template_from_filter(): void {
+ $dir = get_temp_dir() . 'wc-system-status-' . wp_generate_password( 8, false );
+ wp_mkdir_p( $dir );
+ file_put_contents( $dir . '/cart.php', "<?php\n/**\n * @version 1.0.0\n */\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
+ $redirect = static fn( $located, $name ) => 'cart/cart.php' === $name ? $dir . '/cart.php' : $located;
+ add_filter( 'wc_get_template', $redirect, 10, 2 );
+
+ try {
+ $theme = $this->get_status()['system_status']['theme'];
+ } finally {
+ remove_filter( 'wc_get_template', $redirect, 10 );
+ unlink( $dir . '/cart.php' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
+ rmdir( $dir ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ }
+
+ $this->assertTrue( $theme['has_outdated_templates'] );
+ }
+
+ /**
+ * @testdox Should give the same hide_errors answer whether or not WordPress turned display_errors off for a JSON request.
+ */
+ public function test_hide_errors_does_not_depend_on_request_type(): void {
+ if ( ! ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) ) {
+ $this->markTestSkipped( 'Needs WP_DEBUG and WP_DEBUG_DISPLAY on, where the request type used to change the answer.' );
+ }
+
+ $original = (string) ini_get( 'display_errors' );
+
+ try {
+ ini_set( 'display_errors', '1' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Disallowed
+ $html = $this->get_status()['system_status']['security']['hide_errors'];
+ ini_set( 'display_errors', '0' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Disallowed
+ $json = $this->get_status()['system_status']['security']['hide_errors'];
+ } finally {
+ ini_set( 'display_errors', $original ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Disallowed
+ }
+
+ $this->assertSame( $html, $json );
+ $this->assertFalse( $json, 'WP_DEBUG_DISPLAY shows errors to visitors.' );
+ }
+
+ /**
+ * @testdox Should report plugin headers as plain text, without HTML or links.
+ */
+ public function test_plugin_headers_are_plain_text(): void {
+ set_transient(
+ 'wc_system_status_active_plugins',
+ array(
+ array(
+ 'plugin' => 'anchor/anchor.php',
+ 'name' => '<code>Canary</code> Plugin',
+ 'version' => '1.0 <a href="https://anchor.example/v">notes</a>',
+ 'author_name' => '<a href="https://anchor.example/">Anchor & Co</a>',
+ ),
+ )
+ );
+ set_transient(
+ 'wc_system_status_inactive_plugins',
+ array(
+ array(
+ 'plugin' => 'raw/raw.php',
+ 'name' => 'Raw',
+ 'version' => '2.0',
+ 'author_name' => '<script>x</script>Raw Author',
+ ),
+ array(
+ 'plugin' => 'encoded/encoded.php',
+ 'name' => 'Encoded',
+ 'version' => '3.0',
+ 'author_name' => '<a href="https://anchor.example/e">Encoded Author</a>',
+ ),
+ )
+ );
+
+ $status = $this->get_status()['system_status'];
+ $active = array_column( $status['active_plugins'], null, 'plugin' )['anchor/anchor.php'];
+ $inactive = array_column( $status['inactive_plugins'], null, 'plugin' );
+ $json = (string) wp_json_encode( array( $active, $inactive ), JSON_UNESCAPED_SLASHES );
+
+ $this->assertSame( 'Canary Plugin', $active['name'] );
+ $this->assertSame( '1.0 notes', $active['version'] );
+ $this->assertSame( 'Anchor & Co', $active['author'] );
+ $this->assertSame( 'Raw Author', $inactive['raw/raw.php']['author'] );
+ $this->assertSame( 'Encoded Author', $inactive['encoded/encoded.php']['author'] );
+ $this->assertStringNotContainsString( 'anchor.example', $json );
+ $this->assertStringNotContainsString( '<', $json );
+ }
+
+ /**
+ * @testdox Should skip a wc_get_template result that is not a path.
+ */
+ public function test_ignores_non_string_template_filter_result(): void {
+ $return_array = static fn() => array();
+ add_filter( 'wc_get_template', $return_array );
+
+ try {
+ $result = $this->get_status();
+ } finally {
+ remove_filter( 'wc_get_template', $return_array );
+ }
+
+ $this->assertNotWPError( $result );
+ $this->assertFalse( $result['system_status']['theme']['has_outdated_templates'] );
+ }
+
+ /**
+ * @testdox Should report the parent theme name and version for a child theme.
+ */
+ public function test_child_theme_reports_parent(): void {
+ global $wp_theme_directories;
+
+ $root = get_temp_dir() . 'wc-system-status-themes-' . wp_generate_password( 8, false );
+ $original_theme = get_stylesheet();
+ $original_dirs = $wp_theme_directories;
+ $theme_headers = array(
+ 'wc-canary-parent' => "/*\nTheme Name: Canary Parent\nVersion: 2.0.0\n*/",
+ 'wc-canary-child' => "/*\nTheme Name: Canary Child\nTemplate: wc-canary-parent\nVersion: 1.0.0\n*/",
+ );
+ foreach ( $theme_headers as $slug => $header ) {
+ wp_mkdir_p( "$root/$slug" );
+ file_put_contents( "$root/$slug/style.css", $header ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
+ file_put_contents( "$root/$slug/index.php", '<?php' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
+ }
+
+ register_theme_directory( $root );
+ wp_clean_themes_cache();
+
+ try {
+ switch_theme( 'wc-canary-child' );
+ $theme = $this->get_status()['system_status']['theme'];
+ } finally {
+ switch_theme( $original_theme );
+ $wp_theme_directories = $original_dirs; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ wp_clean_themes_cache();
+ foreach ( array_keys( $theme_headers ) as $slug ) {
+ unlink( "$root/$slug/style.css" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
+ unlink( "$root/$slug/index.php" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
+ rmdir( "$root/$slug" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ }
+ rmdir( $root ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir
+ }
+
+ $this->assertSame( 'Canary Child', $theme['name'] );
+ $this->assertSame( 'Canary Parent', $theme['parent_name'] );
+ $this->assertSame( '2.0.0', $theme['parent_version'] );
+ }
+}