| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\AI_Consent\Application; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Helpers\User_Helper; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Consent_Handler |
| 9 |
* Handles the consent given or revoked by the user. |
| 10 |
* |
| 11 |
* @makePublic |
| 12 |
*/ |
| 13 |
class Consent_Handler implements Consent_Handler_Interface { |
| 14 |
|
| 15 |
/** |
| 16 |
* Holds the user helper instance. |
| 17 |
* |
| 18 |
* @var User_Helper |
| 19 |
*/ |
| 20 |
private $user_helper; |
| 21 |
|
| 22 |
/** |
| 23 |
* Class constructor. |
| 24 |
* |
| 25 |
* @param User_Helper $user_helper The user helper. |
| 26 |
*/ |
| 27 |
public function __construct( User_Helper $user_helper ) { |
| 28 |
$this->user_helper = $user_helper; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Handles consent revoked by deleting the consent user metadata from the database. |
| 33 |
* |
| 34 |
* @param int $user_id The user ID. |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function revoke_consent( int $user_id ) { |
| 39 |
$this->user_helper->delete_meta( $user_id, '_yoast_wpseo_ai_consent' ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Handles consent granted by adding the consent user metadata to the database. |
| 44 |
* |
| 45 |
* @param int $user_id The user ID. |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function grant_consent( int $user_id ) { |
| 50 |
$this->user_helper->update_meta( $user_id, '_yoast_wpseo_ai_consent', true ); |
| 51 |
} |
| 52 |
} |
| 53 |
|