Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\TOS\accept_tos
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Handles acceptance of WordPress.com Terms of Service for sites connected to WP.com.
4 *
5 * This is auto-loaded as of Jetpack v8.3 for WP.com connected-sites only.
6 *
7 * @package automattic/jetpack
8 */
9
10namespace Automattic\Jetpack\TOS;
11
12use Automattic\Jetpack\Connection\Client;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18/**
19 * Makes a request to the WP.com legal endpoint to mark the Terms of Service as accepted.
20 */
21function accept_tos() {
22    check_ajax_referer( 'wp_ajax_action', '_nonce' );
23
24    $response = Client::wpcom_json_api_request_as_user(
25        '/legal',
26        '2',
27        array(
28            'method' => 'POST',
29        ),
30        array(
31            'action' => 'accept_tos',
32        )
33    );
34
35    if ( is_wp_error( $response ) ) {
36        // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
37        wp_send_json_error( array( 'message' => __( 'Could not accept the Terms of Service. Please try again later.', 'jetpack' ) ), null, JSON_UNESCAPED_SLASHES );
38        wp_die();
39    }
40
41    // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
42    wp_send_json_success( $response, null, JSON_UNESCAPED_SLASHES );
43
44    wp_die();
45}
46
47add_action( 'wp_ajax_jetpack_accept_tos', __NAMESPACE__ . '\accept_tos' );