Skip to content

Commit 97af2a1

Browse files
committed
feat: enhance setup wizard with progress indicators and improve admin notifications
1 parent f6f750a commit 97af2a1

File tree

8 files changed

+44
-11
lines changed

8 files changed

+44
-11
lines changed

includes/admin/class-setup-wizard.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,15 @@ public function render_wizard() {
198198
* @return void
199199
*/
200200
public function setup_wizard_steps() {
201-
$output_steps = $this->steps;
201+
$output_steps = $this->steps;
202+
$total_steps = count( $output_steps );
203+
$current_step_num = array_search( $this->current_step, array_keys( $this->steps ), true ) + 1;
204+
$progress_percent = ( $current_step_num / $total_steps ) * 100;
202205
?>
203-
<ol class="wzkb-setup-steps" role="tablist" aria-label="<?php esc_attr_e( 'Setup Wizard Steps', 'knowledgebase' ); ?>">
206+
<ol class="wzkb-setup-steps" role="tablist" aria-label="<?php esc_attr_e( 'Setup Wizard Steps', 'knowledgebase' ); ?>" aria-valuenow="<?php echo esc_attr( (string) $current_step_num ); ?>" aria-valuemin="1" aria-valuemax="<?php echo esc_attr( (string) $total_steps ); ?>">
204207
<?php
208+
/* translators: 1: Current step number, 2: Total steps, 3: Progress percentage */
209+
echo '<span class="screen-reader-text">' . esc_html( sprintf( __( 'Step %1$d of %2$d (%3$d%% complete)', 'knowledgebase' ), $current_step_num, $total_steps, round( $progress_percent ) ) ) . '</span>';
205210
foreach ( $output_steps as $step_key => $step ) {
206211
$is_completed = array_search( $this->current_step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true );
207212
$aria_current = $step_key === $this->current_step ? ' aria-current="step"' : '';

includes/admin/css/wizard.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,23 +526,23 @@
526526
flex-direction: column;
527527
gap: 15px;
528528
}
529-
529+
530530
.wzkb-setup-next-actions-horizontal li {
531531
min-width: auto;
532532
}
533-
533+
534534
.wzkb-setup-pro-actions {
535535
flex-direction: column;
536536
}
537-
537+
538538
.wzkb-setup-pro-actions li {
539539
min-width: auto;
540540
}
541-
541+
542542
.wzkb-setup-resource-links {
543543
flex-direction: column;
544544
}
545-
545+
546546
.wzkb-setup-resource-links li {
547547
min-width: auto;
548548
}

includes/admin/js/admin-scripts.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,42 @@ jQuery(document).ready(
1515
security: WZKBAdminData.security
1616
}, function (response) {
1717
if (response.success) {
18-
alert(WZKBAdminData.strings.success_message);
18+
// Use WordPress admin notice instead of alert().
19+
showAdminNotice(WZKBAdminData.strings.success_message, 'success');
1920
} else {
20-
alert(WZKBAdminData.strings.fail_message);
21+
showAdminNotice(WZKBAdminData.strings.fail_message, 'error');
2122
}
2223
}).fail(function (jqXHR, textStatus) {
23-
alert(WZKBAdminData.strings.fail_message);
24+
showAdminNotice(WZKBAdminData.strings.fail_message, 'error');
2425
console.log(WZKBAdminData.strings.request_fail_message + textStatus);
2526
}).always(function () {
2627
$button.prop('disabled', false).find('.spinner').remove();
2728
});
2829
}
2930

31+
// Function to show WordPress admin notices.
32+
function showAdminNotice(message, type) {
33+
var noticeClass = type === 'success' ? 'notice-success' : 'notice-error';
34+
var $notice = $('<div class="notice ' + noticeClass + ' is-dismissible"><p>' + message + '</p></div>');
35+
36+
// Insert notice after the first h1 or h2 in the page.
37+
if ($('.wrap > h1, .wrap > h2').length) {
38+
$('.wrap > h1, .wrap > h2').first().after($notice);
39+
} else {
40+
$('.wrap').prepend($notice);
41+
}
42+
43+
// Scroll to notice.
44+
$('html, body').animate({ scrollTop: $notice.offset().top - 100 }, 300);
45+
46+
// Auto-dismiss after 5 seconds.
47+
setTimeout(function() {
48+
$notice.fadeOut(300, function() {
49+
$(this).remove();
50+
});
51+
}, 5000);
52+
}
53+
3054
// Prompt the user when they leave the page without saving the form.
3155
var formmodified = 0;
3256

includes/admin/js/admin-scripts.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/frontend/templates/archive-wz_knowledgebase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
wp_enqueue_style( 'wz-knowledgebase-styles' );
1818
}
1919
?>
20+
<a href="#main" class="skip-link screen-reader-text"><?php esc_html_e( 'Skip to content', 'knowledgebase' ); ?></a>
2021
<div class="wrap">
2122
<div id="wzkb-content-primary" class="content-area">
2223
<main id="main" class="site-main" role="main">

includes/frontend/templates/single-wz_knowledgebase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
wp_enqueue_style( 'wz-knowledgebase-styles' );
1818
}
1919
?>
20+
<a href="#main" class="skip-link screen-reader-text"><?php esc_html_e( 'Skip to content', 'knowledgebase' ); ?></a>
2021
<div class="wrap">
2122
<div id="wzkb-content-primary" class="content-area">
2223
<main id="main" class="site-main" role="main">

includes/frontend/templates/taxonomy-wzkb_category.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727

2828
?>
29+
<a href="#main" class="skip-link screen-reader-text"><?php esc_html_e( 'Skip to content', 'knowledgebase' ); ?></a>
2930
<div class="wrap">
3031
<div id="wzkb-content-primary" class="content-area">
3132
<main id="main" class="site-main" role="main">

includes/frontend/templates/taxonomy-wzkb_product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
wp_enqueue_style( 'wz-knowledgebase-styles' );
2020
}
2121
?>
22+
<a href="#main" class="skip-link screen-reader-text"><?php esc_html_e( 'Skip to content', 'knowledgebase' ); ?></a>
2223
<div class="wrap">
2324
<div id="wzkb-content-primary" class="content-area">
2425
<main id="main" class="site-main" role="main">

0 commit comments

Comments
 (0)