abilities
3 months ago
connectors
2 months ago
health
2 months ago
identity-crisis
2 months ago
sso
2 months ago
traits
9 months ago
webhooks
9 months ago
class-authorize-json-api.php
2 months ago
class-client.php
8 months ago
class-connection-assets.php
1 year ago
class-connection-notice.php
8 months ago
class-error-handler.php
3 weeks ago
class-external-storage.php
4 months ago
class-heartbeat.php
1 month ago
class-initial-state.php
1 month ago
class-manager.php
3 weeks ago
class-nonce-handler.php
9 months ago
class-package-version-tracker.php
2 months ago
class-package-version.php
3 weeks ago
class-partner-coupon.php
3 months ago
class-partner.php
2 years ago
class-plugin-storage.php
8 months ago
class-plugin.php
9 months ago
class-rest-authentication.php
9 months ago
class-rest-connector.php
1 month ago
class-secrets.php
9 months ago
class-server-sandbox.php
3 months ago
class-site-health.php
2 months ago
class-terms-of-service.php
2 years ago
class-tokens-locks.php
9 months ago
class-tokens.php
9 months ago
class-tracking.php
3 months ago
class-urls.php
6 months ago
class-user-account-status.php
9 months ago
class-users-connection-admin.php
2 months ago
class-utils.php
2 years ago
class-webhooks.php
2 months ago
class-xmlrpc-async-call.php
2 years ago
class-xmlrpc-connector.php
9 months ago
interface-manager.php
4 years ago
interface-storage-provider.php
6 months ago
class-terms-of-service.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * A Terms of Service class for Jetpack. |
| 4 | * |
| 5 | * @package automattic/jetpack-connection |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack; |
| 9 | |
| 10 | /** |
| 11 | * Class Terms_Of_Service |
| 12 | * |
| 13 | * Helper class that is responsible for the state of agreement of the terms of service. |
| 14 | */ |
| 15 | class Terms_Of_Service { |
| 16 | /** |
| 17 | * Jetpack option name where the terms of service state is stored. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | const OPTION_NAME = 'tos_agreed'; |
| 22 | |
| 23 | /** |
| 24 | * Allow the site to agree to the terms of service. |
| 25 | */ |
| 26 | public function agree() { |
| 27 | $this->set_agree(); |
| 28 | /** |
| 29 | * Acton fired when the master user has agreed to the terms of service. |
| 30 | * |
| 31 | * @since 1.0.4 |
| 32 | * @since-jetpack 7.9.0 |
| 33 | */ |
| 34 | do_action( 'jetpack_agreed_to_terms_of_service' ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Allow the site to reject to the terms of service. |
| 39 | */ |
| 40 | public function reject() { |
| 41 | $this->set_reject(); |
| 42 | /** |
| 43 | * Acton fired when the master user has revoked their agreement to the terms of service. |
| 44 | * |
| 45 | * @since 1.0.4 |
| 46 | * @since-jetpack 7.9.1 |
| 47 | */ |
| 48 | do_action( 'jetpack_reject_terms_of_service' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns whether the master user has agreed to the terms of service. |
| 53 | * |
| 54 | * The following conditions have to be met in order to agree to the terms of service. |
| 55 | * 1. The master user has gone though the connect flow. |
| 56 | * 2. The site is not in dev mode. |
| 57 | * 3. The master user of the site is still connected (deprecated @since 1.4.0). |
| 58 | * |
| 59 | * @return bool |
| 60 | */ |
| 61 | public function has_agreed() { |
| 62 | if ( $this->is_offline_mode() ) { |
| 63 | return false; |
| 64 | } |
| 65 | /** |
| 66 | * Before 1.4.0 we used to also check if the master user of the site is connected |
| 67 | * by calling the Connection related `is_active` method. |
| 68 | * As of 1.4.0 we have removed this check in order to resolve the |
| 69 | * circular dependencies it was introducing to composer packages. |
| 70 | * |
| 71 | * @since 1.4.0 |
| 72 | */ |
| 73 | return $this->get_raw_has_agreed(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Abstracted for testing purposes. |
| 78 | * Tells us if the site is in dev mode. |
| 79 | * |
| 80 | * @return bool |
| 81 | */ |
| 82 | protected function is_offline_mode() { |
| 83 | return ( new Status() )->is_offline_mode(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Gets just the Jetpack Option that contains the terms of service state. |
| 88 | * Abstracted for testing purposes. |
| 89 | * |
| 90 | * @return bool |
| 91 | */ |
| 92 | protected function get_raw_has_agreed() { |
| 93 | return \Jetpack_Options::get_option( self::OPTION_NAME, false ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sets the correct Jetpack Option to mark the that the site has agreed to the terms of service. |
| 98 | * Abstracted for testing purposes. |
| 99 | */ |
| 100 | protected function set_agree() { |
| 101 | \Jetpack_Options::update_option( self::OPTION_NAME, true ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Sets the correct Jetpack Option to mark that the site has rejected the terms of service. |
| 106 | * Abstracted for testing purposes. |
| 107 | */ |
| 108 | protected function set_reject() { |
| 109 | \Jetpack_Options::update_option( self::OPTION_NAME, false ); |
| 110 | } |
| 111 | } |
| 112 |