home_url(), 'site_name' => get_bloginfo( 'name' ), 'wp_version' => get_bloginfo( 'version' ), 'wc_version' => defined( 'WC_VERSION' ) ? WC_VERSION : null, 'php_version' => PHP_VERSION, 'site_language' => get_locale(), ); } /** * Sends deactivation feedback. Non-blocking, never throws. * * @param array $args { * Feedback details. They are merged over site_info(), so any site_info() key can be overridden. * * @type string $plugin Canonical plugin name. Free and PRO must send the same value. * @type string $edition 'free' or 'pro'. * @type string $plugin_version Plugin version. * @type string $plugin_slug Plugin slug, for example 'woo-custom-product-addons'. * @type string $reason Short reason text (the option the user picked). * @type string $reason_details Free-text details. * @type string $name Name the user typed (optional, may be empty). * @type string $email Email the user typed (optional, may be empty). * @type bool $consent True only if the user ticked "Acowebs may contact me". * @type array $meta Optional custom data, shown as "Meta fields" in the dashboard, e.g. * array( 'website_name' => 'Shop X', 'active_theme' => 'Astra' ). * Flat: at most 30 keys (letters, numbers, _ . -), string (max 1000 * characters), number, bool or null values, 4 KB in total. Sent only * when it is a non-empty array. An invalid meta makes the API reject * the whole feedback, so pass only values you control. * } * @return void */ public static function send_deactivation( array $args ): void { try { $args = wp_parse_args( $args, array( 'plugin' => '', 'edition' => 'free', 'plugin_version' => '', 'plugin_slug' => '', 'reason' => '', 'reason_details' => '', 'name' => '', 'email' => '', 'consent' => false, ) ); $payload = array_merge( self::site_info(), $args ); // Required by the API. Skip silently rather than send a record that would be rejected. if ( '' === trim( (string) $payload['plugin'] ) || '' === trim( (string) $payload['site_url'] ) ) { return; } $payload['edition'] = strtolower( trim( (string) $payload['edition'] ) ); $payload['consent'] = (bool) $payload['consent']; // Optional custom data: only a non-empty array, sent as a JSON object (an empty PHP array would be "[]"). if ( isset( $payload['meta'] ) && is_array( $payload['meta'] ) && ! empty( $payload['meta'] ) ) { $payload['meta'] = (object) $payload['meta']; } else { unset( $payload['meta'] ); } // The API rejects null for text fields (for example wc_version without WooCommerce), and an empty // string is never a useful value (an empty email would fail validation). Leave both out. // `consent: false` is a boolean, so it is kept. $payload = array_filter( $payload, static function ( $value ) { return null !== $value && '' !== $value; } ); wp_remote_post( self::api_url() . '/v1/deactivation', array( 'method' => 'POST', 'timeout' => 5, 'blocking' => false, // Fire and forget: never wait for the API. 'redirection' => 0, 'headers' => array( 'Content-Type' => 'application/json', ), 'body' => wp_json_encode( $payload ), ) ); } catch ( \Throwable $e ) { // Feedback must never break deactivation. Ignore everything. return; } } } }