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

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