Plugin Directory

Changeset 2956822


Ignore:
Timestamp:
08/22/2023 01:32:00 PM (3 years ago)
Author:
easywpstuff
Message:

update

Location:
accessibility-plus
Files:
8 added
2 edited

Legend:

Unmodified
Added
Removed
  • accessibility-plus/trunk/accessibility.php

    r2951458 r2956822  
    44Plugin URI:
    55Description: Improve pagespeed insight or lighthouse accessibility scores by fixing recommended issues.
    6 Version: 1.2.1
     6Version: 1.2.2
    77Author: easywpstuff
    88Author URI: https://easywpstuff.com
     
    1717include_once('inc/options.php');
    1818
     19function process_html_with_dom($html, $callback) {
     20  $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
     21 
     22  if (empty($dom)) {
     23    return $html;
     24  }
     25 
     26  $callback($dom);
     27
     28  $html = $dom->save();
     29  return $html;
     30}
    1931
    2032// Name: Form elements do not have associated labels
    2133function easywpstuff_assesplus_check_input_labels($html) {
    22   if (empty($html)) {
    23     return $html;
    24   }
    25 
    26   $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    27   if (empty($dom)) {
    28     return $dom;
    29   }
     34  return process_html_with_dom($html, function($dom) {
    3035  $inputs = $dom->find('input');
    3136   
     
    4146    }
    4247  }
    43   return $dom->save();
     48  });
    4449}
    4550
     
    4954  $html = str_replace('</source>', '', $html);
    5055 
    51   $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    52   if (empty($dom)) {
    53     return $dom;
    54   }
     56  return process_html_with_dom($html, function($dom) {
    5557  $links = $dom->find('a');
    5658  $headerLinks = $dom->find('header a');
     
    102104  }
    103105
    104   return $dom->save();
     106  });
    105107}
    106108
     
    110112function easywpstuff_assesplus_add_aria_labels_to_buttons($html) {
    111113
    112   $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    113    if (empty($dom)) {
    114     return $dom;
    115   }
     114  return process_html_with_dom($html, function($dom) {
    116115  $buttons = $dom->find('button');
    117 
    118116  foreach ($buttons as $button) {
    119117    if (!trim($button->plaintext) && !$button->getattribute('aria-label')) {
     
    139137  }
    140138  }
    141   return $dom->save();
     139  });
    142140}
    143141
     
    145143function easywpstuff_assesplus_modify_viewport_meta_tag($html) {
    146144   
    147   $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    148   if (empty($dom)) {
    149     return $dom;
    150   }
     145  return process_html_with_dom($html, function($dom) {
    151146  $viewport_meta_tag = $dom->find('meta[name=viewport]', 0);
    152147  if ($viewport_meta_tag) {
     
    167162    $viewport_meta_tag->setAttribute('content', $content);
    168163  }
    169   return $dom->save();
     164  });
    170165}
    171166
    172167
    173168function easywpstuff_assesplus_add_aria_labels_to_headers($html) {
    174     $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    175     if (empty($dom)) {
    176       return $dom;
    177     }
     169    return process_html_with_dom($html, function($dom) {
    178170
    179171    foreach($dom->find('header div') as $div) {
     
    189181    }
    190182
    191     $html = $dom->save(); // Save the modified HTML
    192     return $html; // Return the modified HTML
     183   });
    193184}
    194185
    195186// <frame> or <iframe> elements do not have a title
    196187function easywpstuff_assesplus_booster_add_to_iframes($html) {
    197     $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    198     if (empty($dom)) {
    199          return $dom;
    200     }
     188    return process_html_with_dom($html, function($dom) {
    201189
    202190    foreach($dom->find('iframe') as $iframe) {
     
    206194    }
    207195
    208     $html = $dom->save();
    209     return $html;
     196    });
    210197}
    211198
    212199//Links are not crawlable
    213200function easywpstuff_assesplus_addHashToBlankLinks($html) {
    214     $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    215     if (empty($dom)) {
    216          return $dom;
    217     }
     201    return process_html_with_dom($html, function($dom) {
    218202    $blankLinks = $dom->find('a');
    219203    foreach ($blankLinks as $link) {
     
    228212        }
    229213    }
    230     $html = $dom->save();
    231     return $html;
     214    });
    232215}
    233216
     
    235218function easywpstuff_assesplus_add_aria_label_to_progressbar($html) {
    236219    // Use Simple HTML DOM to parse the HTML
    237     $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    238     if (empty($dom)) {
    239         return $dom;
    240     }
     220    return process_html_with_dom($html, function($dom) {
    241221    foreach($dom->find('[role=progressbar]') as $element) {
    242222        // Check if the element has aria-label, aria-labelledby or title attribute
     
    249229        }
    250230    }
    251     // Return the modified HTML
    252     $html = $dom->save();
    253     return $html;
     231    });
    254232}
    255233//Image elements do not have [alt] attributes
    256234function easywpstuff_assesplus_addAltToImg($html) {
    257     $dom = lhb_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');
    258     if (empty($dom)) {
    259          return $dom;
    260      }
     235    return process_html_with_dom($html, function($dom) {
    261236    $imgs = $dom->find('img');
    262237    foreach ($imgs as $img) {
     
    276251        }
    277252    }
    278     $html = $dom->save();
    279     return $html;
     253    });
    280254}
    281255
    282256// buffer if option is enabled
    283 function easywpstuff_assesplus_bstr_template_redirect( $buffer ) {
    284 
    285     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_labels'] == 1 ) {
    286         $buffer = easywpstuff_assesplus_check_input_labels( $buffer );
    287     }
    288 
    289     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_discernible_name'] == 1 ) {
    290    
    291         $buffer = easywpstuff_assesplus_add_aria_labels_to_links( $buffer );
    292     }
    293 
    294     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_no_accessible_name'] == 1 ) {
    295    
    296         $buffer = easywpstuff_assesplus_add_aria_labels_to_buttons( $buffer );
    297     }
    298 
    299     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_viewport_meta_tag'] == 1 ) {
    300         $buffer = easywpstuff_assesplus_modify_viewport_meta_tag( $buffer );
    301     }
    302 
    303     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_menuitem_accessible'] == 1 ) {
    304         $buffer = easywpstuff_assesplus_add_aria_labels_to_headers( $buffer );
    305     }
    306 
    307     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_booster_field_iframe_title_tag'] == 1 ) {
    308         $buffer = easywpstuff_assesplus_booster_add_to_iframes( $buffer );
    309     }
    310 
    311     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_add_aria_label_to_progressbar'] == 1 ) {
    312         $buffer = easywpstuff_assesplus_add_aria_label_to_progressbar( $buffer );
    313     }
    314 
    315     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_links_not_crawlable'] == 1 ) {
    316         $buffer = easywpstuff_assesplus_addHashToBlankLinks( $buffer );
    317     }
    318 
    319     if ( get_option( 'easywpstuff_assesplus_booster_options' )['easywpstuff_assesplus_img_donot_alt'] == 1 ) {
    320         $buffer = easywpstuff_assesplus_addAltToImg( $buffer );
    321     }
    322 
    323     return $buffer;
    324 }
    325 //add_action( 'template_redirect', 'easywpstuff_assesplus_bstr_template_redirect', 99 );
    326 
    327 // run the function
     257
     258function easywpstuff_assesplus_bstr_template_redirect($buffer) {
     259    $options = get_option('easywpstuff_assesplus_booster_options');
     260
     261    if ($options['easywpstuff_assesplus_booster_field_no_labels'] == 1) {
     262        $buffer = easywpstuff_assesplus_check_input_labels($buffer);
     263    }
     264
     265    if ($options['easywpstuff_assesplus_booster_field_no_discernible_name'] == 1) {
     266        $buffer = easywpstuff_assesplus_add_aria_labels_to_links($buffer);
     267    }
     268
     269    if ($options['easywpstuff_assesplus_booster_field_no_accessible_name'] == 1) {
     270        $buffer = easywpstuff_assesplus_add_aria_labels_to_buttons($buffer);
     271    }
     272
     273    if ($options['easywpstuff_assesplus_booster_field_viewport_meta_tag'] == 1) {
     274        $buffer = easywpstuff_assesplus_modify_viewport_meta_tag($buffer);
     275    }
     276
     277    if ($options['easywpstuff_assesplus_booster_field_menuitem_accessible'] == 1) {
     278        $buffer = easywpstuff_assesplus_add_aria_labels_to_headers($buffer);
     279    }
     280
     281    if ($options['easywpstuff_assesplus_booster_field_iframe_title_tag'] == 1) {
     282        $buffer = easywpstuff_assesplus_booster_add_to_iframes($buffer);
     283    }
     284
     285    if ($options['easywpstuff_assesplus_add_aria_label_to_progressbar'] == 1) {
     286        $buffer = easywpstuff_assesplus_add_aria_label_to_progressbar($buffer);
     287    }
     288
     289    if ($options['easywpstuff_assesplus_links_not_crawlable'] == 1) {
     290        $buffer = easywpstuff_assesplus_addHashToBlankLinks($buffer);
     291    }
     292
     293    if ($options['easywpstuff_assesplus_img_donot_alt'] == 1) {
     294        $buffer = easywpstuff_assesplus_addAltToImg($buffer);
     295    }
     296
     297    return $buffer;
     298}
     299
    328300add_action( 'template_redirect', 'easywpstuff_assesplus_loader', 99 );
    329301function easywpstuff_assesplus_loader() {
  • accessibility-plus/trunk/readme.txt

    r2951458 r2956822  
    55Tested up to: 6.3
    66Requires PHP: 5.6
    7 Stable tag: 1.2.1
     7Stable tag: 1.2.2
    88License: GNU General Public License v2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5252
    5353== Changelog ==
     54= 1.2.2 =
     55* Improved DOM
    5456= 1.2.1 =
    5557* Minor Fixes
     
    5759* Speedup DOM and Fixed Fatal error
    5860= 1.1.3 =
    59 * Minore Improvement
     61* Minor Improvement
    6062= 1.1.2 =
    6163* Fixed svg conflict
Note: See TracChangeset for help on using the changeset viewer.