module.php
5 months ago
opt-in-page.php
4 months ago
panel-chip.php
10 months ago
welcome-screen.php
8 months ago
opt-in-page.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor\Modules\AtomicOptIn; |
| 4 | |
| 5 | use Elementor\Plugin; |
| 6 | use Elementor\Settings; |
| 7 | use Elementor\User; |
| 8 | use Elementor\Utils; |
| 9 | |
| 10 | class OptInPage { |
| 11 | private Module $module; |
| 12 | |
| 13 | public function __construct( Module $module ) { |
| 14 | $this->module = $module; |
| 15 | } |
| 16 | |
| 17 | public function init() { |
| 18 | if ( ! current_user_can( 'manage_options' ) ) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | $this->register_assets(); |
| 23 | $this->add_settings_tab(); |
| 24 | } |
| 25 | |
| 26 | private function register_assets() { |
| 27 | $page_id = Settings::PAGE_ID; |
| 28 | |
| 29 | add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'enqueue_scripts' ] ); |
| 30 | add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'enqueue_styles' ] ); |
| 31 | } |
| 32 | |
| 33 | public function enqueue_styles() { |
| 34 | wp_enqueue_style( |
| 35 | Module::MODULE_NAME, |
| 36 | $this->module->get_opt_in_css_assets_url( 'modules/editor-v4-opt-in/opt-in' ), |
| 37 | [], |
| 38 | ELEMENTOR_VERSION |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | public function enqueue_scripts() { |
| 43 | $min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 44 | |
| 45 | wp_enqueue_script( |
| 46 | Module::MODULE_NAME, |
| 47 | ELEMENTOR_ASSETS_URL . 'js/editor-v4-opt-in' . $min_suffix . '.js', |
| 48 | [ |
| 49 | 'react', |
| 50 | 'react-dom', |
| 51 | 'elementor-common', |
| 52 | 'elementor-v2-ui', |
| 53 | ], |
| 54 | ELEMENTOR_VERSION, |
| 55 | true |
| 56 | ); |
| 57 | |
| 58 | wp_localize_script( |
| 59 | Module::MODULE_NAME, |
| 60 | 'elementorSettingsEditor4OptIn', |
| 61 | $this->prepare_data() |
| 62 | ); |
| 63 | |
| 64 | wp_set_script_translations( Module::MODULE_NAME, 'elementor' ); |
| 65 | } |
| 66 | |
| 67 | private function prepare_data() { |
| 68 | $create_new_post_type = User::is_current_user_can_edit_post_type( 'page' ) ? 'page' : 'post'; |
| 69 | |
| 70 | return [ |
| 71 | 'features' => [ |
| 72 | 'editor_v4' => $this->module->is_atomic_experiment_active(), |
| 73 | ], |
| 74 | 'urls' => [ |
| 75 | 'start_building' => esc_url( Plugin::$instance->documents->get_create_new_post_url( $create_new_post_type ) ), |
| 76 | ], |
| 77 | ]; |
| 78 | } |
| 79 | |
| 80 | private function add_settings_tab() { |
| 81 | $page_id = Settings::PAGE_ID; |
| 82 | |
| 83 | add_action( "elementor/admin/after_create_settings/{$page_id}", function( Settings $settings ) { |
| 84 | $this->add_new_tab_to( $settings ); |
| 85 | }, 11 ); |
| 86 | } |
| 87 | |
| 88 | private function add_new_tab_to( Settings $settings ) { |
| 89 | $settings->add_tab( Module::MODULE_NAME, [ |
| 90 | 'label' => esc_html__( 'Version 4', 'elementor' ), |
| 91 | 'sections' => [ |
| 92 | 'opt-in' => [ |
| 93 | 'callback' => function() { |
| 94 | echo '<div id="page-editor-v4-opt-in"></div>'; |
| 95 | }, |
| 96 | 'fields' => [], |
| 97 | ], |
| 98 | ], |
| 99 | ] ); |
| 100 | } |
| 101 | } |
| 102 |