stop CloudFlare Rockscript messing up WP Flexible Map plugin!
<?php | |
/* | |
Plugin Name: Flxmap No Rocketscript | |
Plugin URI: https://gist.github.com/webaware/8949605 | |
Description: stop CloudFlare Rockscript messing up the map plugin! | |
Version: 3 | |
Author: WebAware | |
Author URI: http://webaware.com.au/ | |
@ref: http://wordpress.org/support/topic/map-wont-appear | |
@ref: http://stackoverflow.com/a/10611827/911083 | |
@ref: https://support.cloudflare.com/hc/en-us/articles/200169436 | |
*/ | |
/** | |
* output a script tag that won't be replaced by Rocketscript | |
* @param string $handle | |
*/ | |
function flxmap_no_rocketscript($handle) { | |
global $wp_scripts; | |
$script = $wp_scripts->query($handle); | |
$src = $script->src; | |
if ( !empty($script->ver) ) { | |
$src = add_query_arg('ver', $script->ver, $src); | |
} | |
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); | |
echo "<script data-cfasync='false' type='text/javascript' src='$src'></script>\n"; | |
} | |
/** | |
* intercept call to print footer scripts, | |
* replace Google Maps API and Flexible Map script | |
*/ | |
add_action('wp_print_footer_scripts', function() { | |
if (wp_script_is('flxmap')) { | |
wp_dequeue_script('flxmap'); | |
wp_dequeue_script('google-maps'); | |
flxmap_no_rocketscript('google-maps'); | |
flxmap_no_rocketscript('flxmap'); | |
} | |
}, 1); | |
/** | |
* add data-cfasync attribute to Flexible Map script tag | |
* @param string $html | |
* @return string | |
*/ | |
add_filter('flexmap_shortcode_html', function($html) { | |
$html = str_replace('<script', '<script data-cfasync="false"', $html); | |
return $html; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment