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

177 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 'id' => static::ID,
77 'title' => __( 'Elementor Developer Edition', 'elementor' ),
78 'description' => __(
79 '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.',
80 'elementor'
81 ),
82 'button' => [
83 'text' => __( 'Install & Activate', 'elementor' ),
84 'url' => wp_nonce_url(
85 self_admin_url( 'update.php?action=install-plugin&plugin=' . static::PLUGIN_SLUG ),
86 'install-plugin_' . static::PLUGIN_SLUG
87 ),
88 'type' => 'cta',
89 ],
90 ];
91 }
92
93 /**
94 * Return all the plugins names.
95 *
96 * This method is protected so it can be mocked in tests.
97 *
98 * @return array
99 */
100 protected function get_plugins() {
101 if ( ! $this->plugins ) {
102 $this->plugins = array_keys( get_plugins() );
103 }
104
105 return $this->plugins;
106 }
107
108 /**
109 * Checks if elementor dev is installed
110 *
111 * @return bool
112 */
113 private function is_elementor_dev_installed() {
114 return in_array( static::PLUGIN_NAME, $this->get_plugins(), true );
115 }
116
117 /**
118 * Checks if the admin screen is install screen.
119 *
120 * @return bool
121 */
122 private function is_install_screen() {
123 $screen = get_current_screen();
124
125 if ( ! $screen ) {
126 return false;
127 }
128
129 return 'update' === $screen->id;
130 }
131
132 /**
133 * Checks if is one of the promotion plugins is installed
134 *
135 * @return bool
136 */
137 private function is_promotion_plugins_installed() {
138 return array_reduce( $this->promotion_plugins, function ( $should_show_notice, $plugin_name ) {
139 if ( $should_show_notice ) {
140 return true;
141 }
142
143 return in_array( $plugin_name, $this->get_plugins(), true );
144 }, false );
145 }
146
147 /**
148 * Checks if is one of the promotion options is enable.
149 *
150 * @return bool
151 */
152 private function is_promotion_options_enabled() {
153 return array_reduce( $this->promotion_options, function ( $should_show_notice, $option ) {
154 if ( $should_show_notice ) {
155 return true;
156 }
157
158 return 'yes' === get_option( $option, 'no' );
159 }, false );
160 }
161
162 /**
163 * Checks if as at least one active experiment (The state must be "active" and not default-active).
164 *
165 * @return bool
166 */
167 private function has_at_least_one_active_experiment() {
168 foreach ( Plugin::$instance->experiments->get_features() as $feature_name => $feature ) {
169 if ( Experiments_Manager::STATE_ACTIVE === $feature['state'] ) {
170 return true;
171 }
172 }
173
174 return false;
175 }
176 }
177