Skip to content

Commit

Permalink
FacetWP Service : remove load_assets filter // Simplify labels
Browse files Browse the repository at this point in the history
  • Loading branch information
MarieComet committed Jul 5, 2024
1 parent 8ac1dc1 commit 6c4caf3
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion inc/Services/Facet_WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public function register( Service_Container $container ): void {
}

public function boot( Service_Container $container ): void {
add_filter( 'facetwp_load_assets', '__return_true' );
add_filter( 'facetwp_load_a11y', '__return_true' );
add_filter( 'facetwp_facets', [ $this, 'register_facets' ], 40 );
add_filter( 'facetwp_pager_html', [ $this, 'accessible_facetwp_pager_html' ], 10, 2 );
add_filter( 'facetwp_facet_pager_link', [ $this, 'facetwp_facet_pager_link' ], 10, 2 );
add_filter( 'facetwp_facet_html', [ $this, 'facetwp_add_labels' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -180,4 +180,32 @@ public function facetwp_facet_pager_link( $html, $params ): string {

return $html;
}

/**
* Add fake labels to all facets
* Put in $add_label_if_not_empty the facets types for which you want to display the label *only* if the facet is not empty.
*
* @param string $html
* @param array $args
*
* @return string
*/
public function facetwp_add_labels( string $html, array $args ): string {
$add_label_if_not_empty = [
'checkboxes',
'pager',
'reset',
];

if ( ( true === in_array( $args['facet']['type'], $add_label_if_not_empty, true ) && ! empty( $args['values'] ) ) || false === in_array( $args['facet']['type'], $add_label_if_not_empty, true ) ) {
$label = $args['facet']['label'];
if ( function_exists( 'facetwp_i18n' ) ) {
$label = facetwp_i18n( $label );
}

$html = sprintf( '<p aria-hidden="true" class="facetwp-label">%s</p>%s', esc_html( $label ), $html );
}

return $html;
}
}

0 comments on commit 6c4caf3

Please sign in to comment.