FacetWP – support SearchWP term highlight

<?php

/**
 * Modify the output HTML and highlighting all search terms
 */
add_filter( 'facetwp_render_output', function( $output, $params ) {
    $keywords = '';

    if ( isset( FWP()->facet->facets['keywords'] ) ) {
        $keywords = FWP()->facet->facets['keywords']['selected_values'];
        $keywords = is_array( $keywords ) ? implode( ' ', $keywords ) : $keywords;
    }

    if ( ! empty( $keywords ) && class_exists( 'SearchWPHighlighter' ) ) {
        $highlighter = new SearchWPHighlighter();
        $output['template'] = $highlighter->apply_highlight( $output['template'], $keywords );
    }
    return $output;
}, 10, 2 );