'', 'place_lng' => '', 'place_label' => '', 'radius_km' => 20, 'activity_types' => '', 'limit' => 3, 'columns' => 3, 'link_version' => 'default', ); // Appearance controls (style preset + grouped Show toggles + Advanced raw // flags) default to 'auto'/'standard' — see includes/route-card-appearance.php. $defaults['style'] = 'standard'; foreach ( array( 'group_show_photo_or_map', 'group_show_key_stats', 'group_show_badge', 'group_show_description', 'group_show_destinations' ) as $group_key ) { $defaults[ $group_key ] = 'auto'; } if ( function_exists( 'rfcc_route_card_all_raw_flags' ) ) { foreach ( rfcc_route_card_all_raw_flags() as $flag ) { $defaults[ $flag ] = 'auto'; } } $atts = shortcode_atts( $defaults, $atts, 'rfcc_location_preview' ); if ( ! function_exists( 'rfcc_get_routes_within_radius' ) || ! function_exists( 'rfcc_route_card_shortcode_handler' ) ) { return '

' . esc_html__( 'Route Finder location discovery is not available.', 'route-finder' ) . '

'; } $lat = ( $atts['place_lat'] !== '' && is_numeric( $atts['place_lat'] ) ) ? (float) $atts['place_lat'] : null; $lng = ( $atts['place_lng'] !== '' && is_numeric( $atts['place_lng'] ) ) ? (float) $atts['place_lng'] : null; $radius = is_numeric( $atts['radius_km'] ) && (float) $atts['radius_km'] > 0 ? (float) $atts['radius_km'] : 20; $limit = max( 1, absint( $atts['limit'] ) ? absint( $atts['limit'] ) : 3 ); $cols = absint( $atts['columns'] ); if ( $cols < 1 ) { $cols = 1; } elseif ( $cols > 4 ) { $cols = 4; } if ( null === $lat || null === $lng || $lat < -90 || $lat > 90 || $lng < -180 || $lng > 180 ) { return '

' . esc_html__( 'No location configured for this Route Finder preview.', 'route-finder' ) . '

'; } $activity_type_names = array(); if ( ! empty( $atts['activity_types'] ) ) { $activity_type_names = array_filter( array_map( 'trim', explode( ',', $atts['activity_types'] ) ) ); } $matches = rfcc_get_routes_within_radius( $lat, $lng, $radius, $activity_type_names ); $matches = array_slice( $matches, 0, $limit ); // Already closest-first. if ( empty( $matches ) ) { return '

' . esc_html__( 'No routes found near this location.', 'route-finder' ) . '

'; } $appearance_atts = function_exists( 'rfcc_route_card_resolve_appearance_atts' ) ? rfcc_route_card_resolve_appearance_atts( $atts ) : array(); $cards = ''; foreach ( $matches as $match ) { $card_atts = array_merge( array( 'id' => $match['post_id'], 'width' => '100%', 'link_version' => $atts['link_version'], ), $appearance_atts ); $cards .= '
' . rfcc_route_card_shortcode_handler( $card_atts ) . '
'; } rfcc_location_preview_enqueue_style(); return rfcc_kses_map_html( '
' . $cards . '
' ); } /** * Layout CSS for [rfcc_location_preview] / routefinder/location-preview. * * Registered as a src-less handle with the static rules attached via * wp_add_inline_style(), then enqueued when the shortcode renders (so it * prints with the late styles when the shortcode runs inside the page body). */ function rfcc_location_preview_enqueue_style() { $handle = 'rfcc-location-preview-style'; if ( ! wp_style_is( $handle, 'registered' ) ) { wp_register_style( $handle, false, array(), RFCC_PLUGIN_VERSION ); wp_add_inline_style( $handle, '.rfcc-location-preview-grid { display: grid; grid-template-columns: repeat(var(--rfcc-location-preview-columns, 3), minmax(0, 1fr)); gap: 20px; margin: 20px 0; } .rfcc-location-preview-item .rfcc-route-card { margin: 0; height: 100%; } @media (max-width: 782px) { .rfcc-location-preview-grid { grid-template-columns: 1fr; } }' ); } wp_enqueue_style( $handle ); } add_shortcode( 'rfcc_location_preview', 'rfcc_location_preview_shortcode_handler' ); /** * Also load the layout CSS inside the block editor, where the * routefinder/location-preview block's ServerSideRender preview is fetched * over REST (so an enqueue made while rendering it never gets printed). */ function rfcc_location_preview_editor_style() { if ( is_admin() ) { rfcc_location_preview_enqueue_style(); } } add_action( 'enqueue_block_assets', 'rfcc_location_preview_editor_style' );