@@ -40,6 +40,7 @@ public function __construct( WC_Payments_API_Client $payments_api_client ) {
40
40
public function init_hooks () {
41
41
add_action ( 'woocommerce_payments_account_refreshed ' , [ $ this , 'update_compatibility_data ' ] );
42
42
add_action ( 'after_switch_theme ' , [ $ this , 'update_compatibility_data ' ] );
43
+ add_filter ( 'wc_payments_get_onboarding_data_args ' , [ $ this , 'add_compatibility_onboarding_data ' ] );
43
44
}
44
45
45
46
/**
@@ -48,27 +49,47 @@ public function init_hooks() {
48
49
* @return void
49
50
*/
50
51
public function update_compatibility_data () {
51
- $ active_plugins = get_option ( 'active_plugins ' , [] );
52
- $ post_types_count = $ this ->get_post_types_count ();
53
52
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 () );
63
54
} catch ( API_Exception $ e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
64
55
// The exception is already logged if logging is on, nothing else needed.
65
56
}
66
57
}
67
58
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
+
68
89
/**
69
90
* Gets the count of public posts for each post type.
70
91
*
71
- * @return array<\WP_Post_Type|string, string >
92
+ * @return array<\WP_Post_Type|string, int >
72
93
*/
73
94
private function get_post_types_count (): array {
74
95
$ post_types = get_post_types (
@@ -80,10 +101,9 @@ private function get_post_types_count(): array {
80
101
$ post_types_count = [];
81
102
82
103
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 ;
84
105
}
85
106
86
107
return $ post_types_count ;
87
-
88
108
}
89
109
}
0 commit comments