Skip to content

Commit 04e24d2

Browse files
committed
Add hash handling to site health accordions
1 parent fb4ec6f commit 04e24d2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/js/_enqueues/admin/site-health.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jQuery( function( $ ) {
4444
$( '.health-check-accordion' ).on( 'click', '.health-check-accordion-trigger', function() {
4545
var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
4646

47+
window.location.hash = $( this ).attr( 'id' );
48+
4749
if ( isExpanded ) {
4850
$( this ).attr( 'aria-expanded', 'false' );
4951
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
@@ -53,6 +55,19 @@ jQuery( function( $ ) {
5355
}
5456
} );
5557

58+
// Get hash from query string and open the related accordion.
59+
setTimeout( function() {
60+
var hash = window.location.hash;
61+
62+
if ( hash ) {
63+
var requestedPanel = $( hash );
64+
65+
if ( requestedPanel.length ) {
66+
requestedPanel.trigger( 'click' );
67+
}
68+
}
69+
}, 100 );
70+
5671
// Site Health test handling.
5772

5873
$( '.site-health-view-passed' ).on( 'click', function() {

src/wp-admin/site-health-info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
?>
7575
<h3 class="health-check-accordion-heading">
76-
<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" type="button">
76+
<button id="health-check-section-<?php echo esc_attr( $section ); ?>" aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-<?php echo esc_attr( $section ); ?>" type="button">
7777
<span class="title">
7878
<?php echo esc_html( $details['label'] ); ?>
7979
<?php

src/wp-admin/site-health.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301

302302
<script id="tmpl-health-check-issue" type="text/template">
303303
<h4 class="health-check-accordion-heading">
304-
<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" type="button">
304+
<button id="health-check-section-{{ data.test }}" aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" type="button">
305305
<span class="title">{{ data.label }}</span>
306306
<# if ( data.badge ) { #>
307307
<span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>

0 commit comments

Comments
 (0)