Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Rules strict data comparisons #605

Merged
merged 14 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions accessibility-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Accessibility Checker
* Plugin URI: https://a11ychecker.com
* Description: Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.
* Version: 1.11.0
* Version: 1.11.1
* Author: Equalize Digital
* Author URI: https://equalizedigital.com
* License: GPL-2.0+
Expand Down Expand Up @@ -41,7 +41,7 @@

// Current plugin version.
if ( ! defined( 'EDAC_VERSION' ) ) {
define( 'EDAC_VERSION', '1.11.0' );
define( 'EDAC_VERSION', '1.11.1' );
}

// Current database version.
Expand Down
2 changes: 1 addition & 1 deletion admin/class-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function edac_review_notice() {
$edac_review_notice_reminder = get_transient( $transient );

// first time if notice has never been shown wait 14 days.
if ( false === $edac_review_notice_reminder && false === $edac_review_notice ) {
if ( false === $edac_review_notice_reminder && empty( $edac_review_notice ) ) {
// if option isn't set and plugin has been active for more than 14 days show notice. This is for current users.
if ( edac_days_active() > 14 ) {
update_option( $option, 'play' );
Expand Down
16 changes: 8 additions & 8 deletions includes/rules/empty_button.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is
// check buttons.
foreach ( $buttons as $button ) {
if (
str_ireplace( [ ' ', ' ', '-', '_' ], '', trim( $button->plaintext ) ) === ''
&& $button->getAttribute( 'aria-label' ) === ''
&& $button->getAttribute( 'title' ) === ''
empty( str_ireplace( [ ' ', ' ', '-', '_' ], '', trim( $button->plaintext ) ) )
&& empty( $button->getAttribute( 'aria-label' ) )
&& empty( $button->getAttribute( 'title' ) )
) {

$error_code = $button->outertext;
Expand All @@ -39,13 +39,13 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is

if (
'' !== $error_code
&& ( ! isset( $image[0] ) || trim( $image[0]->getAttribute( 'alt' ) ) === '' )
&& ( ! isset( $input[0] ) || trim( $input[0]->getAttribute( 'value' ) ) === '' )
&& ( ! isset( $image[0] ) || empty( trim( $image[0]->getAttribute( 'alt' ) ) ) )
&& ( ! isset( $input[0] ) || empty( trim( $input[0]->getAttribute( 'value' ) ) ) )
&& (
! isset( $i[0] ) ||
(
( trim( $i[0]->getAttribute( 'title' ) ) === '' ) &&
( trim( $i[0]->getAttribute( 'aria-label' ) ) === '' )
( empty( trim( $i[0]->getAttribute( 'title' ) ) ) ) &&
( empty( trim( $i[0]->getAttribute( 'aria-label' ) ) ) )
)
)
) {
Expand All @@ -56,7 +56,7 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is

// check inputs.
foreach ( $inputs as $input ) {
if ( $input->getAttribute( 'value' ) === '' ) {
if ( empty( $input->getAttribute( 'value' ) ) ) {
$errors[] = $input->outertext;
}
}
Expand Down
11 changes: 10 additions & 1 deletion includes/rules/empty_heading_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ function edac_rule_empty_heading_tag( $content, $post ) { // phpcs:ignore -- $po

$heading_code = $heading->outertext;

if ( ( str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', htmlentities( trim( $heading->plaintext ) ) ) === '' || str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', trim( $heading->plaintext ) ) === '' ) && ! preg_match( '#<img(\S|\s)*alt=(\'|\")(\w|\s)(\w|\s|\p{P}|\(|\)|\p{Sm}|~|`|’|\^|\$)+(\'|\")#', $heading_code ) ) {
if ( (
empty( str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', htmlentities( trim( $heading->plaintext ) ) ) ) ||
empty( str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', trim( $heading->plaintext ) ) )
) &&
empty( $heading->getAttribute( 'aria-label' ) ) &&
! preg_match(
'#<img(\S|\s)*alt=(\'|\")(\w|\s)(\w|\s|\p{P}|\(|\)|\p{Sm}|~|`|’|\^|\$)+(\'|\")#',
$heading_code
)
) {

$errors[] = $heading_code;

Expand Down
14 changes: 7 additions & 7 deletions includes/rules/empty_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function edac_rule_empty_link( $content, $post ) { // phpcs:ignore -- $post is r
$error = false;

if (
str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', trim( $link->plaintext ) ) === ''
(string) str_ireplace( [ ' ', '&nbsp;', '-', '_' ], '', trim( $link->plaintext ) ) === ''
&& $link->hasAttribute( 'href' )
&& $link->getAttribute( 'aria-label' ) === ''
&& $link->getAttribute( 'title' ) === ''
&& empty( $link->getAttribute( 'aria-label' ) )
&& empty( $link->getAttribute( 'title' ) )
) {

// This link does not have plaintext within the tag &
Expand All @@ -45,15 +45,15 @@ function edac_rule_empty_link( $content, $post ) { // phpcs:ignore -- $post is r
// does not have a name.

$image = $link->find( 'img' );
if ( ! $error && isset( $input[0] ) && trim( $image[0]->getAttribute( 'alt' ) ) === '' ) {
if ( ! $error && isset( $input[0] ) && empty( trim( $image[0]->getAttribute( 'alt' ) ) ) ) {

// The first image inside the link does not have an alt.
// Throw error.
$error = $a_tag_code;
}

$input = $link->find( 'input' );
if ( ! $error && isset( $input[0] ) && trim( $image[0]->getAttribute( 'value' ) ) === '' ) {
if ( ! $error && isset( $input[0] ) && empty( trim( $image[0]->getAttribute( 'value' ) ) ) ) {

// The first input inside the link does not have a value.
// Throw error.
Expand All @@ -62,8 +62,8 @@ function edac_rule_empty_link( $content, $post ) { // phpcs:ignore -- $post is r

$i = $link->find( 'i' );
if ( ! $error && isset( $input[0] ) &&
trim( $i[0]->getAttribute( 'title' ) ) === '' &&
trim( $i[0]->getAttribute( 'aria-label' ) ) === ''
empty( trim( $i[0]->getAttribute( 'title' ) ) ) &&
empty( trim( $i[0]->getAttribute( 'aria-label' ) ) )
) {

// The first i inside the link does not have a title &
Expand Down
2 changes: 1 addition & 1 deletion includes/rules/iframe_missing_title.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function edac_rule_iframe_missing_title( $content, $post ) { // phpcs:ignore --
$errors = [];

foreach ( $iframe_tags as $iframe ) {
if ( isset( $iframe ) && $iframe->getAttribute( 'title' ) === '' && $iframe->getAttribute( 'aria-label' ) === '' ) {
if ( isset( $iframe ) && empty( $iframe->getAttribute( 'title' ) ) && empty( $iframe->getAttribute( 'aria-label' ) ) ) {

$iframecode = htmlspecialchars( $iframe->outertext );

Expand Down
4 changes: 2 additions & 2 deletions includes/rules/img_alt_empty.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function edac_rule_img_alt_empty( $content, $post ) { // phpcs:ignore -- $post i
isset( $element )
&& 'img' === $element->tag
&& $element->hasAttribute( 'alt' )
&& $element->getAttribute( 'alt' ) === ''
&& (string) $element->getAttribute( 'alt' ) === ''
&& $element->getAttribute( 'role' ) !== 'presentation'
) || (
'input' === $element->tag
&& $element->hasAttribute( 'alt' )
&& $element->getAttribute( 'type' ) === 'image'
&& $element->getAttribute( 'alt' ) === ''
&& (string) $element->getAttribute( 'alt' ) === ''
)
) {

Expand Down
4 changes: 2 additions & 2 deletions includes/rules/img_linked_alt_empty.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function edac_rule_img_linked_alt_empty( $content, $post ) { // phpcs:ignore --
foreach ( $as as $a ) {

// anchors with aria-label or title or valid node text.
if ( $a->getAttribute( 'aria-label' ) === '' && $a->getAttribute( 'title' ) === '' && strlen( $a->plaintext ) <= 5 ) {
if ( empty( $a->getAttribute( 'aria-label' ) ) && empty( $a->getAttribute( 'title' ) ) && strlen( $a->plaintext ) <= 5 ) {

$images = $a->find( 'img' );
foreach ( $images as $image ) {

if ( isset( $image )
&& $image->hasAttribute( 'alt' )
&& $image->getAttribute( 'alt' ) === ''
&& (string) $image->getAttribute( 'alt' ) === ''
&& $image->getAttribute( 'role' ) !== 'presentation' ) {

$image_code = $a;
Expand Down
2 changes: 1 addition & 1 deletion includes/rules/img_linked_alt_missing.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function edac_rule_img_linked_alt_missing( $content, $post ) { // phpcs:ignore -
foreach ( $as as $a ) {

// anchors with aria-label or title or valid node text.
if ( $a->getAttribute( 'aria-label' ) === '' && $a->getAttribute( 'title' ) === '' && strlen( $a->plaintext ) <= 5 ) {
if ( empty( $a->getAttribute( 'aria-label' ) ) && empty( $a->getAttribute( 'title' ) ) && strlen( $a->plaintext ) <= 5 ) {

$images = $a->find( 'img' );
foreach ( $images as $image ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/rules/long_description_invalid.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function edac_rule_long_description_invalid( $content, $post ) { // phpcs:ignore
$file_parts = pathinfo( $longdesc );
$valid_url = filter_var( $longdesc, FILTER_VALIDATE_URL );

if ( $image->getAttribute( 'longdesc' ) === ''
if ( (string) $image->getAttribute( 'longdesc' ) === ''
|| ! $valid_url
|| ! $file_parts['extension']
|| ! $file_parts['filename']
Expand Down
2 changes: 1 addition & 1 deletion includes/rules/missing_title.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function edac_rule_missing_title( $content, $post ) {
return [ "Missing Title - Post ID: $post->ID" ];
}
if ( ( ! isset( $title ) || '' === $title->innertext || '-' === $title->innertext )
&& ( ! isset( $meta_title ) || ( $meta_title->hasAttribute( 'content' ) && ( $meta_title->getAttribute( 'content' ) === '' || strlen( $meta_title->getAttribute( 'content' ) ) <= 1 ) ) )
&& ( ! isset( $meta_title ) || ( $meta_title->hasAttribute( 'content' ) && ( (string) $meta_title->getAttribute( 'content' ) === '' || strlen( $meta_title->getAttribute( 'content' ) ) <= 1 ) ) )
) {
return [ "Missing title tag or meta title tag - Post ID: $post->ID" ];
}
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev
Tags: accessibility, accessible, wcag, ada, WP accessibility
Requires at least: 6.2
Tested up to: 6.5.2
Stable tag: 1.11.0
Stable tag: 1.11.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -171,6 +171,11 @@ No, Accessibility Checker runs completely on your server and does not require yo

== Changelog ==

+ 1.11.1 =
* Fixed: type Casting on several rules
* Fixed: strict data comparison on several rules
* Updated: empty heading tag rule to consider aria-label

= 1.11.0 =
* Updated: Tested up to WP 6.5.2
* Improved: Better detection of the underlined text rule for more accurate results
Expand Down
Loading