PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev3
Elementor Website Builder – more than just a page builder v3.23.0-dev3
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 / common / modules / connect / module.php

module.php in Elementor Website Builder – more than just a page builder 3.23.0-dev3, at core/common/modules/connect/module.php

270 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Common\Modules\Connect;
3
4 use Elementor\Core\Base\Module as BaseModule;
5 use Elementor\Core\Common\Modules\Connect\Apps\Base_App;
6 use Elementor\Core\Common\Modules\Connect\Apps\Common_App;
7 use Elementor\Core\Common\Modules\Connect\Apps\Connect;
8 use Elementor\Core\Common\Modules\Connect\Apps\Library;
9 use Elementor\Plugin;
10 use Elementor\Utils;
11 use WP_User_Query;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly
15 }
16
17 class Module extends BaseModule {
18 const ACCESS_LEVEL_CORE = 0;
19 const ACCESS_LEVEL_PRO = 1;
20 const ACCESS_LEVEL_EXPERT = 20;
21
22 const ACCESS_TIER_FREE = 'free';
23 const ACCESS_TIER_ESSENTIAL = 'essential';
24 const ACCESS_TIER_ESSENTIAL_OCT_2023 = 'essential-oct2023';
25 const ACCESS_TIER_ADVANCED = 'advanced';
26 const ACCESS_TIER_EXPERT = 'expert';
27 const ACCESS_TIER_AGENCY = 'agency';
28
29 /**
30 * @since 2.3.0
31 * @access public
32 */
33 public function get_name() {
34 return 'connect';
35 }
36
37 /**
38 * @var array
39 */
40 protected $registered_apps = [];
41
42 /**
43 * Apps Instances.
44 *
45 * Holds the list of all the apps instances.
46 *
47 * @since 2.3.0
48 * @access protected
49 *
50 * @var Base_App[]
51 */
52 protected $apps = [];
53
54 /**
55 * Registered apps categories.
56 *
57 * Holds the list of all the registered apps categories.
58 *
59 * @since 2.3.0
60 * @access protected
61 *
62 * @var array
63 */
64 protected $categories = [];
65
66 protected $admin_page;
67
68 /**
69 * @since 2.3.0
70 * @access public
71 */
72 public function __construct() {
73 $this->registered_apps = [
74 'connect' => Connect::get_class_name(),
75 'library' => Library::get_class_name(),
76 ];
77
78 // When using REST API the parent module is construct after the action 'elementor/init'
79 // so this part of code make sure to register the module "apps".
80 if ( did_action( 'elementor/init' ) ) {
81 $this->init();
82 } else {
83 // Note: The priority 11 is for allowing plugins to add their register callback on elementor init.
84 add_action( 'elementor/init', [ $this, 'init' ], 11 );
85 }
86
87 add_filter( 'elementor/tracker/send_tracking_data_params', function ( $params ) {
88 return $this->add_tracking_data( $params );
89 } );
90 }
91
92 /**
93 * Register default apps.
94 *
95 * Registers the default apps.
96 *
97 * @since 2.3.0
98 * @access public
99 */
100 public function init() {
101 if ( is_admin() ) {
102 $this->admin_page = new Admin();
103 }
104
105 /**
106 * Register Elementor apps.
107 *
108 * Fires after Elementor registers the default apps.
109 *
110 * @since 2.3.0
111 *
112 * @param self $this The apps manager instance.
113 */
114 do_action( 'elementor/connect/apps/register', $this );
115
116 foreach ( $this->registered_apps as $slug => $class ) {
117 $this->apps[ $slug ] = new $class();
118 }
119 }
120
121 /**
122 * @deprecated 3.1.0
123 */
124 public function localize_settings() {
125 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' );
126
127 return [];
128 }
129
130 /**
131 * Register app.
132 *
133 * Registers an app.
134 *
135 * @since 2.3.0
136 * @access public
137 *
138 * @param string $slug App slug.
139 * @param string $class App full class name.
140 *
141 * @return self The updated apps manager instance.
142 */
143 public function register_app( $slug, $class ) {
144 $this->registered_apps[ $slug ] = $class;
145
146 return $this;
147 }
148
149 /**
150 * Get app instance.
151 *
152 * Retrieve the app instance.
153 *
154 * @since 2.3.0
155 * @access public
156 *
157 * @param $slug
158 *
159 * @return Base_App|null
160 */
161 public function get_app( $slug ) {
162 if ( isset( $this->apps[ $slug ] ) ) {
163 return $this->apps[ $slug ];
164 }
165
166 return null;
167 }
168
169 /**
170 * @since 2.3.0
171 * @access public
172 * @return Base_App[]
173 */
174 public function get_apps() {
175 return $this->apps;
176 }
177
178 /**
179 * @since 2.3.0
180 * @access public
181 */
182 public function register_category( $slug, $args ) {
183 $this->categories[ $slug ] = $args;
184 return $this;
185 }
186
187 /**
188 * @since 2.3.0
189 * @access public
190 */
191 public function get_categories() {
192 return $this->categories;
193 }
194
195 /**
196 * @param string $context Where this subscription plan should be shown.
197 *
198 * @return array
199 */
200 public function get_subscription_plans( $context = '' ) {
201 $base_url = Utils::has_pro() ? 'https://my.elementor.com/upgrade-subscription' : 'https://elementor.com/pro';
202 $promotion_url = $base_url . '/?utm_source=' . $context . '&utm_medium=wp-dash&utm_campaign=gopro';
203
204 return [
205 static::ACCESS_TIER_FREE => [
206 'label' => null,
207 'promotion_url' => null,
208 'color' => null,
209 ],
210 static::ACCESS_TIER_ESSENTIAL => [
211 'label' => 'Pro',
212 'promotion_url' => $promotion_url,
213 'color' => '#92003B',
214 ],
215 static::ACCESS_TIER_ESSENTIAL_OCT_2023 => [
216 'label' => 'Advanced', // Should be the same label as "Advanced".
217 'promotion_url' => $promotion_url,
218 'color' => '#92003B',
219 ],
220 static::ACCESS_TIER_ADVANCED => [
221 'label' => 'Advanced',
222 'promotion_url' => $promotion_url,
223 'color' => '#92003B',
224 ],
225 static::ACCESS_TIER_EXPERT => [
226 'label' => 'Expert',
227 'promotion_url' => $promotion_url,
228 'color' => '#92003B',
229 ],
230 static::ACCESS_TIER_AGENCY => [
231 'label' => 'Agency',
232 'promotion_url' => $promotion_url,
233 'color' => '#92003B',
234 ],
235 ];
236 }
237
238 private function add_tracking_data( $params ) {
239 $users = [];
240
241 $users_query = new WP_User_Query( [
242 'count_total' => false, // Disable SQL_CALC_FOUND_ROWS.
243 'meta_query' => [
244 'key' => Common_App::OPTION_CONNECT_COMMON_DATA_KEY,
245 'compare' => 'EXISTS',
246 ],
247 ] );
248
249 foreach ( $users_query->get_results() as $user ) {
250 $connect_common_data = get_user_option( Common_App::OPTION_CONNECT_COMMON_DATA_KEY, $user->ID );
251
252 if ( $connect_common_data ) {
253 $users [] = [
254 'id' => $user->ID,
255 'email' => $connect_common_data['user']->email,
256 'roles' => implode( ', ', $user->roles ),
257 ];
258 }
259 }
260
261 $params['usages'][ $this->get_name() ] = [
262 'site_key' => get_option( Base_App::OPTION_CONNECT_SITE_KEY ),
263 'count' => count( $users ),
264 'users' => $users,
265 ];
266
267 return $params;
268 }
269 }
270