first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicOptIn;
|
||||
|
||||
use Elementor\Core\Base\Module as BaseModule;
|
||||
use Elementor\Core\Experiments\Manager as Experiments_Manager;
|
||||
use Elementor\Modules\AtomicWidgets\Opt_In as Atomic_Widgets_Opt_In;
|
||||
use Elementor\Plugin;
|
||||
|
||||
class Module extends BaseModule {
|
||||
const EXPERIMENT_NAME = 'e_opt_in_v4_page';
|
||||
const MODULE_NAME = 'editor-v4-opt-in';
|
||||
const WELCOME_POPOVER_DISPLAYED_OPTION = '_e_welcome_popover_displayed';
|
||||
|
||||
public function get_name() {
|
||||
return 'atomic-opt-in';
|
||||
}
|
||||
|
||||
public static function get_experimental_data(): array {
|
||||
return [
|
||||
'name' => self::EXPERIMENT_NAME,
|
||||
'title' => esc_html__( 'Editor v4 (Opt In Page)', 'elementor' ),
|
||||
'description' => esc_html__( 'Enable the settings Opt In page', 'elementor' ),
|
||||
'hidden' => true,
|
||||
'default' => Experiments_Manager::STATE_ACTIVE,
|
||||
'release_status' => Experiments_Manager::RELEASE_STATUS_ALPHA,
|
||||
];
|
||||
}
|
||||
|
||||
public function get_opt_in_css_assets_url( string $path ) {
|
||||
return $this->get_css_assets_url( $path );
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
( new PanelChip() )->init();
|
||||
|
||||
if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
( new Atomic_Widgets_Opt_In() )->init();
|
||||
( new OptInPage( $this ) )->init();
|
||||
|
||||
if ( ! $this->is_atomic_experiment_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
( new WelcomeScreen() )->init();
|
||||
}
|
||||
|
||||
public function is_atomic_experiment_active(): bool {
|
||||
return Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Opt_In::EXPERIMENT_NAME );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicOptIn;
|
||||
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Settings;
|
||||
use Elementor\User;
|
||||
use Elementor\Utils;
|
||||
|
||||
class OptInPage {
|
||||
private Module $module;
|
||||
|
||||
public function __construct( Module $module ) {
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->register_assets();
|
||||
$this->add_settings_tab();
|
||||
}
|
||||
|
||||
private function register_assets() {
|
||||
$page_id = Settings::PAGE_ID;
|
||||
|
||||
add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'enqueue_scripts' ] );
|
||||
add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'enqueue_styles' ] );
|
||||
}
|
||||
|
||||
public function enqueue_styles() {
|
||||
wp_enqueue_style(
|
||||
Module::MODULE_NAME,
|
||||
$this->module->get_opt_in_css_assets_url( 'modules/editor-v4-opt-in/opt-in' ),
|
||||
[],
|
||||
ELEMENTOR_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_script(
|
||||
Module::MODULE_NAME,
|
||||
ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
Module::MODULE_NAME,
|
||||
'elementorSettingsEditor4OptIn',
|
||||
$this->prepare_data()
|
||||
);
|
||||
|
||||
wp_set_script_translations( Module::MODULE_NAME, 'elementor' );
|
||||
}
|
||||
|
||||
private function prepare_data() {
|
||||
$create_new_post_type = User::is_current_user_can_edit_post_type( 'page' ) ? 'page' : 'post';
|
||||
|
||||
return [
|
||||
'features' => [
|
||||
'editor_v4' => $this->module->is_atomic_experiment_active(),
|
||||
],
|
||||
'urls' => [
|
||||
'start_building' => esc_url( Plugin::$instance->documents->get_create_new_post_url( $create_new_post_type ) ),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function add_settings_tab() {
|
||||
$page_id = Settings::PAGE_ID;
|
||||
|
||||
add_action( "elementor/admin/after_create_settings/{$page_id}", function( Settings $settings ) {
|
||||
$this->add_new_tab_to( $settings );
|
||||
}, 11 );
|
||||
}
|
||||
|
||||
private function add_new_tab_to( Settings $settings ) {
|
||||
$settings->add_tab( Module::MODULE_NAME, [
|
||||
'label' => esc_html__( 'Editor V4', 'elementor' ),
|
||||
'sections' => [
|
||||
'opt-in' => [
|
||||
'callback' => function() {
|
||||
echo '<div id="page-editor-v4-opt-in"></div>';
|
||||
},
|
||||
'fields' => [],
|
||||
],
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicOptIn;
|
||||
|
||||
use Elementor\Utils;
|
||||
|
||||
class PanelChip {
|
||||
public function init() {
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_script(
|
||||
'editor-v4-opt-in-alphachip',
|
||||
ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in-alphachip' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( 'editor-v4-opt-in-alphachip', 'elementor' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicOptIn;
|
||||
|
||||
use Elementor\Core\Isolation\Elementor_Adapter;
|
||||
use Elementor\Core\Isolation\Elementor_Adapter_Interface;
|
||||
use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
|
||||
use Elementor\Utils;
|
||||
|
||||
class WelcomeScreen {
|
||||
private Elementor_Adapter_Interface $elementor_adapter;
|
||||
|
||||
public function __construct() {
|
||||
$this->elementor_adapter = new Elementor_Adapter();
|
||||
}
|
||||
|
||||
public function init() {
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'maybe_enqueue_welcome_popover' ] );
|
||||
}
|
||||
|
||||
public function maybe_enqueue_welcome_popover(): void {
|
||||
if ( $this->is_first_or_second_editor_visit() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->has_welcome_popover_been_displayed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->enqueue_scripts();
|
||||
$this->set_welcome_popover_as_displayed();
|
||||
}
|
||||
|
||||
private function is_first_or_second_editor_visit(): bool {
|
||||
if ( ! $this->elementor_adapter ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$editor_visit_count = $this->elementor_adapter->get_count( Elementor_Counter::EDITOR_COUNTER_KEY );
|
||||
return $editor_visit_count < 3;
|
||||
}
|
||||
|
||||
private function has_welcome_popover_been_displayed(): bool {
|
||||
return get_user_meta( $this->get_current_user_id(), Module::WELCOME_POPOVER_DISPLAYED_OPTION, true );
|
||||
}
|
||||
|
||||
private function set_welcome_popover_as_displayed(): void {
|
||||
update_user_meta( $this->get_current_user_id(), Module::WELCOME_POPOVER_DISPLAYED_OPTION, true );
|
||||
}
|
||||
|
||||
private function enqueue_scripts() {
|
||||
$min_suffix = Utils::is_script_debug() ? '' : '.min';
|
||||
|
||||
wp_enqueue_script(
|
||||
Module::MODULE_NAME . '-welcome',
|
||||
ELEMENTOR_ASSETS_URL . 'js/editor-v4-welcome-opt-in' . $min_suffix . '.js',
|
||||
[
|
||||
'react',
|
||||
'react-dom',
|
||||
'elementor-common',
|
||||
'elementor-v2-ui',
|
||||
],
|
||||
ELEMENTOR_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( Module::MODULE_NAME . '-welcome', 'elementor' );
|
||||
}
|
||||
|
||||
|
||||
private function get_current_user_id(): int {
|
||||
$current_user = wp_get_current_user();
|
||||
return $current_user->ID ?? 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user