diff --git a/src/js/_enqueues/wp/code-editor.js b/src/js/_enqueues/wp/code-editor.js index 18451a0a7881e..6833bc2b22020 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 4c6945a62648d..e7470fa5859cf 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -4505,6 +4505,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 75e919355c76c..820dbccdf1d57 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -3092,6 +3092,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', ), @@ -3176,6 +3177,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', ), @@ -3274,6 +3276,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', ), @@ -3369,6 +3372,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', ), @@ -3376,6 +3380,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 *