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

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

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