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

180 lines 4.3 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 $raw_announcements = [
92 [
93 'title' => 'Unlock the Power of Elementor AI',
94 'description' => '<p>Design professional websites with natively integrated AI tools.</p>
95 <ul>
96 <li>Boost creativity & productivity with AI-generated containers. Build layouts from scratch or existing Elementor containers. Coming soon: Generate containers from any layout you reference from the web!</li>
97 <li>Let AI write or edit your text, adjust its length and tone of voice. Also generate custom code that seamlessly integrates into your website.</li>
98 <li>Create one-of-a kind images, add, or erase content in existing images or expand them beyond their original size and aspect ratio.</li>
99 <li>Access and repurpose previously-generated text, code or image prompts with Elementor’s AI History Panel to work efficiently and ensure consistency.</li>
100 </ul>',
101 'media' => [
102 'type' => 'image',
103 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png?' . ELEMENTOR_VERSION,
104 ],
105 'cta' => [
106 [
107 'label' => 'Continue',
108 'variant' => 'primary',
109 'target' => '_blank',
110 ],
111 [
112 'label' => 'Learn More',
113 'target' => '_blank',
114 'url' => 'https://go.elementor.com/whats-new-popup-learn-elementor-ai/',
115 ],
116 ],
117 'triggers' => [
118 [
119 'action' => 'aiStared',
120 ],
121 ],
122 ],
123 ];
124
125 // DO NOT USE THIS FILTER
126 return apply_filters( 'elementor/announcements/raw_announcements', $raw_announcements );
127 }
128
129 /**
130 * Retrieve all announcement objects.
131 *
132 * @return array
133 */
134 private function get_announcements(): array {
135 $announcements = [];
136 foreach ( $this->get_raw_announcements() as $announcement_data ) {
137 $announcements[] = new Announcement( $announcement_data );
138 }
139
140 return $announcements;
141 }
142
143 /**
144 * Retrieve all active announcement objects.
145 *
146 * @return array
147 */
148 private function get_active_announcements(): array {
149 $active_announcements = [];
150 foreach ( $this->get_announcements() as $announcement ) {
151 if ( $announcement->is_active() ) {
152 $active_announcements[] = $announcement;
153 }
154 }
155
156 return $active_announcements;
157 }
158
159 public function __construct() {
160 parent::__construct();
161
162 add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
163 }
164
165 public function on_elementor_init() {
166 if ( empty( $this->get_active_announcements() ) ) {
167 return;
168 }
169
170 add_action( 'elementor/editor/footer', function () {
171 $this->render_app_wrapper();
172 } );
173
174 add_action( 'elementor/editor/after_enqueue_scripts', function () {
175 $this->enqueue_scripts();
176 $this->enqueue_styles();
177 } );
178 }
179 }
180