PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.3
Elementor Website Builder – more than just a page builder v3.32.3
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.32.3, at core/common/modules/connect/module.php

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