diff --git a/includes/classes/Feature/Facets/Widget.php b/includes/classes/Feature/Facets/Widget.php index 886ac064d..b8a675b8a 100644 --- a/includes/classes/Feature/Facets/Widget.php +++ b/includes/classes/Feature/Facets/Widget.php @@ -340,9 +340,36 @@ protected function get_facet_term_html( $term, $url, $selected = false ) { */ $label = apply_filters( 'ep_facet_widget_term_label', $term->name, $term, $selected ); + /** + * Filter the accessible label for an individual facet term link. + * + * Used as the aria-label attribute for filter links. The accessible + * label should include additional context around what action will be + * performed by visiting the link, such as whether the filter will be + * added or removed. + * + * @since 4.0.0 + * @hook ep_facet_widget_term_accessible_label + * @param {string} $label Facet term accessible label. + * @param {WP_Term} $term Term object. + * @param {boolean} $selected Whether the term is selected. + * @return {string} Individual facet term accessible label. + */ + $accessible_label = apply_filters( + 'ep_facet_widget_term_accessible_label', + $selected + /* translators: %s: Filter term name. */ + ? sprintf( __( 'Remove filter: %s', 'elasticpress' ), $term->name ) + /* translators: %s: Filter term name. */ + : sprintf( __( 'Apply filter: %s', 'elasticpress' ), $term->name ), + $term, + $selected + ); + $link = sprintf( - '%3$s', - $term->count ? $href : '', + '%4$s', + esc_attr( $accessible_label ), + $term->count ? $href : 'aria-role="link" aria-disabled="true"', $selected ? 'checked' : '', wp_kses_post( $label ) );