From 9a48b2f1f096d1f1ef4d9da07834ea58024355cc Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Wed, 8 Apr 2026 12:50:31 +0530 Subject: [PATCH] fix: enable input-requires-label HTMLHint rule for accessibility --- src/js/_enqueues/wp/code-editor.js | 1 + src/wp-includes/general-template.php | 1 + tests/phpunit/tests/dependencies/scripts.php | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/js/_enqueues/wp/code-editor.js b/src/js/_enqueues/wp/code-editor.js index 86d5e03254166..209aab8209b5f 100644 --- a/src/js/_enqueues/wp/code-editor.js +++ b/src/js/_enqueues/wp/code-editor.js @@ -98,6 +98,7 @@ if ( 'undefined' === typeof window.wp.codeEditor ) { * @property {boolean} [src-not-empty] - Src not empty rules. * @property {boolean} [attr-no-duplication] - Attribute no duplication rules. * @property {boolean} [alt-require] - Alt require rules. + * @property {boolean} [input-requires-label] - Input requires label rules. * @property {string} [space-tab-mixed-disabled] - Space tab mixed disabled rules. * @property {boolean} [attr-unsafe-chars] - Attribute unsafe chars rules. * @property {JSHintRules} [jshint] - JSHint rules. diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 47e2aeb2ebb05..ba5641b8373ce 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -4201,6 +4201,7 @@ function wp_get_code_editor_settings( $args ) { 'src-not-empty' => true, 'attr-no-duplication' => true, 'alt-require' => true, + 'input-requires-label' => true, 'space-tab-mixed-disabled' => 'tab', 'attr-unsafe-chars' => true, ), diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 5f1c30fe4cf47..c19e7aabc38df 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -3185,6 +3185,7 @@ public function test_wp_enqueue_code_editor_when_php_file_will_be_passed() { 'src-not-empty', 'attr-no-duplication', 'alt-require', + 'input-requires-label', 'space-tab-mixed-disabled', 'attr-unsafe-chars', ), @@ -3268,6 +3269,7 @@ public function test_wp_enqueue_code_editor_when_generated_array_by_compact_will 'src-not-empty', 'attr-no-duplication', 'alt-require', + 'input-requires-label', 'space-tab-mixed-disabled', 'attr-unsafe-chars', ), @@ -3365,6 +3367,7 @@ public function test_wp_enqueue_code_editor_when_generated_array_by_array_merge_ 'src-not-empty', 'attr-no-duplication', 'alt-require', + 'input-requires-label', 'space-tab-mixed-disabled', 'attr-unsafe-chars', ), @@ -3459,6 +3462,7 @@ public function test_wp_enqueue_code_editor_when_simple_array_will_be_passed() { 'src-not-empty', 'attr-no-duplication', 'alt-require', + 'input-requires-label', 'space-tab-mixed-disabled', 'attr-unsafe-chars', ), @@ -3466,6 +3470,21 @@ public function test_wp_enqueue_code_editor_when_simple_array_will_be_passed() { ); } + /** + * Tests that the `input-requires-label` HTMLHint rule is enabled by default + * in `wp_get_code_editor_settings()` for accessibility linting. + * + * @ticket 42780 + * + * @covers ::wp_get_code_editor_settings + */ + public function test_wp_get_code_editor_settings_input_requires_label_rule_is_enabled() { + $settings = wp_get_code_editor_settings( array( 'type' => 'text/html' ) ); + + $this->assertArrayHasKey( 'input-requires-label', $settings['htmlhint'] ); + $this->assertTrue( $settings['htmlhint']['input-requires-label'] ); + } + /** * @ticket 52534 *