Translangated_Step_Welcome::class, 'languages' => Translangated_Step_Languages::class, 'switcher' => Translangated_Step_Switcher::class, 'finish' => Translangated_Step_Finish::class, ]; /** * The current onboarding step or an error. * * @var Translangated_Onboarding_Step_Interface|WP_Error */ protected $step; public function __construct( $settings ){ $this->settings = $settings; add_action( 'admin_init', array( $this, 'run_onboarding_admin' ) ); // Render both menu & admin page. add_action('admin_menu', array($this, 'register_onboarding')); } public function run_onboarding_admin(){ if (current_user_can('manage_options') && $this->is_onboarding()) { add_action('admin_head', array($this, 'remove_admin_notices')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_and_styles')); // Process form submissions on admin_init to prevent headers already sent issues. $this->step = $this->init_step(); $this->step_handle(); } } private function init_step(){ if(!current_user_can('manage_options') || !$this->is_onboarding()){ return new WP_Error('not_onboarding', __( 'Not Translangated onboarding page.', 'translangated' )); } if(file_exists(TRANSLANGATED_PLUGIN_DIR . 'includes/onboarding/interface-onboarding-step.php')){ require_once TRANSLANGATED_PLUGIN_DIR . 'includes/onboarding/interface-onboarding-step.php'; } $step = sanitize_text_field(isset($_GET['step']) ? $_GET['step'] : 'welcome'); $step_class = (isset($this->steps[$step])) ? $this->steps[$step] : null; if($step_class){ $file = TRANSLANGATED_PLUGIN_DIR . 'includes/onboarding/class-' . $step . '.php'; if (file_exists($file)) { include_once($file); } } if (!$step_class || !class_exists($step_class)) { return new WP_Error('invalid_step', sprintf( /* translators: %s: onboarding step identifier */ __( 'Step %s does not exist', 'translangated' ), $step)); } else { return new $step_class($this->settings); } } private function is_onboarding(): bool { if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return false; } if ( empty( $_GET['page'] ) || $_GET['page'] !== 'translangated-onboarding' ) { return false; } return true; } public function register_onboarding(){ add_submenu_page( 'translangated', 'Setup Wizard', 'Setup Wizard', 'manage_options', 'translangated-onboarding', array( $this, 'render_template' ) ); } public function render_template(){ $full_logo = TRANSLANGATED_PLUGIN_URL . 'assets/images/tp-logo-with-text-dark.svg'; $small_logo = TRANSLANGATED_PLUGIN_URL . 'assets/images/tp-logo.png'; // Whether a paid version of Translangated is active. Exposed on the content wrapper so the // onboarding script can detect Pro activation (performed on the WordPress "Add Plugins" page) // and refresh just the step markup instead of reloading the whole page. $trp = Translangated_Plugin::get_translangated_instance(); $is_pro = ! in_array( 'Translangated', $trp->tp_product_name ); ?>
step_render(); ?>
step instanceof Translangated_Onboarding_Step_Interface){ $this->step->handle( map_deep( wp_unslash( $_POST ), 'sanitize_text_field' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified by each step's handle() } } } public function step_render(){ if ($this->step instanceof Translangated_Onboarding_Step_Interface){ $this->step->render(); } else { esc_html_e('Nothing here', 'translangated'); } } public function remove_admin_notices(){ remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); } public function enqueue_scripts_and_styles(){ wp_enqueue_style('translangated-onboarding-style', TRANSLANGATED_PLUGIN_URL . 'assets/css/trp-onboarding-style.css', array(), TRANSLANGATED_PLUGIN_VERSION); wp_enqueue_script( 'translangated-select2-lib-js', TRANSLANGATED_PLUGIN_URL . 'assets/lib/select2-lib/dist/js/select2.min.js', array( 'jquery' ), '4.1.0' ); wp_enqueue_style( 'translangated-select2-lib-css', TRANSLANGATED_PLUGIN_URL . 'assets/lib/select2-lib/dist/css/select2.min.css', array(), '4.1.0' ); // Register and enqueue your script wp_enqueue_script('translangated-onboarding-js', TRANSLANGATED_PLUGIN_URL . 'assets/js/trp-onboarding-script.js', array('jquery', 'translangated-select2-lib-js'), TRANSLANGATED_PLUGIN_VERSION,true); // Localize the script with a variable $translation_array = array( 'translangated_secondary_languages' => apply_filters('translangated_secondary_languages', 1), ); wp_localize_script('translangated-onboarding-js', 'translangated_onboarding_vars', $translation_array); } }