| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Modules\Admin\Components; |
| 4 |
|
| 5 |
use HelloPlus\Includes\Utils; |
| 6 |
use HelloPlus\Modules\Admin\Classes\Menu\Pages\Settings; |
| 7 |
use HelloPlus\Modules\Admin\Classes\Menu\Pages\Setup_Wizard; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Admin_Menu_Controller { |
| 14 |
|
| 15 |
const SETUP_WIZARD_TRANSIENT_NAME = 'helloplus_redirect_to_setup_wizard'; |
| 16 |
|
| 17 |
public function admin_menu( $parent_slug ) { |
| 18 |
if ( Utils::has_hello_elementor_theme() ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
$setup_wizard = new Setup_Wizard(); |
| 22 |
$setup_wizard->register_setup_wizard_page( $parent_slug ); |
| 23 |
} |
| 24 |
|
| 25 |
public function activate() { |
| 26 |
if ( ! Setup_Wizard::has_site_wizard_been_completed() ) { |
| 27 |
set_transient( self::SETUP_WIZARD_TRANSIENT_NAME, true ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function redirect_on_first_activation() { |
| 32 |
if ( empty( get_transient( self::SETUP_WIZARD_TRANSIENT_NAME ) ) ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
if ( ! is_admin() ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
delete_transient( self::SETUP_WIZARD_TRANSIENT_NAME ); |
| 40 |
|
| 41 |
if ( Utils::are_we_on_elementor_domains() ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
if ( Utils::is_test_environment() ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
wp_safe_redirect( self_admin_url( 'admin.php?page=' . Setup_Wizard::SETUP_WIZARD_PAGE_SLUG ) ); |
| 50 |
exit; |
| 51 |
} |
| 52 |
|
| 53 |
public function __construct() { |
| 54 |
add_action( 'hello-plus-theme/admin-menu', [ $this, 'admin_menu' ], 10, 1 ); |
| 55 |
add_action( 'hello-plus/init', [ $this, 'redirect_on_first_activation' ] ); |
| 56 |
if ( ! Utils::has_hello_elementor_theme() ) { |
| 57 |
add_action( 'hello-plus/activate', [ $this, 'activate' ] ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|