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

171 lines 3.8 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' => 'Picture perfect: Introducing the AI image generator',
94 'description' => '<p>Generate new images or edit existing ones with text to image prompts.</p>
95 <ul>
96 <li>Use generative fill to edit, add, or erase content in existing images or expand them beyond their original size and aspect ratio.</li>
97 <li>Choose from twenty-nine preset styles that will supercharge your prompts and check out the image-prompt gallery for inspiration. </li>
98 <li>Create custom code, write content, and generate images with Elementor’s comprehensive AI toolbox.</li>
99 </ul>',
100 'media' => [
101 'type' => 'image',
102 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png?' . ELEMENTOR_VERSION,
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 }
124
125 /**
126 * Retrieve all announcement objects.
127 *
128 * @return array
129 */
130 private function get_announcements(): array {
131 $announcements = [];
132 foreach ( $this->get_raw_announcements() as $announcement_data ) {
133 $announcements[] = new Announcement( $announcement_data );
134 }
135
136 return $announcements;
137 }
138
139 /**
140 * Retrieve all active announcement objects.
141 *
142 * @return array
143 */
144 private function get_active_announcements(): array {
145 $active_announcements = [];
146 foreach ( $this->get_announcements() as $announcement ) {
147 if ( $announcement->is_active() ) {
148 $active_announcements[] = $announcement;
149 }
150 }
151
152 return $active_announcements;
153 }
154
155 public function __construct() {
156 if ( empty( $this->get_active_announcements() ) ) {
157 return;
158 }
159 parent::__construct();
160
161 add_action( 'elementor/editor/footer', function () {
162 $this->render_app_wrapper();
163 } );
164
165 add_action( 'elementor/editor/after_enqueue_scripts', function () {
166 $this->enqueue_scripts();
167 $this->enqueue_styles();
168 } );
169 }
170 }
171