| 1 |
<?php |
| 2 |
namespace Elementor\Core\Common\Modules\EventTracker\Data; |
| 3 |
|
| 4 |
use Elementor\Core\Common\Modules\Connect\Apps\Common_App; |
| 5 |
use Elementor\Core\Common\Modules\Connect\Apps\Library; |
| 6 |
use Elementor\Plugin; |
| 7 |
use WP_REST_Server; |
| 8 |
use Elementor\Data\V2\Base\Controller as Controller_Base; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
class Controller extends Controller_Base { |
| 15 |
|
| 16 |
public function get_name() { |
| 17 |
return 'send-event'; |
| 18 |
} |
| 19 |
|
| 20 |
public function register_endpoints() { |
| 21 |
$this->index_endpoint->register_items_route( \WP_REST_Server::CREATABLE, [ |
| 22 |
'event_data' => [ |
| 23 |
'description' => 'All the recorded event data in JSON format', |
| 24 |
'type' => 'object', |
| 25 |
'required' => true, |
| 26 |
], |
| 27 |
] ); |
| 28 |
} |
| 29 |
|
| 30 |
public function get_permission_callback( $request ) { |
| 31 |
// TODO: CHECK FOR NONCE |
| 32 |
if ( WP_REST_Server::CREATABLE !== $request->get_method() ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
return false; |
| 37 |
// TODO: CHANGE RETURN TO THE FOLLOWING, REMOVE RETURN TRUE |
| 38 |
//return current_user_can( 'manage_options' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function create_items( $request ) { |
| 42 |
$request_body = $request->get_json_params(); |
| 43 |
|
| 44 |
if ( empty( $request_body['event_data'] ) ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
/** @var Library $library */ |
| 49 |
$library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); |
| 50 |
|
| 51 |
if ( $library->is_connected() ) { |
| 52 |
$user_connect_data = get_user_option( get_current_user_id(), Common_App::OPTION_CONNECT_COMMON_DATA_KEY ); |
| 53 |
|
| 54 |
// TODO: add user meta client_id here |
| 55 |
$request_body['event_data']['connect_id'] = $user_connect_data['client_id']; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|