Created
October 19, 2017 12:25
-
-
Save khromov/36d5c1631346fea4dfe8222927798f9b to your computer and use it in GitHub Desktop.
Infogram oEmbed plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Infogram oEmbed | |
Plugin URI: | |
Description: Adds oEmbed support for infogr.am and infogram.com urls. | |
Author: khromov | |
Version: 1.0 | |
Author URI: https://khromov.se | |
*/ | |
wp_oembed_add_provider('https://infogr.am/*', 'https://infogr.am/oembed_iframe'); | |
wp_oembed_add_provider('https://infogram.com/*', 'https://infogram.com/oembed_iframe'); | |
add_action('wp_footer', function() { | |
?> | |
<script> | |
window.addEventListener('message', function(e) { | |
let data; | |
try { | |
data = JSON.parse(e.data); | |
} catch (e) { | |
return false; | |
} | |
if (data.context !== 'iframe.resize') { | |
return false; | |
} | |
let iframe = document.querySelector('iframe[src="' + data.src + '"]'); | |
if (!iframe) { | |
return false; | |
} | |
iframe.height = data.height; | |
}); | |
</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment