options = (array) AdminSettings::get_instance()->get(); $this->jltwp_adminify_setup_wizard(); add_action( 'wp_ajax_wpadminify_save_wizard_data', [ $this, 'wpadminify_save_wizard_data' ] ); } } public function validate_before_save( $settings ) { // Customize $settings['admin_bar_mode'] = ( wp_validate_boolean( $settings['admin_bar_mode'] ) ? '' : 'dark' ); // Admin Bar if ( empty($settings['admin_bar_settings']['admin_bar_position']) ) { $settings['admin_bar_settings']['admin_bar_position'] = 'top'; } foreach ( $settings as $key => $setting ) { $settings[$key] = $this->maybe_convert_to_boolean( $setting ); } return $settings; } public function maybe_convert_to_boolean( &$setting ) { if ( gettype( $setting ) == 'string' && ($setting === 'true' || $setting === 'false') ) { $setting = wp_validate_boolean( $setting ); } else { if ( gettype( $setting ) == 'array' ) { foreach ( $setting as $key => $_setting ) { $setting[$key] = $this->maybe_convert_to_boolean( $_setting ); } } } return $setting; } public function wpadminify_save_wizard_data() { check_ajax_referer( 'jltwp_adminify_sw' ); $this->setup_steps(); if ( !empty($_POST['active_step']) ) { $this->step = $_POST['active_step']; } $settings = ( empty($_POST['settings']) ? [] : (array) $_POST['settings'] ); $settings = $this->validate_before_save( $settings ); update_option( '_wpadminify', $settings ); wp_send_json_success( [ 'redirect' => $this->get_next_step_link(), ] ); } public function load_scripts() { // Register wp_register_script( 'wp-adminify-vue-manifest', WP_ADMINIFY_ASSETS . 'admin/js/manifest.js', [], WP_ADMINIFY_VER, true ); wp_register_script( 'wp-adminify-vue-vendors', WP_ADMINIFY_ASSETS . 'admin/js/vendor.js', [ 'wp-adminify-vue-manifest' ], WP_ADMINIFY_VER, true ); wp_register_style( 'wp-adminify-sw-setup', WP_ADMINIFY_ASSETS . 'css/setup.css', array( 'dashicons', 'install' ) ); wp_register_script( 'wp-adminify-sw-setup', WP_ADMINIFY_ASSETS . 'admin/js/wp-adminify--setup-wizard.js', [ 'jquery', 'wp-adminify-vue-vendors' ], WP_ADMINIFY_VER, true ); // Media Uploader wp_enqueue_media(); // Load wp_enqueue_style( 'wp-adminify-sw-setup' ); wp_enqueue_script( 'wp-adminify-sw-setup' ); // Localize Script $adminify_data = [ "settings" => $this->get_validated_settings(), "wpnonce" => wp_create_nonce( 'jltwp_adminify_sw' ), ]; wp_localize_script( 'wp-adminify-sw-setup', 'adminify_setup_wizard_data', $adminify_data ); } public function get_validated_settings() { // Module $boolean_settings = [ 'admin_ui', 'folders', 'login_customizer', 'admin_columns', 'menu_editor', 'dashboard_widgets', 'pagespeed_insights', 'custom_css_js', 'quick_menu', 'menu_duplicator', 'notification_bar', 'activity_logs', 'post_duplicator', 'admin_pages', 'sidebar_generator', 'post_types_order', 'server_info', 'disable_comments' ]; foreach ( $boolean_settings as $b_setting ) { $this->options[$b_setting] = wp_validate_boolean( $this->options[$b_setting] ); } // Customize $this->options['admin_bar_mode'] = $this->options['admin_bar_mode'] == 'light'; // Admin Bar $admin_bar_settings = [ 'admin_bar_menu', 'admin_bar_search', 'admin_bar_comments', 'admin_bar_view_website', 'admin_bar_dark_light_btn' ]; foreach ( $admin_bar_settings as $admin_bar_setting ) { $this->options['admin_bar_settings'][$admin_bar_setting] = wp_validate_boolean( $this->options['admin_bar_settings'][$admin_bar_setting] ); } if ( empty($this->options['admin_bar_settings']['admin_bar_position']) ) { $this->options['admin_bar_settings']['admin_bar_position'] = 'top'; } // Tweaks $tweaks = [ 'generator_wp_version', 'remove_version_strings', 'remove_dashicons', 'remove_shortlink', 'remove_canonical', 'remove_emoji', 'disable_xmlrpc', 'remove_feed', 'remove_pingback', 'remove_powered', 'gravatar_query_strings' ]; foreach ( $tweaks as $tweak ) { $this->options[$tweak] = wp_validate_boolean( $this->options[$tweak] ); } $admin_notices = [ 'hide_notices', 'remove_welcome_panel', 'remove_php_update_required_nag', 'remove_try_gutenberg_panel', 'core_update_notice', 'plugin_update_notice', 'theme_update_notice' ]; foreach ( $admin_notices as $admin_notice ) { $this->options[$admin_notice] = wp_validate_boolean( $this->options[$admin_notice] ); } return $this->options; } public function setup_steps() { $this->steps = array( 'intro' => [ 'name' => esc_html__( 'Introduction', 'adminify' ), 'view' => [ $this, 'jltwp_adminify_step_introduction' ], ], 'module' => [ 'name' => esc_html__( 'Module', 'adminify' ), 'view' => [ $this, 'setup_step_modules' ], ], 'customize' => [ 'name' => esc_html__( 'Customize', 'adminify' ), 'view' => [ $this, 'setup_step_customize' ], ], 'menu' => [ 'name' => esc_html__( 'Menu', 'adminify' ), 'view' => [ $this, 'setup_step_menu' ], ], 'admin_bar' => [ 'name' => esc_html__( 'Admin Bar', 'adminify' ), 'view' => [ $this, 'setup_step_admin_bar' ], ], 'tweaks' => [ 'name' => esc_html__( 'Tweaks', 'adminify' ), 'view' => [ $this, 'setup_step_tweaks' ], ], 'admin_notices' => array( 'name' => esc_html__( 'Admin Notices', 'adminify' ), 'view' => array( $this, 'setup_step_admin_notices' ), ), 'next_steps' => array( 'name' => esc_html__( 'Ready!', 'adminify' ), 'view' => array( $this, 'setup_step_ready' ), ), ); $this->step = ( isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ) ); } public function jltwp_adminify_setup_wizard() { if ( empty($_GET['page']) || 'wp-adminify-setup-wizard' !== $_GET['page'] ) { return; } $this->setup_steps(); $this->load_scripts(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $this->setup_wizard_content(); $this->setup_wizard_footer(); exit; } function jltwp_adminify_get_content_info( &$site_title, &$tagline, &$admin_email, &$defa_cat, &$set_permalink, &$users_can_register, &$wpsw_date_format, &$wpsw_time_format ) { $site_title = get_bloginfo( 'name' ); $tagline = get_bloginfo( 'description' ); $admin_email = get_bloginfo( 'admin_email' ); $default_category = get_option( 'default_category' ); $defa_cat = get_cat_name( $default_category ); $set_permalink = get_option( 'permalink_structure' ); $users_can_register = get_option( 'users_can_register' ); $wpsw_date_format = get_option( 'date_format' ); $wpsw_time_format = get_option( 'time_format' ); } public function get_wizard_url() { return admin_url( 'index.php?page=wp-adminify-setup-wizard' ); } public function get_next_step_link() { $keys = array_keys( $this->steps ); return add_query_arg( 'step', $keys[array_search( $this->step, array_keys( $this->steps ) ) + 1], $this->get_wizard_url() ); } public function get_prev_step_link() { $keys = array_keys( $this->steps ); return add_query_arg( 'step', $keys[array_search( $this->step, array_keys( $this->steps ) ) - 1], $this->get_wizard_url() ); } public function setup_wizard_header() { header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); if ( !defined( 'WP_ADMIN' ) ) { require_once ABSPATH . 'wp-admin/admin.php'; } global $title, $hook_suffix, $current_screen, $wp_locale, $pagenow, $update_title, $total_update_count, $parent_file ; if ( empty($current_screen) ) { set_current_screen(); } get_admin_page_title(); $title = strip_tags( $title ); if ( is_network_admin() ) { $admin_title = sprintf( __( 'Network Admin: %s' ), get_network()->site_name ); } elseif ( is_user_admin() ) { $admin_title = sprintf( __( 'User Dashboard: %s' ), get_network()->site_name ); } else { $admin_title = get_bloginfo( 'name' ); } if ( $admin_title === $title ) { $admin_title = sprintf( __( '%s — WordPress' ), $title ); } else { $admin_title = sprintf( __( '%1$s ‹ %2$s — WordPress' ), $title, $admin_title ); } if ( wp_is_recovery_mode() ) { $admin_title = sprintf( __( 'Recovery Mode — %s' ), $admin_title ); } $admin_title = apply_filters( 'admin_title', $admin_title, $title ); wp_user_settings(); _wp_admin_html_begin(); ?>