WC Tracker: Add info about features and plugin compatibility (#38613)

* Adds a data key with the list of WC features that are currently enabled on the site.
* Adds a feature_compat key to each plugin that shows its compatibility with each feature (compatible, incompatible, or uncertain) if the plugin is "WooCommerce aware", otherwise just an empty array.
This commit is contained in:
Corey McKrill 2023-06-14 12:40:41 -07:00 committed by GitHub
commit 3595622e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Adds info about features and plugin compatibility to the data collected by WC Tracker

View File

@ -12,8 +12,8 @@
use Automattic\Jetpack\Constants; use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore; use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil };
use Automattic\WooCommerce\Internal\Utilities\BlocksUtil; use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
use Automattic\WooCommerce\Utilities\OrderUtil;
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
@ -153,7 +153,6 @@ class WC_Tracker {
$data['inactive_plugins'] = $all_plugins['inactive_plugins']; $data['inactive_plugins'] = $all_plugins['inactive_plugins'];
// Jetpack & WooCommerce Connect. // Jetpack & WooCommerce Connect.
$data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none'; $data['jetpack_version'] = Constants::is_defined( 'JETPACK__VERSION' ) ? Constants::get_constant( 'JETPACK__VERSION' ) : 'none';
$data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no'; $data['jetpack_connected'] = ( class_exists( 'Jetpack' ) && is_callable( 'Jetpack::is_active' ) && Jetpack::is_active() ) ? 'yes' : 'no';
$data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no'; $data['jetpack_is_staging'] = self::is_jetpack_staging_site() ? 'yes' : 'no';
@ -177,6 +176,9 @@ class WC_Tracker {
// Shipping method info. // Shipping method info.
$data['shipping_methods'] = self::get_active_shipping_methods(); $data['shipping_methods'] = self::get_active_shipping_methods();
// Features.
$data['enabled_features'] = self::get_enabled_features();
// Get all WooCommerce options info. // Get all WooCommerce options info.
$data['settings'] = self::get_all_woocommerce_options_values(); $data['settings'] = self::get_all_woocommerce_options_values();
@ -329,6 +331,10 @@ class WC_Tracker {
if ( isset( $v['PluginURI'] ) ) { if ( isset( $v['PluginURI'] ) ) {
$formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] ); $formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] );
} }
$formatted['feature_compatibility'] = array();
if ( wc_get_container()->get( PluginUtil::class )->is_woocommerce_aware_plugin( $k ) ) {
$formatted['feature_compatibility'] = array_filter( FeaturesUtil::get_compatible_features_for_plugin( $k ) );
}
if ( in_array( $k, $active_plugins_keys, true ) ) { if ( in_array( $k, $active_plugins_keys, true ) ) {
// Remove active plugins from list so we can show active and inactive separately. // Remove active plugins from list so we can show active and inactive separately.
unset( $plugins[ $k ] ); unset( $plugins[ $k ] );
@ -904,6 +910,23 @@ class WC_Tracker {
return $active_methods; return $active_methods;
} }
/**
* Get an array of slugs for WC features that are enabled on the site.
*
* @return string[]
*/
private static function get_enabled_features() {
$all_features = FeaturesUtil::get_features( true, true );
$enabled_features = array_filter(
$all_features,
function( $feature ) {
return $feature['is_enabled'];
}
);
return array_keys( $enabled_features );
}
/** /**
* Get all options starting with woocommerce_ prefix. * Get all options starting with woocommerce_ prefix.
* *

View File

@ -118,4 +118,13 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case {
$this->assertEquals( ( $order_count / count( $created_via_entries ) ), $order_data['created_via'][ $created_via_entry ] ); $this->assertEquals( ( $order_count / count( $created_via_entries ) ), $order_data['created_via'][ $created_via_entry ] );
} }
} }
/**
* @testDox Test enabled features tracking data.
*/
public function test_get_tracking_data_enabled_features() {
$tracking_data = WC_Tracker::get_tracking_data();
$this->assertIsArray( $tracking_data['enabled_features'] );
}
} }