Skip to content

Commit

Permalink
Update includes/rules/img_alt_long.php
Browse files Browse the repository at this point in the history
Co-authored-by: William Patton <[email protected]>
  • Loading branch information
SteveJonesDev and pattonwebz authored Mar 27, 2024
1 parent 6d3f898 commit 47efd33
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions includes/rules/img_alt_long.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
*/
function edac_rule_img_alt_long( $content, $post ) { // phpcs:ignore -- $post is reserved for future use or for compliance with a specific interface.

$dom = $content['html'];
$errors = array();
$images = $dom->find( 'img' );
$max_alt_length = absint( apply_filters( 'edac_max_alt_length', 300 ) );
$max_alt_length = max( 1, $max_alt_length );
$dom = $content['html'];
$errors = array();
$images = $dom->find( 'img' );

/**
* Filter the max alt text length checked by the img_alt_long rule before it is considered an issue.
*
* @since 1.11.0
*
* @param int $length The length used in the rule to determine the max length before flagging as an issue.
*/
$max_alt_length = max( 1, absint( apply_filters( 'edac_max_alt_length', 300 ) ) );

foreach ( $images as $image ) {
if ( isset( $image ) && $image->hasAttribute( 'alt' ) && $image->getAttribute( 'alt' ) !== '' ) {
Expand Down

0 comments on commit 47efd33

Please sign in to comment.