PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.4
Elementor Website Builder – more than just a page builder v3.1.4
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 / core / admin / notices / elementor-dev-notice.php

elementor-dev-notice.php in Elementor Website Builder – more than just a page builder 3.1.4, at core/admin/notices/elementor-dev-notice.php

178 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin\Notices;
3
4 use Elementor\User;
5 use Elementor\Plugin;
6 use Elementor\Core\Experiments\Manager as Experiments_Manager;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Elementor_Dev_Notice extends Base_Notice {
13 /**
14 * Notice ID.
15 */
16 const ID = 'elementor_dev_promote';
17
18 /**
19 * Plugin slug to install.
20 */
21 const PLUGIN_SLUG = 'elementor-beta';
22
23 /**
24 * Plugin name.
25 */
26 const PLUGIN_NAME = 'elementor-beta/elementor-beta.php';
27
28 /**
29 * Holds the plugins names.
30 *
31 * @var array
32 */
33 private $plugins = [];
34
35 /**
36 * If one of those plugin is installed it will show the notice.
37 *
38 * @var string[]
39 */
40 private $promotion_plugins = [
41 'woocommerce-beta-tester/woocommerce-beta-tester.php',
42 'wp-jquery-update-test/wp-jquery-update-test.php',
43 'wordpress-beta-tester/wp-beta-tester.php',
44 'gutenberg/gutenberg.php',
45 ];
46
47 /**
48 * If one of those options is enabled it will show the notice.
49 *
50 * @var string[]
51 */
52 private $promotion_options = [
53 'elementor_beta',
54 ];
55
56 /**
57 * @inheritDoc
58 */
59 public function should_print() {
60 return current_user_can( 'install_plugins' ) &&
61 ! User::is_user_notice_viewed( static::ID ) &&
62 ! $this->is_elementor_dev_installed() &&
63 ! $this->is_install_screen() &&
64 (
65 $this->has_at_least_one_active_experiment() ||
66 $this->is_promotion_plugins_installed() ||
67 $this->is_promotion_options_enabled()
68 );
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function get_config() {
75 return [
76 'dismissible' => true,
77 'id' => static::ID,
78 'title' => __( 'Elementor Developer Edition', 'elementor' ),
79 'description' => __(
80 'Get a sneak peek at our in progress development versions, and help us improve Elementor to perfection. Developer Edition releases contain experimental functionality for testing purposes.',
81 'elementor'
82 ),
83 'button' => [
84 'text' => __( 'Install & Activate', 'elementor' ),
85 'url' => wp_nonce_url(
86 self_admin_url( 'update.php?action=install-plugin&plugin=' . static::PLUGIN_SLUG ),
87 'install-plugin_' . static::PLUGIN_SLUG
88 ),
89 'class' => 'button',
90 ],
91 ];
92 }
93
94 /**
95 * Return all the plugins names.
96 *
97 * This method is protected so it can be mocked in tests.
98 *
99 * @return array
100 */
101 protected function get_plugins() {
102 if ( ! $this->plugins ) {
103 $this->plugins = array_keys( get_plugins() );
104 }
105
106 return $this->plugins;
107 }
108
109 /**
110 * Checks if elementor dev is installed
111 *
112 * @return bool
113 */
114 private function is_elementor_dev_installed() {
115 return in_array( static::PLUGIN_NAME, $this->get_plugins(), true );
116 }
117
118 /**
119 * Checks if the admin screen is install screen.
120 *
121 * @return bool
122 */
123 private function is_install_screen() {
124 $screen = get_current_screen();
125
126 if ( ! $screen ) {
127 return false;
128 }
129
130 return 'update' === $screen->id;
131 }
132
133 /**
134 * Checks if is one of the promotion plugins is installed
135 *
136 * @return bool
137 */
138 private function is_promotion_plugins_installed() {
139 return array_reduce( $this->promotion_plugins, function ( $should_show_notice, $plugin_name ) {
140 if ( $should_show_notice ) {
141 return true;
142 }
143
144 return in_array( $plugin_name, $this->get_plugins(), true );
145 }, false );
146 }
147
148 /**
149 * Checks if is one of the promotion options is enable.
150 *
151 * @return bool
152 */
153 private function is_promotion_options_enabled() {
154 return array_reduce( $this->promotion_options, function ( $should_show_notice, $option ) {
155 if ( $should_show_notice ) {
156 return true;
157 }
158
159 return 'yes' === get_option( $option, 'no' );
160 }, false );
161 }
162
163 /**
164 * Checks if as at least one active experiment (The state must be "active" and not default-active).
165 *
166 * @return bool
167 */
168 private function has_at_least_one_active_experiment() {
169 foreach ( Plugin::$instance->experiments->get_features() as $feature_name => $feature ) {
170 if ( Experiments_Manager::STATE_ACTIVE === $feature['state'] ) {
171 return true;
172 }
173 }
174
175 return false;
176 }
177 }
178