Skip to content

Commit c4f63db

Browse files
authored
Add compatibility data when onboarding (#7990)
1 parent edf69a5 commit c4f63db

File tree

4 files changed

+232
-83
lines changed

4 files changed

+232
-83
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: add
3+
4+
Add compatibility data to onboarding init payload.

includes/class-compatibility-service.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function __construct( WC_Payments_API_Client $payments_api_client ) {
4040
public function init_hooks() {
4141
add_action( 'woocommerce_payments_account_refreshed', [ $this, 'update_compatibility_data' ] );
4242
add_action( 'after_switch_theme', [ $this, 'update_compatibility_data' ] );
43+
add_filter( 'wc_payments_get_onboarding_data_args', [ $this, 'add_compatibility_onboarding_data' ] );
4344
}
4445

4546
/**
@@ -48,27 +49,47 @@ public function init_hooks() {
4849
* @return void
4950
*/
5051
public function update_compatibility_data() {
51-
$active_plugins = get_option( 'active_plugins', [] );
52-
$post_types_count = $this->get_post_types_count();
5352
try {
54-
$this->payments_api_client->update_compatibility_data(
55-
[
56-
'woopayments_version' => WCPAY_VERSION_NUMBER,
57-
'woocommerce_version' => WC_VERSION,
58-
'blog_theme' => get_stylesheet(),
59-
'active_plugins' => $active_plugins,
60-
'post_types_count' => $post_types_count,
61-
]
62-
);
53+
$this->payments_api_client->update_compatibility_data( $this->get_compatibility_data() );
6354
} catch ( API_Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
6455
// The exception is already logged if logging is on, nothing else needed.
6556
}
6657
}
6758

59+
/**
60+
* Adds the compatibility data to the onboarding args.
61+
*
62+
* @param array $args The args being sent when onboarding.
63+
*
64+
* @return array
65+
*/
66+
public function add_compatibility_onboarding_data( $args ): array {
67+
$args['compatibility_data'] = $this->get_compatibility_data();
68+
return $args;
69+
}
70+
71+
/**
72+
* Gets the compatibility data.
73+
*
74+
* @return array
75+
*/
76+
private function get_compatibility_data(): array {
77+
$active_plugins = get_option( 'active_plugins', [] );
78+
$post_types_count = $this->get_post_types_count();
79+
80+
return [
81+
'woopayments_version' => WCPAY_VERSION_NUMBER,
82+
'woocommerce_version' => WC_VERSION,
83+
'blog_theme' => get_stylesheet(),
84+
'active_plugins' => $active_plugins,
85+
'post_types_count' => $post_types_count,
86+
];
87+
}
88+
6889
/**
6990
* Gets the count of public posts for each post type.
7091
*
71-
* @return array<\WP_Post_Type|string, string>
92+
* @return array<\WP_Post_Type|string, int>
7293
*/
7394
private function get_post_types_count(): array {
7495
$post_types = get_post_types(
@@ -80,10 +101,9 @@ private function get_post_types_count(): array {
80101
$post_types_count = [];
81102

82103
foreach ( $post_types as $post_type ) {
83-
$post_types_count[ $post_type ] = wp_count_posts( $post_type )->publish;
104+
$post_types_count[ $post_type ] = (int) wp_count_posts( $post_type )->publish;
84105
}
85106

86107
return $post_types_count;
87-
88108
}
89109
}

0 commit comments

Comments
 (0)