$this->get_wizard_steps(), 'translation_strings' => $this->get_translation_strings(), 'page_slug' => 'tptn_wizard', 'menu_args' => array( 'parent' => 'tptn_options_page', 'capability' => 'manage_options', ), ); parent::__construct( $settings_key, $prefix, $args ); $this->additional_hooks(); } /** * Additional hooks specific to Top 10. * * @since 4.2.0 */ protected function additional_hooks() { // Trigger wizard setup logic on plugin activation. add_action( 'tptn_activate', array( $this, 'trigger_wizard_on_activation' ) ); // Register Tom Select AJAX handlers for wizard taxonomy fields. add_action( 'wp_ajax_nopriv_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) ); add_action( 'wp_ajax_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) ); } /** * Get wizard steps configuration. * * @since 4.2.0 * * @return array Wizard steps. */ public function get_wizard_steps() { $all_settings_grouped = Settings::get_registered_settings(); $all_settings = array(); foreach ( $all_settings_grouped as $section_settings ) { $all_settings = array_merge( $all_settings, $section_settings ); } $basic_settings_keys = array( 'add_to', 'limit', 'post_types', 'range_desc', 'daily_range', 'hour_range', ); $display_settings_keys = array( 'title', 'title_daily', 'show_excerpt', 'show_author', 'show_date', 'post_thumb_op', 'thumb_size', ); $content_tuning_keys = array( 'exclude_front', 'exclude_post_ids', 'exclude_cat_slugs', 'exclude_on_cat_slugs', ); $admin_settings_keys = array( 'show_metabox', 'show_metabox_admins', 'pv_in_admin', 'show_count_non_admins', ); $pro_settings_keys = array( 'use_global_settings', 'admin_column_post_types', 'show_dashboard_to_roles', 'max_execution_time', ); $steps = array( 'welcome' => array( 'title' => __( 'Welcome to Top 10', 'top-10' ), 'description' => __( 'Thank you for installing Top 10! This wizard will help you configure the essential settings to get your popular posts list working perfectly.', 'top-10' ), 'settings' => array(), ), 'basic_settings' => array( 'title' => __( 'Basic Settings', 'top-10' ), 'description' => __( 'Configure how Top 10 tracks and counts your popular posts.', 'top-10' ), 'settings' => $this->build_step_settings( $basic_settings_keys, $all_settings ), ), 'display_options' => array( 'title' => __( 'Display Options', 'top-10' ), 'description' => __( 'Customize how your popular posts list will look and what information to display.', 'top-10' ), 'settings' => $this->build_step_settings( $display_settings_keys, $all_settings ), ), 'content_tuning' => array( 'title' => __( 'Content Tuning', 'top-10' ), 'description' => __( 'Fine-tune which content is included and how posts are excluded from the list.', 'top-10' ), 'settings' => $this->build_step_settings( $content_tuning_keys, $all_settings ), ), 'admin_settings' => array( 'title' => __( 'Admin Settings', 'top-10' ), 'description' => __( 'Configure how Top 10 integrates with your admin area, dashboards, and user roles.', 'top-10' ), 'settings' => $this->build_step_settings( $admin_settings_keys, $all_settings ), ), 'pro_settings' => array( 'title' => __( 'Pro Settings', 'top-10' ), 'description' => __( 'Configure Pro-only options such as global block settings, category exclusions, and query optimisation. These features require Top 10 Pro.', 'top-10' ), 'settings' => $this->build_step_settings( $pro_settings_keys, $all_settings ), ), ); /** * Filter wizard steps. * * @param array $steps Wizard steps. */ return apply_filters( 'tptn_wizard_steps', $steps ); } /** * Build settings array for a wizard step from keys. * * @since 4.2.0 * * @param array $keys Setting keys for this step. * @param array $all_settings All settings array. * @return array */ protected function build_step_settings( $keys, $all_settings ) { $step_settings = array(); foreach ( $keys as $key ) { if ( isset( $all_settings[ $key ] ) ) { $step_settings[ $key ] = $all_settings[ $key ]; } } return $step_settings; } /** * Get translation strings for the wizard. * * @since 4.2.0 * * @return array Translation strings. */ public function get_translation_strings() { return array( 'page_title' => __( 'Top 10 Setup Wizard', 'top-10' ), 'menu_title' => __( 'Setup Wizard', 'top-10' ), 'next_step' => __( 'Next Step', 'top-10' ), 'previous_step' => __( 'Previous Step', 'top-10' ), 'finish_setup' => __( 'Finish Setup', 'top-10' ), 'skip_wizard' => __( 'Skip Wizard', 'top-10' ), /* translators: %s: Search query. */ 'tom_select_no_results' => __( 'No results found for "%s"', 'top-10' ), 'steps_nav_aria_label' => __( 'Setup Wizard Steps', 'top-10' ), /* translators: %1$d: Current step number, %2$d: Total number of steps */ 'step_of' => __( 'Step %1$d of %2$d', 'top-10' ), 'wizard_complete' => __( 'Setup Complete!', 'top-10' ), 'setup_complete' => __( 'Your Top 10 plugin has been configured successfully. You can now start displaying popular posts on your site!', 'top-10' ), 'go_to_settings' => __( 'Go to Settings', 'top-10' ), 'checkbox_modified' => __( 'Modified from default setting', 'top-10' ), ); } /** * Trigger wizard on plugin activation. * * @since 4.2.0 */ public function trigger_wizard_on_activation() { // Set a transient that will trigger the wizard on first admin page visit. // This works better than an option because it's temporary and won't persist // if the wizard is never accessed. set_transient( 'tptn_show_wizard_activation_redirect', true, HOUR_IN_SECONDS ); // Also set an option for more persistent storage in multisite environments. update_option( 'tptn_show_wizard', true ); } /** * Get the URL to redirect to after wizard completion. * * @since 4.2.0 * * @return string Redirect URL. */ protected function get_completion_redirect_url() { return admin_url( 'admin.php?page=tptn_options_page' ); } /** * Override render_wizard_page to handle custom steps. * * @since 4.2.0 */ public function render_wizard_page() { $this->current_step = $this->get_current_step(); $step_config = $this->get_current_step_config(); if ( empty( $step_config ) ) { $this->render_completion_page(); return; } // Check if this is a custom step. if ( ! empty( $step_config['custom_step'] ) ) { $this->render_custom_tables_step( $step_config ); return; } // Use parent method for regular steps. parent::render_wizard_page(); } /** * Render the custom tables indexing step. * * @since 4.2.0 * * @param array $step_config Step configuration. */ protected function render_custom_tables_step( $step_config ) { ?>

translation_strings['wizard_title'] ); ?>

render_wizard_steps_navigation(); ?>

translation_strings['step_of'] ), esc_html( (string) $this->current_step ), esc_html( (string) $this->total_steps ) ); ?>

prefix}_wizard_nonce", "{$this->prefix}_wizard_nonce" ); ?>
render_custom_tables_interface(); ?>
render_wizard_buttons(); ?>

translation_strings['wizard_complete'] ); ?>

translation_strings['setup_complete'] ); ?>