Completed
Push — fix/submit-button-colours ( 6bc57e...e6b2bf )
by
unknown
37:58 queued 30:47
created

wpcom-tos.php ➔ accept_tos()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
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 Jetpack
8
 */
9
10
namespace Automattic\Jetpack\TOS;
11
12
use Automattic\Jetpack\Connection\Client;
13
14
/**
15
 * Makes a request to the WP.com legal endpoint to mark the Terms of Service as accepted.
16
 */
17
function accept_tos() {
18
	check_ajax_referer( 'wp_ajax_action', '_nonce' );
19
20
	$response = Client::wpcom_json_api_request_as_user(
21
		'/legal',
22
		'2',
23
		array(
24
			'method' => 'POST',
25
		),
26
		array(
0 ignored issues
show
Documentation introduced by
array('action' => 'accept_tos') is of type array<string,string,{"action":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
			'action' => 'accept_tos',
28
		)
29
	);
30
31
	if ( is_wp_error( $response ) ) {
32
		wp_send_json_error( array( 'message' => __( 'Could not accept the Terms of Service. Please try again later.', 'jetpack' ) ) );
33
		wp_die();
34
	}
35
36
	wp_send_json_success( $response );
37
38
	wp_die();
39
}
40
41
add_action( 'wp_ajax_jetpack_accept_tos', __NAMESPACE__ . '\accept_tos' );
42