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

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