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

152 lines 3.1 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 // DO NOT USE THIS FILTER
98 return apply_filters( 'elementor/announcements/raw_announcements', $raw_announcements );
99 }
100
101 /**
102 * Retrieve all announcement objects.
103 *
104 * @return array
105 */
106 private function get_announcements(): array {
107 $announcements = [];
108 foreach ( $this->get_raw_announcements() as $announcement_data ) {
109 $announcements[] = new Announcement( $announcement_data );
110 }
111
112 return $announcements;
113 }
114
115 /**
116 * Retrieve all active announcement objects.
117 *
118 * @return array
119 */
120 private function get_active_announcements(): array {
121 $active_announcements = [];
122 foreach ( $this->get_announcements() as $announcement ) {
123 if ( $announcement->is_active() ) {
124 $active_announcements[] = $announcement;
125 }
126 }
127
128 return $active_announcements;
129 }
130
131 public function __construct() {
132 parent::__construct();
133
134 add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
135 }
136
137 public function on_elementor_init() {
138 if ( empty( $this->get_active_announcements() ) ) {
139 return;
140 }
141
142 add_action( 'elementor/editor/footer', function () {
143 $this->render_app_wrapper();
144 } );
145
146 add_action( 'elementor/editor/after_enqueue_scripts', function () {
147 $this->enqueue_scripts();
148 $this->enqueue_styles();
149 } );
150 }
151 }
152