PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.0-beta1
Elementor Website Builder – more than just a page builder v3.13.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
elementor / modules / announcements / module.php

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

167 lines 3.6 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' => 'Activate Containers for Brilliant Layouts',
94 '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>',
95 'media' => [
96 'type' => 'image',
97 'src' => ELEMENTOR_ASSETS_URL . 'images/announcement.png',
98 ],
99 'cta' => [
100 [
101 'label' => 'Activate Containers',
102 'variant' => 'primary',
103 'target' => '_blank',
104 'url' => ElementorSettings::get_url() . '#tab-experiments',
105 ],
106 [
107 'label' => 'Try It First',
108 'target' => '_blank',
109 'url' => 'https://go.elementor.com/whats-new-popup/',
110 ],
111 ],
112 'triggers' => [
113 [
114 'action' => 'isFlexContainerInactive',
115 ],
116 ],
117 ],
118 ];
119 }
120
121 /**
122 * Retrieve all announcement objects.
123 *
124 * @return array
125 */
126 private function get_announcements(): array {
127 $announcements = [];
128 foreach ( $this->get_raw_announcements() as $announcement_data ) {
129 $announcements[] = new Announcement( $announcement_data );
130 }
131
132 return $announcements;
133 }
134
135 /**
136 * Retrieve all active announcement objects.
137 *
138 * @return array
139 */
140 private function get_active_announcements(): array {
141 $active_announcements = [];
142 foreach ( $this->get_announcements() as $announcement ) {
143 if ( $announcement->is_active() ) {
144 $active_announcements[] = $announcement;
145 }
146 }
147
148 return $active_announcements;
149 }
150
151 public function __construct() {
152 if ( empty( $this->get_active_announcements() ) ) {
153 return;
154 }
155 parent::__construct();
156
157 add_action( 'elementor/editor/footer', function () {
158 $this->render_app_wrapper();
159 } );
160
161 add_action( 'elementor/editor/after_enqueue_scripts', function () {
162 $this->enqueue_scripts();
163 $this->enqueue_styles();
164 } );
165 }
166 }
167