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
image-optimization / modules / connect / module.php

module.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/connect/module.php

80 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Connect;
4
5 use ElementorOne\Connect\Facade;
6 use ImageOptimization\Classes\Module_Base;
7 use ImageOptimization\Modules\Connect\Classes\Config;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Class Module
15 */
16 class Module extends Module_Base {
17 /**
18 * Get module name.
19 * Retrieve the module name.
20 * @access public
21 * @return string Module name.
22 */
23 public function get_name() {
24 return 'connect';
25 }
26
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();
32 }
33
34 public static function get_connect(): ?Facade {
35 return Facade::get( Config::PLUGIN_SLUG );
36 }
37
38 public static function is_active(): bool {
39 return empty( get_option( 'image_optimizer_client_data' ) );
40 }
41
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;
61 }
62
63 public function __construct() {
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 ] );
78 }
79 }
80