Skip to content

Commit 6cb574b

Browse files
committed
Site Health: Allow direct linking to site health check result.
This changeset does the following changes: - Add an ID to each accordion button - Update the URL hash each time an accordion button is clicked - On page load, open the related accordion when provided This way, people can use the URL of the page to share a direct link to the site health info section they want. Props sippis, kabir93, audrasjb, saratheonline, pratiklondhe, vgnavada, SirLouen, nikunj8866, pmbaldha, sajjad67, huzaifaalmesbah, westonruter. Fixes #62846. git-svn-id: https://develop.svn.wordpress.org/trunk@61614 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a777756 commit 6cb574b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

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

47+
if ( $( this ).prop( 'id' ) ) {
48+
window.location.hash = $( this ).prop( 'id' );
49+
}
50+
4751
if ( isExpanded ) {
4852
$( this ).attr( 'aria-expanded', 'false' );
4953
$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
@@ -53,6 +57,20 @@ jQuery( function( $ ) {
5357
}
5458
} );
5559

60+
/* global setTimeout */
61+
wp.domReady( function() {
62+
// Get hash from query string and open the related accordion.
63+
var hash = window.location.hash;
64+
65+
if ( hash ) {
66+
var requestedPanel = $( hash );
67+
68+
if ( requestedPanel.is( '.health-check-accordion-trigger' ) ) {
69+
requestedPanel.trigger( 'click' );
70+
}
71+
}
72+
} );
73+
5674
// Site Health test handling.
5775

5876
$( '.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

0 commit comments

Comments
 (0)