PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.0-dev3
Elementor Website Builder – more than just a page builder v3.20.0-dev3
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 / modules / announcements / module.php

module.php in Elementor Website Builder – more than just a page builder 3.20.0-dev3, at modules/announcements/module.php

184 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Announcements;
4
5 use Elementor\Core\Base\App as BaseApp;
6 use Elementor\Modules\Announcements\Classes\Announcement;
7 use Elementor\Settings as ElementorSettings;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Module extends BaseApp {
14
15 /**
16 * @return bool
17 */
18 public static function is_active(): bool {
19 return is_admin();
20 }
21
22 /**
23 * @return string
24 */
25 public function get_name(): string {
26 return 'announcements';
27 }
28
29 /**
30 * Render wrapper for the app to load.
31 */
32 private function render_app_wrapper() {
33 ?>
34 <div id="e-announcements-root"></div>
35 <?php
36 }
37
38 /**
39 * Enqueue app scripts.
40 */
41 private function enqueue_scripts() {
42 wp_enqueue_script(
43 'announcements-app',
44 $this->get_js_assets_url( 'announcements-app' ),
45 [
46 'wp-i18n',
47 ],
48 ELEMENTOR_VERSION,
49 true
50 );
51
52 wp_set_script_translations( 'announcements-app', 'elementor' );
53
54 $this->print_config( 'announcements-app' );
55 }
56
57 /**
58 * Get initialization settings to use in frontend.
59 *
60 * @return array[]
61 */
62 protected function get_init_settings(): array {
63 $active_announcements = $this->get_active_announcements();
64 $additional_settings = [];
65
66 foreach ( $active_announcements as $announcement ) {
67 $additional_settings[] = $announcement->get_prepared_data();
68 //@TODO - replace with ajax request from the front after actually triggered
69 $announcement->after_triggered();
70 }
71
72 return [
73 'announcements' => $additional_settings,
74 ];
75 }
76
77 /**
78 * Enqueue the module styles.
79 */
80 public function enqueue_styles() {
81 wp_enqueue_style(
82 'announcements-app',
83 $this->get_css_assets_url( 'modules/announcements/announcements' ),
84 [],
85 ELEMENTOR_VERSION
86 );
87 }
88
89 /**
90 * Retrieve all announcement in raw format ( array ).
91 *
92 * @return array[]
93 */
94 private function get_raw_announcements(): array {
95 $raw_announcements = [
96 [
97 'title' => 'Unlock the Power of Elementor AI ',
98 'description' => '<p>Design a website true to your brand with natively integrated AI tools.</p>
99 <ul>
100 <li>Generate containers using text or any website you reference from the web and get a wireframe layout to start with. Use the container variations capability to bring the wireframe to life with design and content.</li>
101 <li>Let AI write or edit your text in the context of your brand, tone of voice and optimal length. Also generate custom code or CSS that seamlessly integrates into your website.</li>
102 <li>Create one-of-a-kind images, add, or erase content from existing images or expand them beyond their original size and aspect ratio.</li>
103 <li>Use Elementor’s AI History Panel to efficiently access previously-generated text, code or image prompts, and ensure consistency across your site.</li>
104 </ul>',
105 'media' => [
106 'type' => 'image',
107 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png?' . ELEMENTOR_VERSION,
108 ],
109 'cta' => [
110 [
111 'label' => 'Continue',
112 'variant' => 'primary',
113 'target' => '_blank',
114 ],
115 [
116 'label' => 'Learn More',
117 'target' => '_blank',
118 'url' => 'https://go.elementor.com/whats-new-popup-learn-elementor-ai/',
119 ],
120 ],
121 'triggers' => [
122 [
123 'action' => 'aiStared',
124 ],
125 ],
126 ],
127 ];
128
129 // DO NOT USE THIS FILTER
130 return apply_filters( 'elementor/announcements/raw_announcements', $raw_announcements );
131 }
132
133 /**
134 * Retrieve all announcement objects.
135 *
136 * @return array
137 */
138 private function get_announcements(): array {
139 $announcements = [];
140 foreach ( $this->get_raw_announcements() as $announcement_data ) {
141 $announcements[] = new Announcement( $announcement_data );
142 }
143
144 return $announcements;
145 }
146
147 /**
148 * Retrieve all active announcement objects.
149 *
150 * @return array
151 */
152 private function get_active_announcements(): array {
153 $active_announcements = [];
154 foreach ( $this->get_announcements() as $announcement ) {
155 if ( $announcement->is_active() ) {
156 $active_announcements[] = $announcement;
157 }
158 }
159
160 return $active_announcements;
161 }
162
163 public function __construct() {
164 parent::__construct();
165
166 add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
167 }
168
169 public function on_elementor_init() {
170 if ( empty( $this->get_active_announcements() ) ) {
171 return;
172 }
173
174 add_action( 'elementor/editor/footer', function () {
175 $this->render_app_wrapper();
176 } );
177
178 add_action( 'elementor/editor/after_enqueue_scripts', function () {
179 $this->enqueue_scripts();
180 $this->enqueue_styles();
181 } );
182 }
183 }
184