esc_html__( 'Comment and Search Form Labels', 'accessibility-checker' ), 'description' => esc_html__( 'Add missing labels to WordPress comment and search forms.', 'accessibility-checker' ), 'callback' => [ $this, 'comment_search_label_section_callback' ], ]; return $sections; } ); add_filter( 'edac_filter_fixes_settings_fields', [ $this, 'get_fields_array' ], ); } /** * Get the settings fields for the fix. * * @param array $fields The array of fields that are already registered, if any. * * @return array */ public function get_fields_array( array $fields = [] ): array { $fields['edac_fix_comment_label'] = [ 'label' => esc_html__( 'Label Comment Form', 'accessibility-checker' ), 'type' => 'checkbox', 'labelledby' => 'add_comment_label', 'description' => esc_html__( 'Add missing labels to the WordPress comment form.', 'accessibility-checker' ), 'section' => 'comment_search_label', 'fix_slug' => $this->get_slug(), 'group_name' => $this->get_nicename(), 'help_id' => 8658, ]; $fields['edac_fix_search_label'] = [ 'label' => esc_html__( 'Label Search Form', 'accessibility-checker' ), 'type' => 'checkbox', 'labelledby' => 'add_search_label', 'description' => esc_html__( 'Add a missing label to the WordPress search form.', 'accessibility-checker' ), 'section' => 'comment_search_label', 'fix_slug' => $this->get_slug(), 'help_id' => 8659, ]; return $fields; } /** * Run the fix for adding the comment and search form labels. */ public function run(): void { // Add the actual fixes if enabled in settings. if ( get_option( 'edac_fix_comment_label', false ) ) { add_filter( 'comment_form_defaults', [ $this, 'fix_comment_form_labels' ], PHP_INT_MAX ); } if ( get_option( 'edac_fix_search_label', false ) ) { add_filter( 'get_search_form', [ $this, 'fix_search_form_label' ], PHP_INT_MAX ); } } /** * Fixes labels in the comments form. * * @param array $defaults The default comment form arguments. * @return array Modified comment form arguments. */ public function fix_comment_form_labels( $defaults ): array { // Check if the comment label is set correctly; if not, fix it. if ( empty( $defaults['comment_field'] ) || ! strpos( $defaults['comment_field'], '

'; } // Check the author field label. if ( isset( $defaults['fields']['author'] ) && ! strpos( $defaults['fields']['author'], '

'; } // Check the email field label. if ( isset( $defaults['fields']['email'] ) && ! strpos( $defaults['fields']['email'], '

'; } // Check the website field label. if ( isset( $defaults['fields']['url'] ) && ! strpos( $defaults['fields']['url'], '

'; } return $defaults; } /** * Fixes the search form label. * * @param string $form The HTML of the search form. * @return string Modified search form HTML. */ public function fix_search_form_label( $form ): string { // Check if the form already contains a visible