PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.2
Elementor Website Builder – more than just a page builder v4.2.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / app / modules / site-builder / module.php

module.php in Elementor Website Builder – more than just a page builder 4.2.2, at app/modules/site-builder/module.php

102 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\SiteBuilder;
3
4 use Elementor\App\Modules\SiteBuilder\Connect\App;
5 use Elementor\App\Modules\SiteBuilder\Rest\Rest_Api;
6 use Elementor\App\Modules\SiteBuilder\Services\Connect_Auth_Service;
7 use Elementor\Core\Base\Module as BaseModule;
8 use Elementor\Plugin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 class Module extends BaseModule {
15
16 public function get_name() {
17 return 'site-builder';
18 }
19
20 public function __construct() {
21 parent::__construct();
22
23 $this->register_experiment();
24
25 if ( ! $this->is_experiment_active() ) {
26 return;
27 }
28
29 add_action( 'elementor/init', [ $this, 'on_elementor_init' ], 12 );
30
31 add_action( 'elementor/connect/apps/register', function ( $connect_module ) {
32 $connect_module->register_app( 'site-builder', App::get_class_name() );
33 } );
34
35 add_action( 'rest_api_init', function () {
36 ( new Rest_Api() )->register_routes();
37 } );
38 }
39
40 private function register_experiment() {
41 Plugin::instance()->experiments->add_feature([
42 'name' => 'site-builder',
43 'title' => esc_html__( 'Site Builder', 'elementor' ),
44 'description' => esc_html__( 'Enable Site Builder.', 'elementor' ),
45 'release_status' => Plugin::$instance->experiments::RELEASE_STATUS_DEV,
46 'hidden' => true,
47 ]);
48 }
49
50 private function is_experiment_active(): bool {
51 return Plugin::$instance->experiments->is_feature_active( 'site-builder' );
52 }
53
54 public function on_elementor_init() {
55 if ( ! Plugin::instance()->app->is_current() ) {
56 return;
57 }
58
59 $settings = [
60 'iframeUrl' => $this->get_iframe_url(),
61 'isAdmin' => current_user_can( 'manage_options' ),
62 'exitTo' => admin_url( 'admin.php?page=elementor' ),
63 'elementorAiCurrentContext' => $this->get_elementor_ai_current_context(),
64 ];
65
66 Plugin::$instance->app->set_settings( 'site-builder', $settings );
67 }
68
69 private function get_elementor_ai_current_context(): array {
70 $choices = get_option( 'elementor_onboarding_choices', [] );
71 $site_about = $choices['site_about'] ?? [];
72 return [
73 'siteTitle' => (string) get_bloginfo( 'name' ),
74 'siteAbout' => $site_about,
75 ];
76 }
77
78 private function get_iframe_url(): string {
79 if ( defined( 'ELEMENTOR_SITE_BUILDER_IFRAME_URL' ) ) {
80 return ELEMENTOR_SITE_BUILDER_IFRAME_URL;
81 }
82
83 return 'https://planner.elementor.com/chat.html';
84 }
85
86 public function get_config(): ?array {
87 if ( ! $this->is_experiment_active() ) {
88 return null;
89 }
90
91 $connect_auth = ( new Connect_Auth_Service() )->get_connect_auth();
92
93 if ( ! $connect_auth ) {
94 return [];
95 }
96
97 return [
98 'siteKey' => $connect_auth['siteKey'],
99 ];
100 }
101 }
102