Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions admin/class-enqueue-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,19 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() {
'edac-editor-app',
'edac_editor_app',
[
'postID' => $post_id,
'edacUrl' => esc_url_raw( get_site_url() ),
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
'baseurl' => plugin_dir_url( __DIR__ ),
'active' => $active,
'pro' => $pro,
'debug' => $debug,
'scanUrl' => $scan_url,
'maxAltLength' => max( 1, absint( apply_filters( 'edac_max_alt_length', 300 ) ) ),
'version' => EDAC_VERSION,
'postStatus' => get_post_status( $post_id ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'postID' => $post_id,
'edacUrl' => esc_url_raw( get_site_url() ),
'edacApiUrl' => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
'baseurl' => plugin_dir_url( __DIR__ ),
'active' => $active,
'pro' => $pro,
'debug' => $debug,
'scanUrl' => $scan_url,
'maxAltLength' => max( 1, absint( apply_filters( 'edac_max_alt_length', 300 ) ) ),
'ruleExclusions' => self::get_rule_exclusions(),
'version' => EDAC_VERSION,
'postStatus' => get_post_status( $post_id ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
]
);

Expand Down Expand Up @@ -448,4 +449,19 @@ private static function get_sr_only_editor_styles(): string {
private static function get_current_page_slug(): ?string {
return isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only.
}

/**
* Build a map of rule slug => exclusion selectors for rules that declare exclusions.
*
* @return array<string, string[]>
*/
private static function get_rule_exclusions(): array {
$exclusions = [];
foreach ( edac_register_rules() as $rule ) {
if ( ! empty( $rule['exclusions'] ) ) {
$exclusions[ $rule['slug'] ] = $rule['exclusions'];
}
}
return $exclusions;
}
Comment thread
SteveJonesDev marked this conversation as resolved.
Outdated
}
5 changes: 5 additions & 0 deletions includes/classes/Rules/Rule/AriaHiddenRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static function get_rule(): array {
'combines' => [
'aria_hidden_validation',
],
'exclusions' => [
'.wp-block-spacer',
'.wp-block-cover__background.has-background-dim',
'.wp-block-post-featured-image__overlay.has-background-dim',
],
];
}
}
5 changes: 2 additions & 3 deletions src/editorApp/checkPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ const injectIframe = ( previewUrl, postID ) => {
body.setAttribute( 'data-iframe-post-id', postID );

if ( iframeDocument ) {
if ( window?.edac_editor_app?.maxAltLength ) {
// if the frame doesn't have window.scanOptions then create is as an object.
if ( window?.edac_editor_app?.maxAltLength || window?.edac_editor_app?.ruleExclusions ) {
if ( ! iframeDocument.defaultView.scanOptions ) {
iframeDocument.defaultView.scanOptions = {};
}

// set the maxAlthLength for the scanOptions.
iframeDocument.defaultView.scanOptions = {
maxAltLength: window.edac_editor_app.maxAltLength,
ruleExclusions: window.edac_editor_app.ruleExclusions,
};
Comment thread
SteveJonesDev marked this conversation as resolved.
}

Expand Down
11 changes: 7 additions & 4 deletions src/pageScanner/checks/aria-hidden-valid-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ const srClasses = [

export default {
id: 'aria_hidden_valid_usage',
evaluate: ( node ) => {
evaluate: ( node, options = {} ) => {
// Check if element is hidden with CSS
const computedStyle = window.getComputedStyle( node );
if ( computedStyle.display === 'none' || computedStyle.visibility === 'hidden' ) {
return true;
}

// Check for valid element properties
if ( node.classList.contains( 'wp-block-spacer' ) ) {
return true;
// Check against configured exclusion selectors.
const exclusions = options?.exclusions || [];
for ( const selector of exclusions ) {
if ( node.matches( selector ) ) {
return true;
}
}
Comment thread
SteveJonesDev marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const role = node.getAttribute( 'role' );
Expand Down
7 changes: 6 additions & 1 deletion src/pageScanner/config/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ export const checksArray = [
hasAmbiguousText,
anchorExists,
imageInputHasAlt,
ariaHiddenValidUsage,
{
...ariaHiddenValidUsage,
options: {
exclusions: window?.scanOptions?.ruleExclusions?.aria_hidden || [],
Comment thread
SteveJonesDev marked this conversation as resolved.
},
},
tableHasHeaders,
headingIsEmpty,
transcriptMissing,
Expand Down
Loading