PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 2.1.8
bBlocks – Essential Gutenberg Blocks & Patterns Collection v2.1.8
2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 All 108 releases
b-blocks / build / google-map / render.php

render.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 2.1.8, at build/google-map/render.php

49 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 $prefix = 'bBlocksGoogleMap';
4 $id = wp_unique_id( "$prefix-" );
5 $api_keys = get_option( 'bBlocksApiKeys', [] );
6 $planClass = BBlocks\Inc\Utils::isPro() ? 'pro' : 'free';
7 $attributes = BBlocks\Inc\Sanitize::attributes( $attributes );
8 $source = isset( $attributes['source'] ) && is_array( $attributes['source'] ) ? $attributes['source'] : [];
9 $markers = isset( $attributes['markers'] ) && is_array( $attributes['markers'] ) ? $attributes['markers'] : [];
10 $caption = isset( $attributes['caption'] ) && is_array( $attributes['caption'] ) ? $attributes['caption'] : [];
11
12 // Best available human-readable location for the static fallback.
13 $fallback_address = '';
14 if ( ! empty( $source['center']['address'] ) ) {
15 $fallback_address = $source['center']['address'];
16 } elseif ( ! empty( $markers[0]['address'] ) ) {
17 $fallback_address = $markers[0]['address'];
18 } elseif ( ! empty( $markers[0]['title'] ) ) {
19 $fallback_address = $markers[0]['title'];
20 } elseif ( ! empty( $caption['text'] ) ) {
21 $fallback_address = $caption['text'];
22 }
23
24 // Fall back to raw coordinates so the deep link always resolves somewhere.
25 $fallback_query = $fallback_address;
26 if ( '' === $fallback_query && isset( $source['center']['lat'], $source['center']['lng'] ) ) {
27 $fallback_query = $source['center']['lat'] . ',' . $source['center']['lng'];
28 }
29
30 $maps_url = $fallback_query ? 'https://www.google.com/maps/search/?api=1&query=' . rawurlencode( $fallback_query ) : 'https://www.google.com/maps';
31 ?>
32 <div
33 <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_block_wrapper_attributes() is properly escaped ?>
34 <?php echo get_block_wrapper_attributes( [ 'class' => $planClass ] ); ?>
35 id='<?php echo esc_attr( $id ); ?>'
36 data-attributes='<?php echo esc_attr( wp_json_encode( $attributes ) ); ?>'
37 data-mapkey='<?php echo esc_attr( $api_keys['googleMaps']['key'] ?? '' ); ?>'
38 >
39 <div class='b-blocks-google-map-fallback'>
40 <?php if ( $fallback_address ) : ?>
41 <p class='b-blocks-google-map-fallback-address'><?php echo esc_html( $fallback_address ); ?></p>
42 <?php endif; ?>
43
44 <a class='b-blocks-google-map-fallback-link' href='<?php echo esc_url( $maps_url ); ?>' target='_blank' rel='noopener noreferrer'>
45 <?php esc_html_e( 'Open in Google Maps', 'b-blocks' ); ?>
46 </a>
47 </div>
48 </div>
49