summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/contact-info.php')
-rw-r--r--plugins/jetpack/modules/widgets/contact-info.php37
1 files changed, 29 insertions, 8 deletions
diff --git a/plugins/jetpack/modules/widgets/contact-info.php b/plugins/jetpack/modules/widgets/contact-info.php
index 292f96d7..7a0a373e 100644
--- a/plugins/jetpack/modules/widgets/contact-info.php
+++ b/plugins/jetpack/modules/widgets/contact-info.php
@@ -321,19 +321,42 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) {
/**
* Builds map display HTML code from the supplied latitude and longitude.
*
- * @param float $lat Map Latitude
- * @param float $lon Map Longitude
+ * @param string $address Address.
+ * @param string $api_key API Key.
*
- * @return string HTML of the map
+ * @return string HTML of the map.
*/
function build_map( $address, $api_key = null ) {
$this->enqueue_scripts();
- $src = add_query_arg( 'q', urlencode( $address ), 'https://www.google.com/maps/embed/v1/place' );
+ $src = add_query_arg( 'q', rawurlencode( $address ), 'https://www.google.com/maps/embed/v1/place' );
if ( ! empty( $api_key ) ) {
$src = add_query_arg( 'key', $api_key, $src );
}
- return '<iframe width="600" height="216" frameborder="0" src="' . esc_url( $src ) . '" class="contact-map"></iframe>';
+ $height = 216;
+
+ $iframe_attributes = sprintf(
+ ' height="%d" frameborder="0" src="%s" class="contact-map"',
+ esc_attr( $height ),
+ esc_url( $src )
+ );
+
+ $iframe_html = sprintf( '<iframe width="600" %s></iframe>', $iframe_attributes );
+
+ if ( ! Jetpack_AMP_Support::is_amp_request() ) {
+ return $iframe_html;
+ }
+
+ $amp_iframe_html = sprintf( '<amp-iframe layout="fixed-height" width="auto" sandbox="allow-scripts allow-same-origin" %s>', $iframe_attributes );
+
+ // Add placeholder to avoid AMP error: <amp-iframe> elements must be positioned outside the first 75% of the viewport or 600px from the top (whichever is smaller).
+ $amp_iframe_html .= sprintf( '<span placeholder>%s</span>', esc_html__( 'Loading map&hellip;', 'jetpack' ) );
+
+ // Add original iframe as fallback in case JavaScript is disabled.
+ $amp_iframe_html .= sprintf( '<noscript>%s</noscript>', $iframe_html );
+
+ $amp_iframe_html .= '</amp-iframe>';
+ return $amp_iframe_html;
}
/**
@@ -348,9 +371,7 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) {
$address = strtolower( $address );
$address = preg_replace( '/\s+/', ' ', trim( $address ) ); // Get rid of any unwanted whitespace
$address = str_ireplace( ' ', '+', $address ); // Use + not %20
- urlencode( $address );
-
- return $address;
+ return urlencode( $address );
}
/**