| @@ -2,34 +2,17 @@ | ||
| 2 | 2 | namespace Elementor\Core\Common\Modules\Connect; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 5 | use Elementor\Core\Common\Modules\Connect\Apps\Base_App; |
| 6 | -use Elementor\Core\Common\Modules\Connect\Apps\Common_App; | |
| 7 | 6 | use Elementor\Core\Common\Modules\Connect\Apps\Connect; |
| 8 | -use Elementor\Core\Common\Modules\Connect\Apps\Feedback; | |
| 9 | 7 | 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 | 8 | |
| 15 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; // Exit if accessed directly. | |
| 10 | + exit; // Exit if accessed directly | |
| 17 | 11 | } |
| 18 | 12 | |
| 19 | 13 | class Module extends BaseModule { |
| 20 | - const ACCESS_LEVEL_CORE = 0; | |
| 21 | - const ACCESS_LEVEL_PRO = 1; | |
| 22 | - const ACCESS_LEVEL_EXPERT = 20; | |
| 23 | 14 | |
| 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 | 15 | /** |
| 33 | 16 | * @since 2.3.0 |
| 34 | 17 | * @access public |
| 35 | 18 | */ |
| @@ -75,25 +58,12 @@ | ||
| 75 | 58 | public function __construct() { |
| 76 | 59 | $this->registered_apps = [ |
| 77 | 60 | 'connect' => Connect::get_class_name(), |
| 78 | 61 | 'library' => Library::get_class_name(), |
| 79 | - 'feedback' => Feedback::get_class_name(), | |
| 80 | 62 | ]; |
| 81 | 63 | |
| 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 | - } ); | |
| 64 | + // Note: The priority 11 is for allowing plugins to add their register callback on elementor init. | |
| 65 | + add_action( 'elementor/init', [ $this, 'init' ], 11 ); | |
| 96 | 66 | } |
| 97 | 67 | |
| 98 | 68 | /** |
| 99 | 69 | * Register default apps. |
| @@ -121,10 +91,21 @@ | ||
| 121 | 91 | |
| 122 | 92 | foreach ( $this->registered_apps as $slug => $class ) { |
| 123 | 93 | $this->apps[ $slug ] = new $class(); |
| 124 | 94 | } |
| 95 | + | |
| 96 | + add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); | |
| 125 | 97 | } |
| 126 | 98 | |
| 99 | + public function localize_settings( $settings ) { | |
| 100 | + return array_replace_recursive( $settings, [ | |
| 101 | + 'i18n' => [ | |
| 102 | + 'connect_error' => __( 'Unable to connect', 'elementor' ), | |
| 103 | + 'connected_successfully' => __( 'Connected successfully', 'elementor' ), | |
| 104 | + ], | |
| 105 | + ] ); | |
| 106 | + } | |
| 107 | + | |
| 127 | 108 | /** |
| 128 | 109 | * Register app. |
| 129 | 110 | * |
| 130 | 111 | * Registers an app. |
| @@ -131,15 +112,15 @@ | ||
| 131 | 112 | * |
| 132 | 113 | * @since 2.3.0 |
| 133 | 114 | * @access public |
| 134 | 115 | * |
| 135 | - * @param string $slug App slug. | |
| 136 | - * @param string $class_name App full class name. | |
| 116 | + * @param string $slug App slug. | |
| 117 | + * @param string $class App full class name. | |
| 137 | 118 | * |
| 138 | 119 | * @return self The updated apps manager instance. |
| 139 | 120 | */ |
| 140 | - public function register_app( $slug, $class_name ) { | |
| 141 | - $this->registered_apps[ $slug ] = $class_name; | |
| 121 | + public function register_app( $slug, $class ) { | |
| 122 | + $this->registered_apps[ $slug ] = $class; | |
| 142 | 123 | |
| 143 | 124 | return $this; |
| 144 | 125 | } |
| 145 | 126 | |
| @@ -188,84 +169,5 @@ | ||
| 188 | 169 | public function get_categories() { |
| 189 | 170 | return $this->categories; |
| 190 | 171 | } |
| 191 | 172 | |
| 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 | 173 | } |