PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.1
Elementor Website Builder – more than just a page builder v3.13.1
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.13.1, at modules/announcements/module.php

197 lines 4.7 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 ELEMENTOR_VERSION,
47 true
48 );
49
50 $this->print_config( 'announcements-app' );
51 }
52
53 /**
54 * Get initialization settings to use in frontend.
55 *
56 * @return array[]
57 */
58 protected function get_init_settings(): array {
59 $active_announcements = $this->get_active_announcements();
60 $additional_settings = [];
61
62 foreach ( $active_announcements as $announcement ) {
63 $additional_settings[] = $announcement->get_prepared_data();
64 //@TODO - replace with ajax request from the front after actually triggered
65 $announcement->after_triggered();
66 }
67
68 return [
69 'announcements' => $additional_settings,
70 ];
71 }
72
73 /**
74 * Enqueue the module styles.
75 */
76 public function enqueue_styles() {
77 wp_enqueue_style(
78 'announcements-app',
79 $this->get_css_assets_url( 'modules/announcements/announcements' ),
80 [],
81 ELEMENTOR_VERSION
82 );
83 }
84
85 /**
86 * Retrieve all announcement in raw format ( array ).
87 *
88 * @return array[]
89 */
90 private function get_raw_announcements(): array {
91 return [
92 [
93 'title' => 'Create smarter with Elementor AI',
94 'description' => '<p>Instantly turn your ideas into original text and custom code with a free trial of Elementor AI installed on the newest versions of Elementor.</p>
95 <ul>
96 <li>Effortlessly write professional copy about any topic, in any tone. Then instantly translate it to twenty-five languages.</li>
97 <li>No code? No problem. Generate Custom Code, CSS, and HTML with a prompt</li>
98 <li>Coming soon: A picture might be worth a thousand words, but all you need is a short description to generate the perfect image for your site.</li>
99 </ul>',
100 'media' => [
101 'type' => 'image',
102 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png',
103 ],
104 'cta' => [
105 [
106 'label' => 'Continue',
107 'variant' => 'primary',
108 'target' => '_blank',
109 ],
110 [
111 'label' => 'Learn More',
112 'target' => '_blank',
113 'url' => 'https://go.elementor.com/whats-new-popup-learn-elementor-ai/',
114 ],
115 ],
116 'triggers' => [
117 [
118 'action' => 'aiStared',
119 ],
120 ],
121 ],
122 [
123 'title' => 'Activate Containers for Brilliant Layouts',
124 'description' => 'Take advantage of the full power of Containers in Elementor to create slick, pixel-perfect, responsive layouts, plus improve the performance of your website. Follow these steps: <strong>Switch Flexbox Container to ‘Active’ and Save.</strong>',
125 'media' => [
126 'type' => 'image',
127 'src' => ELEMENTOR_ASSETS_URL . 'images/containers-announcement.png',
128 ],
129 'cta' => [
130 [
131 'label' => 'Activate Container',
132 'variant' => 'primary',
133 'target' => '_blank',
134 'url' => ElementorSettings::get_url() . '#tab-experiments',
135 ],
136 [
137 'label' => 'Try It First',
138 'target' => '_blank',
139 'url' => 'https://go.elementor.com/whats-new-popup/',
140 ],
141 ],
142 'triggers' => [
143 [
144 'action' => 'isFlexContainerInactive',
145 ],
146 ],
147 ],
148 ];
149 }
150
151 /**
152 * Retrieve all announcement objects.
153 *
154 * @return array
155 */
156 private function get_announcements(): array {
157 $announcements = [];
158 foreach ( $this->get_raw_announcements() as $announcement_data ) {
159 $announcements[] = new Announcement( $announcement_data );
160 }
161
162 return $announcements;
163 }
164
165 /**
166 * Retrieve all active announcement objects.
167 *
168 * @return array
169 */
170 private function get_active_announcements(): array {
171 $active_announcements = [];
172 foreach ( $this->get_announcements() as $announcement ) {
173 if ( $announcement->is_active() ) {
174 $active_announcements[] = $announcement;
175 }
176 }
177
178 return $active_announcements;
179 }
180
181 public function __construct() {
182 if ( empty( $this->get_active_announcements() ) ) {
183 return;
184 }
185 parent::__construct();
186
187 add_action( 'elementor/editor/footer', function () {
188 $this->render_app_wrapper();
189 } );
190
191 add_action( 'elementor/editor/after_enqueue_scripts', function () {
192 $this->enqueue_scripts();
193 $this->enqueue_styles();
194 } );
195 }
196 }
197