wpcom-tos.php
42 lines
| 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 | /** |
| 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( |
| 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 |