balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

module.php (4435B)


      1 <?php
      2 namespace Elementor\Core\Common\Modules\Connect;
      3 
      4 use Elementor\Utils;
      5 use Elementor\Core\Base\Module as BaseModule;
      6 use Elementor\Core\Common\Modules\Connect\Apps\Base_App;
      7 use Elementor\Core\Common\Modules\Connect\Apps\Connect;
      8 use Elementor\Core\Common\Modules\Connect\Apps\Library;
      9 use Elementor\Plugin;
     10 
     11 if ( ! defined( 'ABSPATH' ) ) {
     12 	exit; // Exit if accessed directly
     13 }
     14 
     15 class Module extends BaseModule {
     16 	const ACCESS_LEVEL_CORE = 0;
     17 	const ACCESS_LEVEL_PRO = 1;
     18 	const ACCESS_LEVEL_EXPERT = 20;
     19 
     20 	/**
     21 	 * @since 2.3.0
     22 	 * @access public
     23 	 */
     24 	public function get_name() {
     25 		return 'connect';
     26 	}
     27 
     28 	/**
     29 	 * @var array
     30 	 */
     31 	protected $registered_apps = [];
     32 
     33 	/**
     34 	 * Apps Instances.
     35 	 *
     36 	 * Holds the list of all the apps instances.
     37 	 *
     38 	 * @since 2.3.0
     39 	 * @access protected
     40 	 *
     41 	 * @var Base_App[]
     42 	 */
     43 	protected $apps = [];
     44 
     45 	/**
     46 	 * Registered apps categories.
     47 	 *
     48 	 * Holds the list of all the registered apps categories.
     49 	 *
     50 	 * @since 2.3.0
     51 	 * @access protected
     52 	 *
     53 	 * @var array
     54 	 */
     55 	protected $categories = [];
     56 
     57 	protected $admin_page;
     58 
     59 	/**
     60 	 * @since 2.3.0
     61 	 * @access public
     62 	 */
     63 	public function __construct() {
     64 		$this->registered_apps = [
     65 			'connect' => Connect::get_class_name(),
     66 			'library' => Library::get_class_name(),
     67 		];
     68 
     69 		// When using REST API the parent module is construct after the action 'elementor/init'
     70 		// so this part of code make sure to register the module "apps".
     71 		if ( did_action( 'elementor/init' ) ) {
     72 			$this->init();
     73 		} else {
     74 			// Note: The priority 11 is for allowing plugins to add their register callback on elementor init.
     75 			add_action( 'elementor/init', [ $this, 'init' ], 11 );
     76 		}
     77 	}
     78 
     79 	/**
     80 	 * Register default apps.
     81 	 *
     82 	 * Registers the default apps.
     83 	 *
     84 	 * @since 2.3.0
     85 	 * @access public
     86 	 */
     87 	public function init() {
     88 		if ( is_admin() ) {
     89 			$this->admin_page = new Admin();
     90 		}
     91 
     92 		/**
     93 		 * Register Elementor apps.
     94 		 *
     95 		 * Fires after Elementor registers the default apps.
     96 		 *
     97 		 * @since 2.3.0
     98 		 *
     99 		 * @param self $this The apps manager instance.
    100 		 */
    101 		do_action( 'elementor/connect/apps/register', $this );
    102 
    103 		foreach ( $this->registered_apps as $slug => $class ) {
    104 			$this->apps[ $slug ] = new $class();
    105 		}
    106 	}
    107 
    108 	/**
    109 	 * @deprecated 3.1.0
    110 	 */
    111 	public function localize_settings() {
    112 		Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.1.0' );
    113 
    114 		return [];
    115 	}
    116 
    117 	/**
    118 	 * Register app.
    119 	 *
    120 	 * Registers an app.
    121 	 *
    122 	 * @since 2.3.0
    123 	 * @access public
    124 	 *
    125 	 * @param string $slug App slug.
    126 	 * @param string $class App full class name.
    127 	 *
    128 	 * @return self The updated apps manager instance.
    129 	 */
    130 	public function register_app( $slug, $class ) {
    131 		$this->registered_apps[ $slug ] = $class;
    132 
    133 		return $this;
    134 	}
    135 
    136 	/**
    137 	 * Get app instance.
    138 	 *
    139 	 * Retrieve the app instance.
    140 	 *
    141 	 * @since 2.3.0
    142 	 * @access public
    143 	 *
    144 	 * @param $slug
    145 	 *
    146 	 * @return Base_App|null
    147 	 */
    148 	public function get_app( $slug ) {
    149 		if ( isset( $this->apps[ $slug ] ) ) {
    150 			return $this->apps[ $slug ];
    151 		}
    152 
    153 		return null;
    154 	}
    155 
    156 	/**
    157 	 * @since 2.3.0
    158 	 * @access public
    159 	 * @return Base_App[]
    160 	 */
    161 	public function get_apps() {
    162 		return $this->apps;
    163 	}
    164 
    165 	/**
    166 	 * @since 2.3.0
    167 	 * @access public
    168 	 */
    169 	public function register_category( $slug, $args ) {
    170 		$this->categories[ $slug ] = $args;
    171 		return $this;
    172 	}
    173 
    174 	/**
    175 	 * @since 2.3.0
    176 	 * @access public
    177 	 */
    178 	public function get_categories() {
    179 		return $this->categories;
    180 	}
    181 
    182 	/**
    183 	 * @param $context
    184 	 *
    185 	 * @return array
    186 	 */
    187 	public function get_subscription_plans( $context ) {
    188 		return [
    189 			static::ACCESS_LEVEL_CORE => [
    190 				'label' => null,
    191 				'promotion_url' => null,
    192 				'color' => null,
    193 			],
    194 			static::ACCESS_LEVEL_PRO => [
    195 				'label' => 'Pro',
    196 				'promotion_url' => Utils::get_pro_link( "https://elementor.com/pro/?utm_source={$context}&utm_medium=wp-dash&utm_campaign=gopro" ),
    197 				'color' => '#92003B',
    198 			],
    199 			static::ACCESS_LEVEL_EXPERT => [
    200 				'label' => 'Expert',
    201 				'promotion_url' => Utils::get_pro_link( "https://elementor.com/pro/?utm_source={$context}&utm_medium=wp-dash&utm_campaign=goexpert" ),
    202 				'color' => '#010051',
    203 			],
    204 		];
    205 	}
    206 
    207 	protected function get_init_settings() {
    208 		/** @var Connect $connect */
    209 		$connect = $this->get_app( 'library' );
    210 		if ( ! $connect ) {
    211 			return [];
    212 		}
    213 		return [
    214 			'is_user_connected' => $connect->is_connected(),
    215 			'connect_url' => $connect->get_admin_url( 'authorize' ),
    216 		];
    217 	}
    218 
    219 }