説明なし

wpcom-tos.php 928B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace Automattic\Jetpack\TOS;
  10. use Automattic\Jetpack\Connection\Client;
  11. /**
  12. * Makes a request to the WP.com legal endpoint to mark the Terms of Service as accepted.
  13. */
  14. function accept_tos() {
  15. check_ajax_referer( 'wp_ajax_action', '_nonce' );
  16. $response = Client::wpcom_json_api_request_as_user(
  17. '/legal',
  18. '2',
  19. array(
  20. 'method' => 'POST',
  21. ),
  22. array(
  23. 'action' => 'accept_tos',
  24. )
  25. );
  26. if ( is_wp_error( $response ) ) {
  27. wp_send_json_error( array( 'message' => __( 'Could not accept the Terms of Service. Please try again later.', 'jetpack' ) ) );
  28. wp_die();
  29. }
  30. wp_send_json_success( $response );
  31. wp_die();
  32. }
  33. add_action( 'wp_ajax_jetpack_accept_tos', __NAMESPACE__ . '\accept_tos' );