Remove “_” custom fields from data source list in facet settings and listing builder items

<?php
/**
 * See: https://facetwp.com/help-center/developers/hooks/advanced-hooks/facetwp_facet_sources/#remove-custom-fields
 * Removes all data sources that are custom fields with "_" named meta_key from data sources in FacetWP settings
 * Keys in sources include "custom_fields", "posts, "taxonomies"
 * Integrations add their own sources: e.g. "upt/", "woocommerce/", "acf"
 * Context is 'default' for facet settings, context would be 'builder' for Listing Builder items
 **/
add_filter( 'facetwp_facet_sources', function( $sources, $context ) {
    foreach ( $sources AS $key => $value ) {
        if ( "custom_fields" == $key && 'default' == $context ) {
            $choices = array_values( array_filter( $value['choices'], function( $value, $key ) {
                if ( str_starts_with( $key, "cf/_" ) ) {
                    return false;
                }
                return true;
            }, ARRAY_FILTER_USE_BOTH ) );
            $sources[$key]['choices'] = $choices;
        }
    }
    return $sources;
}, 10, 2 );