PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | modules/connect/module.php +44 -29 1.4.11.7.7 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 2
3 3 namespace ImageOptimization\Modules\Connect;
4 4
5 +use ElementorOne\Connect\Facade;
5 6 use ImageOptimization\Classes\Module_Base;
6 -use ImageOptimization\Modules\Connect\Classes\Data;
7 +use ImageOptimization\Modules\Connect\Classes\Config;
7 8
8 9 if ( ! defined( 'ABSPATH' ) ) {
9 10 exit; // Exit if accessed directly
10 11 }
@@ -12,9 +13,8 @@
12 13 /**
13 14 * Class Module
14 15 */
15 16 class Module extends Module_Base {
16 -
17 17 /**
18 18 * Get module name.
19 19 * Retrieve the module name.
20 20 * @access public
@@ -23,42 +23,57 @@
23 23 public function get_name() {
24 24 return 'connect';
25 25 }
26 26
27 - /**
28 - * component_list
29 - * @return string[]
30 - */
31 - public static function component_list() : array {
32 - return [
33 - 'Handler',
34 - ];
27 + public static function is_connected(): bool {
28 + $facade = self::get_connect();
29 + $access_token = $facade->data()->get_access_token();
30 +
31 + return (bool) $access_token && $facade->utils()->is_valid_home_url();
35 32 }
36 33
37 - /**
38 - * routes_list
39 - * @return string[]
40 - */
41 - public static function routes_list() : array {
42 - return [
43 - 'Authorize',
44 - 'Disconnect',
45 - 'Deactivate',
46 - 'Deactivate_And_Disconnect',
47 - 'Version',
48 - ];
34 + public static function get_connect(): ?Facade {
35 + return Facade::get( Config::PLUGIN_SLUG );
49 36 }
50 37
51 - public static function is_connected() : bool {
52 - return ! ! Data::get_access_token();
38 + public static function is_active(): bool {
39 + return empty( get_option( 'image_optimizer_client_data' ) );
53 40 }
54 41
55 - public static function is_active() : bool {
56 - // TODO: Add login to check if the function should be active or not.
57 - return empty( get_option( 'image_optimizer_client_data' ) );
42 + public function authorize_url( $authorize_url ) {
43 + $utm_params = [];
44 +
45 + $io_campaign = get_transient( 'elementor_image_optimization_campaign' );
46 + if ( false === $io_campaign ) {
47 + return $authorize_url;
48 + }
49 +
50 + foreach ( [ 'source', 'medium', 'campaign' ] as $key ) {
51 + if ( ! empty( $io_campaign[ $key ] ) ) {
52 + $utm_params[ 'utm_' . $key ] = $io_campaign[ $key ];
53 + }
54 + }
55 +
56 + if ( ! empty( $utm_params ) ) {
57 + $authorize_url = add_query_arg( $utm_params, $authorize_url );
58 + }
59 +
60 + return $authorize_url;
58 61 }
59 62
60 63 public function __construct() {
61 - $this->register_components();
62 - $this->register_routes();
64 + add_filter( 'elementor_one/image_optimizer_connect_authorize_url', [ $this, 'authorize_url' ] );
65 +
66 + Facade::make( [
67 + 'app_name' => Config::APP_NAME,
68 + 'app_prefix' => Config::APP_PREFIX,
69 + 'app_rest_namespace' => Config::APP_REST_NAMESPACE,
70 + 'base_url' => Config::BASE_URL,
71 + 'admin_page' => Config::ADMIN_PAGE,
72 + 'app_type' => Config::APP_TYPE,
73 + 'scopes' => Config::SCOPES,
74 + 'state_nonce' => Config::STATE_NONCE,
75 + 'connect_mode' => Config::CONNECT_MODE,
76 + 'plugin_slug' => Config::PLUGIN_SLUG,
77 + ] );
63 78 }
64 79 }