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

178 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 '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' => __( 'Discover your new superpowers ', 'elementor' ),
98 'description' => __( '<p>With AI for text, code, image generation and editing, you can bring your vision to life faster than ever. Start your free trial now - <b>no credit card required!</b></p>', 'elementor' ),
99 'media' => [
100 'type' => 'image',
101 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png?' . ELEMENTOR_VERSION,
102 ],
103 'cta' => [
104 [
105 'label' => __( 'Let\'s do it', 'elementor' ),
106 'variant' => 'primary',
107 'target' => '_top',
108 'url' => '#welcome-ai',
109 ],
110 [
111 'label' => __( 'Skip', 'elementor' ),
112 'variant' => 'secondary',
113 ],
114 ],
115 'triggers' => [
116 [
117 'action' => 'aiStared',
118 ],
119 ],
120 ],
121 ];
122
123 // DO NOT USE THIS FILTER
124 return apply_filters( 'elementor/announcements/raw_announcements', $raw_announcements );
125 }
126
127 /**
128 * Retrieve all announcement objects.
129 *
130 * @return array
131 */
132 private function get_announcements(): array {
133 $announcements = [];
134 foreach ( $this->get_raw_announcements() as $announcement_data ) {
135 $announcements[] = new Announcement( $announcement_data );
136 }
137
138 return $announcements;
139 }
140
141 /**
142 * Retrieve all active announcement objects.
143 *
144 * @return array
145 */
146 private function get_active_announcements(): array {
147 $active_announcements = [];
148 foreach ( $this->get_announcements() as $announcement ) {
149 if ( $announcement->is_active() ) {
150 $active_announcements[] = $announcement;
151 }
152 }
153
154 return $active_announcements;
155 }
156
157 public function __construct() {
158 parent::__construct();
159
160 add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
161 }
162
163 public function on_elementor_init() {
164 if ( empty( $this->get_active_announcements() ) ) {
165 return;
166 }
167
168 add_action( 'elementor/editor/footer', function () {
169 $this->render_app_wrapper();
170 } );
171
172 add_action( 'elementor/editor/after_enqueue_scripts', function () {
173 $this->enqueue_scripts();
174 $this->enqueue_styles();
175 } );
176 }
177 }
178