| 1 |
<?php |
| 2 |
namespace Elementor\Modules\CloudLibrary; |
| 3 |
|
| 4 |
use Elementor\Core\Base\Module as BaseModule; |
| 5 |
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule; |
| 6 |
use Elementor\Modules\CloudLibrary\Connect\Cloud_Library; |
| 7 |
use Elementor\Core\Common\Modules\Connect\Apps\Library; |
| 8 |
use Elementor\Core\Experiments\Manager as ExperimentsManager; |
| 9 |
use Elementor\Plugin; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
class Module extends BaseModule { |
| 16 |
|
| 17 |
public function get_name(): string { |
| 18 |
return 'cloud-library'; |
| 19 |
} |
| 20 |
|
| 21 |
public function __construct() { |
| 22 |
parent::__construct(); |
| 23 |
|
| 24 |
$this->register_experiment(); |
| 25 |
|
| 26 |
if ( Plugin::$instance->experiments->is_feature_active( $this->get_name() ) ) { |
| 27 |
$this->register_app(); |
| 28 |
|
| 29 |
add_action( 'elementor/init', function () { |
| 30 |
$this->set_cloud_library_settings(); |
| 31 |
}, 12 /** After the initiation of the connect cloud library */ ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
private function register_experiment() { |
| 36 |
Plugin::$instance->experiments->add_feature( [ |
| 37 |
'name' => $this->get_name(), |
| 38 |
'title' => esc_html__( 'Cloud Library', 'elementor' ), |
| 39 |
'description' => esc_html__( 'Enable Cloud Library.', 'elementor' ), |
| 40 |
'release_status' => ExperimentsManager::RELEASE_STATUS_DEV, |
| 41 |
'default' => ExperimentsManager::STATE_INACTIVE, |
| 42 |
'hidden' => true, |
| 43 |
] ); |
| 44 |
} |
| 45 |
|
| 46 |
private function register_app() { |
| 47 |
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) { |
| 48 |
$connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() ); |
| 49 |
} ); |
| 50 |
} |
| 51 |
|
| 52 |
private function set_cloud_library_settings() { |
| 53 |
if ( ! Plugin::$instance->common ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
/** @var ConnectModule $connect */ |
| 58 |
$connect = Plugin::$instance->common->get_component( 'connect' ); |
| 59 |
|
| 60 |
/** @var Library $library */ |
| 61 |
$library = $connect->get_app( 'library' ); |
| 62 |
|
| 63 |
if ( ! $library ) { |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
Plugin::$instance->app->set_settings( 'cloud-library', [ |
| 68 |
'library_connect_url' => esc_url( $library->get_admin_url( 'authorize', [ |
| 69 |
'utm_source' => 'template-library', |
| 70 |
'utm_medium' => 'wp-dash', |
| 71 |
'utm_campaign' => 'library-connect', |
| 72 |
'utm_content' => 'cloud-library', |
| 73 |
] ) ), |
| 74 |
'library_connect_title' => esc_html__( 'Connect', 'elementor' ), |
| 75 |
'library_connect_sub_title' => esc_html__( 'Sub Title', 'elementor' ), |
| 76 |
'library_connect_button_text' => esc_html__( 'Connect', 'elementor' ), |
| 77 |
] ); |
| 78 |
} |
| 79 |
} |
| 80 |
|