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

261 lines 5.6 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 * Register app.
123 *
124 * Registers an app.
125 *
126 * @since 2.3.0
127 * @access public
128 *
129 * @param string $slug App slug.
130 * @param string $class App full class name.
131 *
132 * @return self The updated apps manager instance.
133 */
134 public function register_app( $slug, $class ) {
135 $this->registered_apps[ $slug ] = $class;
136
137 return $this;
138 }
139
140 /**
141 * Get app instance.
142 *
143 * Retrieve the app instance.
144 *
145 * @since 2.3.0
146 * @access public
147 *
148 * @param $slug
149 *
150 * @return Base_App|null
151 */
152 public function get_app( $slug ) {
153 if ( isset( $this->apps[ $slug ] ) ) {
154 return $this->apps[ $slug ];
155 }
156
157 return null;
158 }
159
160 /**
161 * @since 2.3.0
162 * @access public
163 * @return Base_App[]
164 */
165 public function get_apps() {
166 return $this->apps;
167 }
168
169 /**
170 * @since 2.3.0
171 * @access public
172 */
173 public function register_category( $slug, $args ) {
174 $this->categories[ $slug ] = $args;
175 return $this;
176 }
177
178 /**
179 * @since 2.3.0
180 * @access public
181 */
182 public function get_categories() {
183 return $this->categories;
184 }
185
186 /**
187 * @param string $context Where this subscription plan should be shown.
188 *
189 * @return array
190 */
191 public function get_subscription_plans( $context = '' ) {
192 $base_url = Utils::has_pro() ? 'https://my.elementor.com/upgrade-subscription' : 'https://elementor.com/pro';
193 $promotion_url = $base_url . '/?utm_source=' . $context . '&utm_medium=wp-dash&utm_campaign=gopro';
194
195 return [
196 static::ACCESS_TIER_FREE => [
197 'label' => null,
198 'promotion_url' => null,
199 'color' => null,
200 ],
201 static::ACCESS_TIER_ESSENTIAL => [
202 'label' => 'Pro',
203 'promotion_url' => $promotion_url,
204 'color' => '#92003B',
205 ],
206 static::ACCESS_TIER_ESSENTIAL_OCT_2023 => [
207 'label' => 'Advanced', // Should be the same label as "Advanced".
208 'promotion_url' => $promotion_url,
209 'color' => '#92003B',
210 ],
211 static::ACCESS_TIER_ADVANCED => [
212 'label' => 'Advanced',
213 'promotion_url' => $promotion_url,
214 'color' => '#92003B',
215 ],
216 static::ACCESS_TIER_EXPERT => [
217 'label' => 'Expert',
218 'promotion_url' => $promotion_url,
219 'color' => '#92003B',
220 ],
221 static::ACCESS_TIER_AGENCY => [
222 'label' => 'Agency',
223 'promotion_url' => $promotion_url,
224 'color' => '#92003B',
225 ],
226 ];
227 }
228
229 private function add_tracking_data( $params ) {
230 $users = [];
231
232 $users_query = new WP_User_Query( [
233 'count_total' => false, // Disable SQL_CALC_FOUND_ROWS.
234 'meta_query' => [
235 'key' => Common_App::OPTION_CONNECT_COMMON_DATA_KEY,
236 'compare' => 'EXISTS',
237 ],
238 ] );
239
240 foreach ( $users_query->get_results() as $user ) {
241 $connect_common_data = get_user_option( Common_App::OPTION_CONNECT_COMMON_DATA_KEY, $user->ID );
242
243 if ( $connect_common_data ) {
244 $users [] = [
245 'id' => $user->ID,
246 'email' => $connect_common_data['user']->email,
247 'roles' => implode( ', ', $user->roles ),
248 ];
249 }
250 }
251
252 $params['usages'][ $this->get_name() ] = [
253 'site_key' => get_option( Base_App::OPTION_CONNECT_SITE_KEY ),
254 'count' => count( $users ),
255 'users' => $users,
256 ];
257
258 return $params;
259 }
260 }
261