| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin\api; |
| 4 |
|
| 5 |
use Leadin\api\Base_Api_Controller; |
| 6 |
use Leadin\data\User_Metadata; |
| 7 |
|
| 8 |
/** |
| 9 |
* User meta review Api, used to set the user metadata. |
| 10 |
*/ |
| 11 |
class User_Meta_Api_Controller extends Base_Api_Controller { |
| 12 |
|
| 13 |
/** |
| 14 |
* Class constructor, register route. |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
self::register_leadin_route( |
| 18 |
'/skip-review', |
| 19 |
\WP_REST_Server::CREATABLE, |
| 20 |
array( $this, 'skip_review' ) |
| 21 |
); |
| 22 |
self::register_leadin_route( |
| 23 |
'/track-consent', |
| 24 |
\WP_REST_Server::CREATABLE, |
| 25 |
array( $this, 'track_consent' ) |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Skip Review. Sets SKIP_REVIEW meta data for a user with current datetime. |
| 31 |
*/ |
| 32 |
public function skip_review() { |
| 33 |
User_Metadata::set_skip_review( time() ); |
| 34 |
return new \WP_REST_Response( 'OK', 200 ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Used to set user consent on HubSpot anonymous tracking. |
| 39 |
* |
| 40 |
* @param array $request Request body. |
| 41 |
*/ |
| 42 |
public function track_consent( $request ) { |
| 43 |
$data = json_decode( $request->get_body(), true ); |
| 44 |
if ( array_key_exists( 'canTrack', $data ) ) { |
| 45 |
$consent = $data['canTrack']; |
| 46 |
User_Metadata::set_track_consent( $consent ? 'true' : 'false' ); |
| 47 |
} |
| 48 |
return new \WP_REST_Response( |
| 49 |
wp_json_encode( User_Metadata::get_track_consent(), true ), |
| 50 |
200 |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
|