| 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 |
|
| 10 |
namespace Automattic\Jetpack\TOS; |
| 11 |
|
| 12 |
use Automattic\Jetpack\Connection\Client; |
| 13 |
|
| 14 |
if ( ! 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 |
*/ |
| 21 |
function 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 |
} |
| 39 |
|
| 40 |
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int. |
| 41 |
wp_send_json_success( $response, null, JSON_UNESCAPED_SLASHES ); |
| 42 |
} |
| 43 |
|
| 44 |
add_action( 'wp_ajax_jetpack_accept_tos', __NAMESPACE__ . '\accept_tos' ); |
| 45 |
|