Skip to content

Commit

Permalink
Internal: AI - Prepare for installing AI kits
Browse files Browse the repository at this point in the history
  • Loading branch information
matipojo committed Dec 5, 2024
1 parent 121cdb5 commit a397b54
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/modules/import-export/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ private function handle_import_kit__runner() {
);
}

do_action( 'elementor/import-export/import-kit/runner/after-run', $import );

wp_send_json_success( $import );
}

Expand Down
26 changes: 26 additions & 0 deletions modules/ai/connect/ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ public function get_remote_frontend_config( $data ) {
);
}

/**
* @param array $event_data {
* @type string $name
* @type array $data
* @type array $client {
* @type string $name
* @type string $version
* @type string $session_id
* }
* }
*/
public function send_event(array $event_data ): void{
$this->ai_request(
'POST',
'client-events/events',
[
'payload' => $event_data,
'api_version' => ELEMENTOR_VERSION,
'site_lang' => get_bloginfo( 'language' ),
],
false,
'',
'json'
);
}

/**
* get_file_payload
* @param $filename
Expand Down
37 changes: 37 additions & 0 deletions modules/ai/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Elementor\Plugin;
use Elementor\Core\Utils\Collection;
use Elementor\Modules\Ai\Connect\Ai;
use Elementor\Tracker;
use Elementor\User;
use Elementor\Utils;

Expand Down Expand Up @@ -39,6 +40,7 @@ public function __construct() {

if ( is_admin() ) {
( new Preferences() )->register();
add_action( 'elementor/import-export/import-kit/runner/after-run', [ $this, 'handle_kit_install' ] );
}

if ( ! Plugin::$instance->experiments->is_feature_active( 'container' ) ) {
Expand Down Expand Up @@ -165,6 +167,41 @@ public function __construct() {
add_action( 'elementor/element/common/_section_transform/after_section_end', [ $this, 'register_ai_hover_effect_control' ], 10, 1 );
}

public function handle_kit_install( $imported_data ) {
if ( $imported_data['status'] !== 'success' ) {
return;
}

if ( $imported_data['runner'] !== 'site-settings' ) {
return;
}

$is_connected = $this->get_ai_app()->is_connected() && User::get_introduction_meta( 'ai_get_started' );

if ( ! Tracker::is_allow_track() && ! $is_connected ) {
return;
}

if ( ! isset( $imported_data['configData']['lastImportedSession']['instance_data']['site_settings']['settings']['ai'] ) ) {
return;
}

$lastImportedSession = $imported_data['configData']['lastImportedSession'];
$imported_ai_data = $lastImportedSession['instance_data']['site_settings']['settings']['ai'];

if ( $is_connected ) {
$this->get_ai_app()->send_event( [
'name' => 'kit_installed',
'data' => $imported_ai_data,
'client' => [
'name' => 'elementor',
'version' => ELEMENTOR_VERSION,
'session_id' => $lastImportedSession['session_id'],
],
] );
}
}

public function register_ai_hover_effect_control( Element_Base $element ) {
if ( ! $element->get_controls( 'ai_hover_animation' ) ) {
$element->add_control(
Expand Down

0 comments on commit a397b54

Please sign in to comment.