| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Common\Modules\EventsManager; |
| 4 |
|
| 5 |
use Elementor\Core\Base\Module as BaseModule; |
| 6 |
use Elementor\Core\Common\Modules\Connect\Apps\Base_App; |
| 7 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 |
use Elementor\Includes\EditorAssetsAPI; |
| 9 |
use Elementor\Utils; |
| 10 |
use Elementor\Plugin; |
| 11 |
use Elementor\Tracker; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; // Exit if accessed directly. |
| 15 |
} |
| 16 |
|
| 17 |
class Module extends BaseModule { |
| 18 |
|
| 19 |
const EXPERIMENT_NAME = 'editor_events'; |
| 20 |
|
| 21 |
const REMOTE_MIXPANEL_CONFIG_URL = 'https://assets.elementor.com/mixpanel/v1/mixpanel.json'; |
| 22 |
|
| 23 |
public function get_name() { |
| 24 |
return 'events-manager'; |
| 25 |
} |
| 26 |
|
| 27 |
public static function get_editor_events_config() { |
| 28 |
$can_send_events = ! empty( ELEMENTOR_EDITOR_EVENTS_MIXPANEL_TOKEN ) && |
| 29 |
Tracker::is_allow_track() && |
| 30 |
! Tracker::has_terms_changed( '2025-07-07' ) && |
| 31 |
Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ); |
| 32 |
|
| 33 |
$is_flags_enabled = false; |
| 34 |
|
| 35 |
if ( $can_send_events ) { |
| 36 |
$mixpanel_config = self::get_remote_mixpanel_config(); |
| 37 |
$is_flags_enabled = EditorAssetsAPI::has_valid_nested_array( $mixpanel_config, [ 0 ] ) |
| 38 |
? (bool) ( $mixpanel_config[0]['flags'] ?? false ) |
| 39 |
: false; |
| 40 |
} |
| 41 |
|
| 42 |
$settings = [ |
| 43 |
'can_send_events' => $can_send_events, |
| 44 |
'elementor_version' => ELEMENTOR_VERSION, |
| 45 |
'site_url' => hash( 'sha256', get_site_url() ), |
| 46 |
'wp_version' => get_bloginfo( 'version' ), |
| 47 |
'user_agent' => esc_html( Utils::get_super_global_value( $_SERVER, 'HTTP_USER_AGENT' ) ), |
| 48 |
'site_language' => get_locale(), |
| 49 |
'site_key' => get_option( Base_App::OPTION_CONNECT_SITE_KEY ), |
| 50 |
'subscription_id' => self::get_subscription_id(), |
| 51 |
'subscription' => self::get_subscription(), |
| 52 |
'token' => ELEMENTOR_EDITOR_EVENTS_MIXPANEL_TOKEN, |
| 53 |
'flags_enabled' => $is_flags_enabled, |
| 54 |
]; |
| 55 |
|
| 56 |
return $settings; |
| 57 |
} |
| 58 |
|
| 59 |
public static function get_experimental_data(): array { |
| 60 |
return [ |
| 61 |
'name' => static::EXPERIMENT_NAME, |
| 62 |
'title' => esc_html__( 'Elementor Editor Events', 'elementor' ), |
| 63 |
'description' => esc_html__( 'Editor events processing', 'elementor' ), |
| 64 |
'hidden' => true, |
| 65 |
'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA, |
| 66 |
'default' => Experiments_Manager::STATE_INACTIVE, |
| 67 |
'new_site' => [ |
| 68 |
'default_active' => true, |
| 69 |
'minimum_installation_version' => '3.32.0', |
| 70 |
], |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
private static function get_subscription_id() { |
| 75 |
$subscription = self::get_subscription(); |
| 76 |
|
| 77 |
return $subscription['subscription_id'] ?? null; |
| 78 |
} |
| 79 |
|
| 80 |
private static function get_subscription() { |
| 81 |
if ( ! Utils::has_pro() ) { |
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
$license_data = get_option( '_elementor_pro_license_v2_data' ); |
| 86 |
if ( ! isset( $license_data['value'] ) ) { |
| 87 |
return null; |
| 88 |
} |
| 89 |
|
| 90 |
return json_decode( $license_data['value'], true ); |
| 91 |
} |
| 92 |
|
| 93 |
private static function get_remote_mixpanel_config() { |
| 94 |
$editor_assets_api = new EditorAssetsAPI( [ |
| 95 |
EditorAssetsAPI::ASSETS_DATA_URL => static::REMOTE_MIXPANEL_CONFIG_URL, |
| 96 |
EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_mixpanel_config', |
| 97 |
EditorAssetsAPI::ASSETS_DATA_KEY => 'mixpanel', |
| 98 |
] ); |
| 99 |
|
| 100 |
return $editor_assets_api->get_assets_data(); |
| 101 |
} |
| 102 |
} |
| 103 |
|