diff --git a/accessibility-checker.php b/accessibility-checker.php index b04de3fa..3a104eaa 100755 --- a/accessibility-checker.php +++ b/accessibility-checker.php @@ -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.16.2 + * Version: 1.16.3 * Author: Equalize Digital * Author URI: https://equalizedigital.com * License: GPL-2.0+ @@ -35,7 +35,7 @@ // Current plugin version. if ( ! defined( 'EDAC_VERSION' ) ) { - define( 'EDAC_VERSION', '1.16.2' ); + define( 'EDAC_VERSION', '1.16.3' ); } // Current database version. diff --git a/admin/site-health/class-free.php b/admin/site-health/class-free.php index 0463c851..bd1865b5 100644 --- a/admin/site-health/class-free.php +++ b/admin/site-health/class-free.php @@ -8,6 +8,8 @@ namespace EDAC\Admin\SiteHealth; +use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager; + /** * Loads free information into Site Health * @@ -28,6 +30,18 @@ public function __construct() { * @return array */ public function get() { + // Get only the non-pro fixes. + $fixes = array_filter( + FixesManager::get_instance()->get_fixes_settings(), + function ( $fix ) { + return ! $fix['is_pro']; + } + ); + // remove the is_pro flag, this isn't needed in the output. + foreach ( $fixes as $key => $fix ) { + unset( $fixes[ $key ]['is_pro'] ); + } + return [ 'label' => __( 'Accessibility Checker — Free', 'accessibility-checker' ), 'fields' => [ @@ -87,6 +101,10 @@ public function get() { 'label' => 'DB Table Count', 'value' => absint( edac_database_table_count( 'accessibility_checker' ) ), ], + 'fixes' => [ + 'label' => 'Fixes', + 'value' => esc_html( wp_json_encode( $fixes ) ), + ], ], ]; } diff --git a/admin/site-health/class-pro.php b/admin/site-health/class-pro.php index 3746ba5f..ac8007f2 100644 --- a/admin/site-health/class-pro.php +++ b/admin/site-health/class-pro.php @@ -8,6 +8,8 @@ namespace EDAC\Admin\SiteHealth; +use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager; + /** * Loads pro information into Site Health * @@ -28,6 +30,19 @@ public function __construct() { * @return array */ public function get() { + + // Get only the pro fixes. + $fixes = array_filter( + FixesManager::get_instance()->get_fixes_settings(), + function ( $fix ) { + return $fix['is_pro']; + } + ); + // remove the is_pro flag, this isn't needed in the output. + foreach ( $fixes as $key => $fix ) { + unset( $fixes[ $key ]['is_pro'] ); + } + return [ 'label' => __( 'Accessibility Checker — Pro', 'accessibility-checker' ), 'fields' => [ @@ -71,6 +86,10 @@ public function get() { 'label' => 'Ignores DB Table Count', 'value' => absint( edac_database_table_count( 'accessibility_checker_global_ignores' ) ), ], + 'fixes' => [ + 'label' => 'Fixes', + 'value' => esc_html( wp_json_encode( $fixes ) ), + ], ], ]; } diff --git a/includes/classes/Fixes/Fix/AddLabelToUnlabelledFormFieldsFix.php b/includes/classes/Fixes/Fix/AddLabelToUnlabelledFormFieldsFix.php index 1578a691..3342ed67 100644 --- a/includes/classes/Fixes/Fix/AddLabelToUnlabelledFormFieldsFix.php +++ b/includes/classes/Fixes/Fix/AddLabelToUnlabelledFormFieldsFix.php @@ -31,7 +31,7 @@ public static function get_slug(): string { * @return string */ public static function get_nicename(): string { - return __( 'Add Size & Type To File Links', 'accessibility-checker' ); + return __( 'Add Labels to Unlabelled Form Fields', 'accessibility-checker' ); } /** diff --git a/includes/classes/Fixes/FixesManager.php b/includes/classes/Fixes/FixesManager.php index 887a0af4..38459a11 100644 --- a/includes/classes/Fixes/FixesManager.php +++ b/includes/classes/Fixes/FixesManager.php @@ -158,6 +158,30 @@ public function get_fix( $slug ) { return isset( $this->fixes[ $slug ] ) ? $this->fixes[ $slug ] : null; } + /** + * Get the fixes settings. + * + * Returns an array of all the fix settings and their values along with a pro or not flag. + * + * @return array + */ + public function get_fixes_settings() { + $fixes_array = []; + foreach ( $this->fixes as $fix ) { + + $fields = []; + foreach ( $fix->get_fields_array() as $field_slug => $field ) { + $fields[ $field_slug ] = get_option( $field_slug, $field['default'] ?? 0 ); + } + + $fixes_array[ $fix::get_slug() ] = [ + 'fields' => $fields, + 'is_pro' => isset( $fix->is_pro ) ? $fix->is_pro : false, + ]; + } + return $fixes_array; + } + /** * Register the fixes. */ diff --git a/package.json b/package.json index bbc421b3..32959e7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accessibility-checker", - "version": "1.16.2", + "version": "1.16.3", "description": "Audit and check your website for accessibility before you hit publish. In-post accessibility scanner and guidance.", "author": "Equalize Digital", "license": "GPL-2.0+", diff --git a/readme.txt b/readme.txt index 55bce39f..0a62be35 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: equalizedigital, alh0319, stevejonesdev Tags: accessibility, accessible, wcag, ada, WP accessibility Requires at least: 6.2 Tested up to: 6.7.0 -Stable tag: 1.16.2 +Stable tag: 1.16.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -171,8 +171,11 @@ No, Accessibility Checker runs completely on your server and does not require yo == Changelog == -= 1.16.2 = += 1.16.3 = +* Enhancement: Add Fix settings to site health info panels. +* Fixed: Corrected a string that was misplaced in a fix. += 1.16.2 = * Enhancement: Use better names for fix modal titles. * Enhancement: Improve the link_pdf rule to detect more accurately. * Enhancement: Improve the link_ms_office_doc rule to detect more accurately. diff --git a/tests/phpunit/includes/classes/Fixes/FixesManagerTest.php b/tests/phpunit/includes/classes/Fixes/FixesManagerTest.php new file mode 100644 index 00000000..d17f7456 --- /dev/null +++ b/tests/phpunit/includes/classes/Fixes/FixesManagerTest.php @@ -0,0 +1,118 @@ +getProperty( 'instance' ); + $instance->setAccessible( true ); + $instance->setValue( null, null ); + } + + /** + * Tear down the test environment by closing Mockery. + * + * @return void + */ + public function tearDown(): void { + Mockery::close(); + } + + /** + * Test that the instance retuns an empty array when no fixes are registered. + * + * @return void + */ + public function test_get_fixes_settings_returns_empty_array_when_no_fixes() { + $fixes_manager = FixesManager::get_instance(); + $this->assertEmpty( $fixes_manager->get_fixes_settings() ); + } + + /** + * Test that the instance returns the correct structure when fixes are registered. + * + * @return void + */ + public function test_get_fixes_settings_returns_correct_structure() { + $fix_mock = Mockery::mock( 'EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddFileSizeAndTypeToLinkedFilesFix' ); + $fix_mock->shouldReceive( 'get_slug' )->andReturn( 'mock_fix' ); + $fix_mock->shouldReceive( 'get_fields_array' )->andReturn( + [ + 'field1' => [ 'default' => 'value1' ], + 'field2' => [ 'default' => 'value2' ], + ] + ); + $fix_mock->is_pro = true; + + $fixes_manager = FixesManager::get_instance(); + $reflection = new ReflectionClass( $fixes_manager ); + $fixes_property = $reflection->getProperty( 'fixes' ); + $fixes_property->setAccessible( true ); + $fixes_property->setValue( $fixes_manager, [ 'mock_fix' => $fix_mock ] ); + + $expected = [ + 'mock_fix' => [ + 'fields' => [ + 'field1' => 'value1', + 'field2' => 'value2', + ], + 'is_pro' => true, + ], + ]; + + $this->assertEquals( $expected, $fixes_manager->get_fixes_settings() ); + } + + /** + * Test that the instance returns the default values when options aren't set. + * + * @return void + */ + public function test_get_fixes_settings_uses_default_values() { + $fix_mock = Mockery::mock( 'EqualizeDigital\AccessibilityChecker\Fixes\Fix\AddFileSizeAndTypeToLinkedFilesFix' ); + $fix_mock->shouldReceive( 'get_slug' )->andReturn( 'mock_fix' ); + $fix_mock->shouldReceive( 'get_fields_array' )->andReturn( + [ + 'field1' => [ 'default' => 'default_value1' ], + 'field2' => [ 'default' => 'default_value2' ], + ] + ); + + $fixes_manager = FixesManager::get_instance(); + $reflection = new ReflectionClass( $fixes_manager ); + $fixes_property = $reflection->getProperty( 'fixes' ); + $fixes_property->setAccessible( true ); + $fixes_property->setValue( $fixes_manager, [ 'mock_fix' => $fix_mock ] ); + + $expected = [ + 'mock_fix' => [ + 'fields' => [ + 'field1' => 'default_value1', + 'field2' => 'default_value2', + ], + 'is_pro' => false, + ], + ]; + + $this->assertEquals( $expected, $fixes_manager->get_fixes_settings() ); + } +}