Skip to content

The abandoned osm_map_iframe_template filter

Jörn Lund edited this page Dec 13, 2020 · 1 revision

In versions prior to 1.3.0 there used to be an undocumented filter named osm_map_iframe_template.

This filter is no longer effective in WordPress 5.5 and above.

Assuming that your code looked somehow like this before ...

add_filter('osm_map_iframe_template', function($html) {
    /* 1: iframe src, 2: iframe attributes, 3: osm-url, 4: label */
    return '<iframe src="%1$s" %2$s></iframe><br/><strong><a target="_blank" href="%3$s">%4$s</a></strong>';
}

... your migration should be:

<?php
// file: your-theme/osm-maps/osm.php
/**
 *	Map Template Name: OpenStreetMap iFrame
 */

// extract $field & $value from $args
$map = $args['map'];
$field = $args['field'];

$iframe_atts = [
    'height'       => $field['height'],
    'width'        => '425',
    'frameborder'  => 0,
    'scrolling'    => 'no',
    'marginheight' => 0,
    'marginwidth'  => 0,
];

?>
<iframe src="<?php echo esc_url( acf_osm_get_iframe_url( $map ) ); ?>" <?php echo acf_esc_attr( $iframe_atts ); ?>></iframe><br/>
<strong>
	<a target="_blank" href=<?php echo esc_url( acf_osm_get_link_url( $map ) ); ?>">
		<?php esc_html_e( 'View Larger Map','acf-openstreetmap-field' ); ?>
	</a>
</strong>

Clone this wiki locally