PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.1
WebberZone Top 10 — Popular Posts v4.3.1
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / includes / admin / class-settings-wizard.php

class-settings-wizard.php in WebberZone Top 10 — Popular Posts 4.3.1, at includes/admin/class-settings-wizard.php

352 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settings Wizard class.
4 *
5 * @package WebberZone\Top_Ten\Admin
6 */
7
8 namespace WebberZone\Top_Ten\Admin;
9
10 use WebberZone\Top_Ten\Admin\Settings\Settings_Wizard_API;
11 use WebberZone\Top_Ten\Admin\Settings;
12 use function WebberZone\Top_Ten\wz_top_ten;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 /**
20 * Settings Wizard class for Top 10.
21 *
22 * @since 4.2.0
23 */
24 class Settings_Wizard extends Settings_Wizard_API {
25
26 /**
27 * Main constructor class.
28 *
29 * @since 4.2.0
30 */
31 public function __construct() {
32 $settings_key = 'tptn_settings';
33 $prefix = 'tptn';
34
35 $args = array(
36 'steps' => $this->get_wizard_steps(),
37 'translation_strings' => $this->get_translation_strings(),
38 'page_slug' => 'tptn_wizard',
39 'menu_args' => array(
40 'parent' => 'tptn_options_page',
41 'capability' => 'manage_options',
42 ),
43 );
44
45 parent::__construct( $settings_key, $prefix, $args );
46 $this->additional_hooks();
47 }
48
49 /**
50 * Additional hooks specific to Top 10.
51 *
52 * @since 4.2.0
53 */
54 protected function additional_hooks() {
55 // Trigger wizard setup logic on plugin activation.
56 add_action( 'tptn_activate', array( $this, 'trigger_wizard_on_activation' ) );
57
58 // Register Tom Select AJAX handlers for wizard taxonomy fields.
59 add_action( 'wp_ajax_nopriv_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) );
60 add_action( 'wp_ajax_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) );
61 }
62
63 /**
64 * Get wizard steps configuration.
65 *
66 * @since 4.2.0
67 *
68 * @return array Wizard steps.
69 */
70 public function get_wizard_steps() {
71 $all_settings_grouped = Settings::get_registered_settings();
72 $all_settings = array();
73 foreach ( $all_settings_grouped as $section_settings ) {
74 $all_settings = array_merge( $all_settings, $section_settings );
75 }
76
77 $basic_settings_keys = array(
78 'add_to',
79 'limit',
80 'post_types',
81 'range_desc',
82 'daily_range',
83 'hour_range',
84 );
85
86 $display_settings_keys = array(
87 'title',
88 'title_daily',
89 'show_excerpt',
90 'show_author',
91 'show_date',
92 'post_thumb_op',
93 'thumb_size',
94 );
95
96 $content_tuning_keys = array(
97 'exclude_front',
98 'exclude_post_ids',
99 'exclude_cat_slugs',
100 'exclude_on_cat_slugs',
101 );
102
103 $admin_settings_keys = array(
104 'show_metabox',
105 'show_metabox_admins',
106 'pv_in_admin',
107 'show_count_non_admins',
108 );
109
110 $pro_settings_keys = array(
111 'use_global_settings',
112 'admin_column_post_types',
113 'show_dashboard_to_roles',
114 'max_execution_time',
115 );
116
117 $steps = array(
118 'welcome' => array(
119 'title' => __( 'Welcome to Top 10', 'top-10' ),
120 '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' ),
121 'settings' => array(),
122 ),
123 'basic_settings' => array(
124 'title' => __( 'Basic Settings', 'top-10' ),
125 'description' => __( 'Configure how Top 10 tracks and counts your popular posts.', 'top-10' ),
126 'settings' => $this->build_step_settings( $basic_settings_keys, $all_settings ),
127 ),
128 'display_options' => array(
129 'title' => __( 'Display Options', 'top-10' ),
130 'description' => __( 'Customize how your popular posts list will look and what information to display.', 'top-10' ),
131 'settings' => $this->build_step_settings( $display_settings_keys, $all_settings ),
132 ),
133 'content_tuning' => array(
134 'title' => __( 'Content Tuning', 'top-10' ),
135 'description' => __( 'Fine-tune which content is included and how posts are excluded from the list.', 'top-10' ),
136 'settings' => $this->build_step_settings( $content_tuning_keys, $all_settings ),
137 ),
138 'admin_settings' => array(
139 'title' => __( 'Admin Settings', 'top-10' ),
140 'description' => __( 'Configure how Top 10 integrates with your admin area, dashboards, and user roles.', 'top-10' ),
141 'settings' => $this->build_step_settings( $admin_settings_keys, $all_settings ),
142 ),
143 'pro_settings' => array(
144 'title' => __( 'Pro Settings', 'top-10' ),
145 'description' => __( 'Configure Pro-only options such as global block settings, category exclusions, and query optimisation. These features require Top 10 Pro.', 'top-10' ),
146 'settings' => $this->build_step_settings( $pro_settings_keys, $all_settings ),
147 ),
148 );
149
150 /**
151 * Filter wizard steps.
152 *
153 * @param array $steps Wizard steps.
154 */
155 return apply_filters( 'tptn_wizard_steps', $steps );
156 }
157
158 /**
159 * Build settings array for a wizard step from keys.
160 *
161 * @since 4.2.0
162 *
163 * @param array $keys Setting keys for this step.
164 * @param array $all_settings All settings array.
165 * @return array
166 */
167 protected function build_step_settings( $keys, $all_settings ) {
168 $step_settings = array();
169
170 foreach ( $keys as $key ) {
171 if ( isset( $all_settings[ $key ] ) ) {
172 $step_settings[ $key ] = $all_settings[ $key ];
173 }
174 }
175
176 return $step_settings;
177 }
178
179 /**
180 * Get translation strings for the wizard.
181 *
182 * @since 4.2.0
183 *
184 * @return array Translation strings.
185 */
186 public function get_translation_strings() {
187 return array(
188 'page_title' => __( 'Top 10 Setup Wizard', 'top-10' ),
189 'menu_title' => __( 'Setup Wizard', 'top-10' ),
190 'next_step' => __( 'Next Step', 'top-10' ),
191 'previous_step' => __( 'Previous Step', 'top-10' ),
192 'finish_setup' => __( 'Finish Setup', 'top-10' ),
193 'skip_wizard' => __( 'Skip Wizard', 'top-10' ),
194 /* translators: %s: Search query. */
195 'tom_select_no_results' => __( 'No results found for "%s"', 'top-10' ),
196 'steps_nav_aria_label' => __( 'Setup Wizard Steps', 'top-10' ),
197 /* translators: %1$d: Current step number, %2$d: Total number of steps */
198 'step_of' => __( 'Step %1$d of %2$d', 'top-10' ),
199 'wizard_complete' => __( 'Setup Complete!', 'top-10' ),
200 'setup_complete' => __( 'Your Top 10 plugin has been configured successfully. You can now start displaying popular posts on your site!', 'top-10' ),
201 'go_to_settings' => __( 'Go to Settings', 'top-10' ),
202 'checkbox_modified' => __( 'Modified from default setting', 'top-10' ),
203 );
204 }
205
206 /**
207 * Trigger wizard on plugin activation.
208 *
209 * @since 4.2.0
210 */
211 public function trigger_wizard_on_activation() {
212 // Set a transient that will trigger the wizard on first admin page visit.
213 // This works better than an option because it's temporary and won't persist
214 // if the wizard is never accessed.
215 set_transient( 'tptn_show_wizard_activation_redirect', true, HOUR_IN_SECONDS );
216
217 // Also set an option for more persistent storage in multisite environments.
218 update_option( 'tptn_show_wizard', true );
219 }
220
221 /**
222 * Get the URL to redirect to after wizard completion.
223 *
224 * @since 4.2.0
225 *
226 * @return string Redirect URL.
227 */
228 protected function get_completion_redirect_url() {
229 return admin_url( 'admin.php?page=tptn_options_page' );
230 }
231
232 /**
233 * Override render_wizard_page to handle custom steps.
234 *
235 * @since 4.2.0
236 */
237 public function render_wizard_page() {
238 $this->current_step = $this->get_current_step();
239 $step_config = $this->get_current_step_config();
240
241 if ( empty( $step_config ) ) {
242 $this->render_completion_page();
243 return;
244 }
245
246 // Check if this is a custom step.
247 if ( ! empty( $step_config['custom_step'] ) ) {
248 $this->render_custom_tables_step( $step_config );
249 return;
250 }
251
252 // Use parent method for regular steps.
253 parent::render_wizard_page();
254 }
255
256 /**
257 * Render the custom tables indexing step.
258 *
259 * @since 4.2.0
260 *
261 * @param array $step_config Step configuration.
262 */
263 protected function render_custom_tables_step( $step_config ) {
264 ?>
265 <div class="wrap wizard-wrap">
266 <h1><?php echo esc_html( $this->translation_strings['wizard_title'] ); ?></h1>
267
268 <?php $this->render_wizard_steps_navigation(); ?>
269
270 <div class="wizard-progress">
271 <div class="wizard-progress-bar">
272 <div class="wizard-progress-fill" style="width: <?php echo esc_attr( (string) ( ( $this->current_step / $this->total_steps ) * 100 ) ); ?>%;"></div>
273 </div>
274 <p class="wizard-step-counter">
275 <?php
276 printf(
277 esc_html( $this->translation_strings['step_of'] ),
278 esc_html( (string) $this->current_step ),
279 esc_html( (string) $this->total_steps )
280 );
281 ?>
282 </p>
283 </div>
284
285 <div class="wizard-content">
286 <div class="wizard-step">
287 <h2><?php echo esc_html( $step_config['title'] ?? '' ); ?></h2>
288
289 <?php if ( ! empty( $step_config['description'] ) ) : ?>
290 <p class="wizard-step-description"><?php echo wp_kses_post( $step_config['description'] ); ?></p>
291 <?php endif; ?>
292
293 <form method="post" action="">
294 <?php wp_nonce_field( "{$this->prefix}_wizard_nonce", "{$this->prefix}_wizard_nonce" ); ?>
295
296 <div class="wizard-fields">
297 <?php $this->render_custom_tables_interface(); ?>
298 </div>
299
300 <div class="wizard-actions">
301 <?php $this->render_wizard_buttons(); ?>
302 </div>
303 </form>
304 </div>
305 </div>
306 </div>
307 <?php
308 }
309
310 /**
311 * Render the custom tables indexing interface.
312 *
313 * @since 4.2.0
314 */
315 protected function render_custom_tables_interface() {
316 // Top 10 does not implement the CRP custom tables UI in its wizard.
317 // Intentionally left blank.
318 }
319
320 /**
321 * Override the render completion page to show Top 10 specific content.
322 *
323 * @since 4.2.0
324 */
325 protected function render_completion_page() {
326 ?>
327 <div class="wrap wizard-wrap wizard-complete">
328 <div class="wizard-completion-header">
329 <h1><?php echo esc_html( $this->translation_strings['wizard_complete'] ); ?></h1>
330 <p class="wizard-completion-message">
331 <?php echo esc_html( $this->translation_strings['setup_complete'] ); ?>
332 </p>
333 </div>
334
335 <div class="wizard-completion-content">
336 <div class="wizard-completion-actions">
337 <a href="<?php echo esc_url( $this->get_completion_redirect_url() ); ?>" class="button button-primary button-large">
338 <?php esc_html_e( 'Go to Settings', 'top-10' ); ?>
339 </a>
340 <a href="<?php echo esc_url( admin_url( 'admin.php?page=tptn_tools_page' ) ); ?>" class="button button-secondary button-large">
341 <?php esc_html_e( 'Go to Tools', 'top-10' ); ?>
342 </a>
343 <a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="button button-secondary button-large" target="_blank" rel="noopener noreferrer">
344 <?php esc_html_e( 'View Site', 'top-10' ); ?>
345 </a>
346 </div>
347 </div>
348 </div>
349 <?php
350 }
351 }
352