first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
interface Elementor_Adapter_Interface {
|
||||
|
||||
public function get_kit_settings();
|
||||
|
||||
public function get_main_post();
|
||||
|
||||
public function is_active_kit_default(): bool;
|
||||
|
||||
public function get_count( $key ): ?int;
|
||||
|
||||
public function set_count( $key, $count = 0 ): void;
|
||||
|
||||
public function increment( $key ): void;
|
||||
|
||||
public function is_key_allowed( $key ): bool;
|
||||
|
||||
public function get_template_type( $template_id ): string;
|
||||
|
||||
public function get_tier(): string;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Modules\ElementorCounter\Module as Elementor_Counter_Module;
|
||||
use Elementor\TemplateLibrary\Source_Local;
|
||||
use Elementor\Utils;
|
||||
|
||||
class Elementor_Adapter implements Elementor_Adapter_Interface {
|
||||
|
||||
public function get_kit_settings() {
|
||||
return Plugin::$instance->kits_manager->get_kit_for_frontend()->get_settings();
|
||||
}
|
||||
|
||||
public function get_main_post() {
|
||||
return Plugin::$instance->kits_manager->get_kit_for_frontend()->get_main_post();
|
||||
}
|
||||
|
||||
public function is_active_kit_default(): bool {
|
||||
$kit_id = Plugin::$instance->kits_manager->get_active_id();
|
||||
|
||||
if ( false === $kit_id || null === $kit_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return esc_html__( 'Default Kit', 'elementor' ) === get_post( $kit_id )->post_title;
|
||||
}
|
||||
|
||||
public function get_count( $key ): ?int {
|
||||
return Elementor_Counter_Module::instance()->get_count( $key );
|
||||
}
|
||||
|
||||
public function set_count( $key, $count = 0 ): void {
|
||||
Elementor_Counter_Module::instance()->set_count( $key, $count );
|
||||
}
|
||||
|
||||
public function increment( $key ): void {
|
||||
Elementor_Counter_Module::instance()->increment( $key );
|
||||
}
|
||||
|
||||
public function is_key_allowed( $key ): bool {
|
||||
return Elementor_Counter_Module::instance()->is_key_allowed( $key );
|
||||
}
|
||||
|
||||
public function get_template_type( $template_id ): string {
|
||||
return Source_Local::get_template_type( $template_id );
|
||||
}
|
||||
|
||||
public function get_tier(): string {
|
||||
return Utils::has_pro() ? ConnectModule::ACCESS_TIER_PRO_LEGACY : ConnectModule::ACCESS_TIER_FREE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
interface Elementor_Counter_Adapter_Interface {
|
||||
public function get_count( $key ): ?int;
|
||||
|
||||
public function set_count( $key, $count = 0 ): void;
|
||||
|
||||
public function increment( $key ): void;
|
||||
|
||||
public function is_key_allowed( $key ): bool;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
interface Plugin_Status_Adapter_Interface {
|
||||
|
||||
public function is_plugin_installed( $plugin_path ): bool;
|
||||
|
||||
public function get_install_plugin_url( $plugin_path ): string;
|
||||
|
||||
public function get_activate_plugin_url( $plugin_path ): string;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
class Plugin_Status_Adapter implements Plugin_Status_Adapter_Interface {
|
||||
|
||||
public Wordpress_Adapter_Interface $wordpress_adapter;
|
||||
|
||||
public function __construct( Wordpress_Adapter_Interface $wordpress_adapter ) {
|
||||
$this->wordpress_adapter = $wordpress_adapter;
|
||||
}
|
||||
|
||||
public function is_plugin_installed( $plugin_path ): bool {
|
||||
$installed_plugins = $this->wordpress_adapter->get_plugins();
|
||||
|
||||
return isset( $installed_plugins[ $plugin_path ] );
|
||||
}
|
||||
|
||||
public function get_install_plugin_url( $plugin_path ): string {
|
||||
$slug = dirname( $plugin_path );
|
||||
$admin_base_url = $this->wordpress_adapter->self_admin_url( 'update.php' );
|
||||
|
||||
$admin_url = add_query_arg( [
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => $slug,
|
||||
], $admin_base_url );
|
||||
|
||||
return $this->wordpress_adapter->wp_nonce_url( $admin_url, 'install-plugin_' . $slug );
|
||||
}
|
||||
|
||||
public function get_activate_plugin_url( $plugin_path ): string {
|
||||
$admin_base_url = $this->wordpress_adapter->self_admin_url( 'plugins.php' );
|
||||
|
||||
$admin_url = add_query_arg( [
|
||||
'action' => 'activate',
|
||||
'plugin' => $plugin_path,
|
||||
'plugin_status' => 'all',
|
||||
'paged' => 1,
|
||||
's' => '',
|
||||
], $admin_base_url );
|
||||
|
||||
return $this->wordpress_adapter->wp_nonce_url( $admin_url, 'activate-plugin_' . $plugin_path );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
interface Wordpress_Adapter_Interface {
|
||||
|
||||
public function get_plugins();
|
||||
|
||||
public function is_plugin_active( $plugin_path );
|
||||
|
||||
public function wp_nonce_url( $url, $action );
|
||||
|
||||
public function self_admin_url( $path );
|
||||
|
||||
public function get_pages( $args );
|
||||
|
||||
public function get_query( $args );
|
||||
|
||||
public function get_option( $option_key );
|
||||
|
||||
public function add_option( $option_key, $option_value );
|
||||
|
||||
public function update_option( $option_key, $option_value );
|
||||
|
||||
public function get_user_preferences( $preference_key );
|
||||
|
||||
public function set_user_preferences( $preference_key, $value );
|
||||
|
||||
public function is_new_installation();
|
||||
|
||||
public function add_query_arg( $args, $url );
|
||||
|
||||
public function has_custom_logo();
|
||||
|
||||
public function current_user_can( $capability, $args );
|
||||
|
||||
public function get_post_status( $post_id );
|
||||
|
||||
public function get_posts( $args );
|
||||
|
||||
public function get_post_types( $args = [], $output = 'names', $operator = 'and' );
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Core\Isolation;
|
||||
|
||||
use Elementor\Core\Settings\Manager;
|
||||
use Elementor\Core\Upgrade\Manager as Upgrade_Manager;
|
||||
|
||||
class Wordpress_Adapter implements Wordpress_Adapter_Interface {
|
||||
|
||||
public function get_plugins(): array {
|
||||
return get_plugins();
|
||||
}
|
||||
|
||||
public function is_plugin_active( $plugin_path ): bool {
|
||||
return is_plugin_active( $plugin_path );
|
||||
}
|
||||
|
||||
public function wp_nonce_url( $url, $action ): string {
|
||||
return wp_nonce_url( $url, $action );
|
||||
}
|
||||
|
||||
public function self_admin_url( $path ): string {
|
||||
return self_admin_url( $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of pages (or hierarchical post type items).
|
||||
*
|
||||
* @return WP_Post[]|false Array of pages (or hierarchical post type items). Boolean false if the
|
||||
* specified post type is not hierarchical or the specified status is not
|
||||
* supported by the post type.
|
||||
*/
|
||||
public function get_pages( $args ): ?array {
|
||||
return get_pages( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a wp query instance.
|
||||
*
|
||||
* @return \WP_Query
|
||||
*/
|
||||
public function get_query( $args ): ?\WP_Query {
|
||||
return new \WP_Query( $args );
|
||||
}
|
||||
|
||||
public function get_option( $option_key ) {
|
||||
return get_option( $option_key );
|
||||
}
|
||||
|
||||
public function update_option( $option_key, $option_value ): void {
|
||||
update_option( $option_key, $option_value );
|
||||
}
|
||||
|
||||
public function add_option( $option_key, $option_value ): void {
|
||||
add_option( $option_key, $option_value );
|
||||
}
|
||||
|
||||
public function get_user_preferences( $preference_key ) {
|
||||
return Manager::get_settings_managers( 'editorPreferences' )
|
||||
->get_model()
|
||||
->get_settings( $preference_key );
|
||||
}
|
||||
|
||||
public function set_user_preferences( $preference_key, $value ) {
|
||||
Manager::get_settings_managers( 'editorPreferences' )
|
||||
->get_model()
|
||||
->set_settings( $preference_key, $value );
|
||||
}
|
||||
|
||||
public function is_new_installation() {
|
||||
return Upgrade_Manager::is_new_installation();
|
||||
}
|
||||
|
||||
public function add_query_arg( $args, $url ): string {
|
||||
return add_query_arg( $args, $url );
|
||||
}
|
||||
|
||||
public function has_custom_logo(): bool {
|
||||
return has_custom_logo();
|
||||
}
|
||||
|
||||
public function current_user_can( $capability, $args ): bool {
|
||||
return current_user_can( $capability, $args );
|
||||
}
|
||||
|
||||
public function get_post_status( $post_id ): string {
|
||||
return get_post_status( $post_id );
|
||||
}
|
||||
|
||||
public function get_posts( $args ): array {
|
||||
return get_posts( $args );
|
||||
}
|
||||
|
||||
public function get_post_types( $args = [], $output = 'names', $operator = 'and' ): array {
|
||||
return get_post_types( $args, $output, $operator );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user