| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: iframe |
| 4 |
Plugin URI: http://wordpress.org/plugins/iframe/ |
| 5 |
Description: [iframe src="http://www.youtube.com/embed/4qsGTXLnmKs" width="100%" height="500"] shortcode |
| 6 |
Version: 4.0 |
| 7 |
Author: webvitaly |
| 8 |
Author URI: http://web-profile.com.ua/wordpress/plugins/ |
| 9 |
License: GPLv3 |
| 10 |
*/ |
| 11 |
|
| 12 |
|
| 13 |
function iframe_unqprfx_embed_shortcode( $atts ) { |
| 14 |
$defaults = array( |
| 15 |
'src' => 'http://www.youtube.com/embed/4qsGTXLnmKs', |
| 16 |
'width' => '100%', |
| 17 |
'height' => '500', |
| 18 |
'scrolling' => 'yes', |
| 19 |
'class' => 'iframe-class', |
| 20 |
'frameborder' => '0' |
| 21 |
); |
| 22 |
|
| 23 |
foreach ( $defaults as $default => $value ) { // add defaults |
| 24 |
if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all |
| 25 |
$atts[$default] = $value; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
$html = "\n".'<!-- iframe plugin v.4.0 wordpress.org/plugins/iframe/ -->'."\n"; |
| 30 |
$html .= '<iframe'; |
| 31 |
foreach( $atts as $attr => $value ) { |
| 32 |
if ( strtolower($attr) != 'same_height_as' AND strtolower($attr) != 'onload' ) { // remove some attributes |
| 33 |
if ( $value != '' ) { // adding all attributes |
| 34 |
$html .= ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; |
| 35 |
} else { // adding empty attributes |
| 36 |
$html .= ' ' . esc_attr( $attr ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
$html .= '></iframe>'."\n"; |
| 41 |
|
| 42 |
if ( isset( $atts["same_height_as"] ) ) { |
| 43 |
$html .= ' |
| 44 |
<script> |
| 45 |
document.addEventListener("DOMContentLoaded", function(){ |
| 46 |
var target_element, iframe_element; |
| 47 |
iframe_element = document.querySelector("iframe.' . esc_attr( $atts["class"] ) . '"); |
| 48 |
target_element = document.querySelector("' . esc_attr( $atts["same_height_as"] ) . '"); |
| 49 |
iframe_element.style.height = target_element.offsetHeight + "px"; |
| 50 |
}); |
| 51 |
</script> |
| 52 |
'; |
| 53 |
} |
| 54 |
|
| 55 |
return $html; |
| 56 |
} |
| 57 |
add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' ); |
| 58 |
|
| 59 |
|
| 60 |
function iframe_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row |
| 61 |
if ( strpos( $file, 'iframe.php' ) !== false ) { |
| 62 |
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" title="Plugin page">Iframe</a>' ) ); |
| 63 |
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">Donate</a>' ) ); |
| 64 |
$links = array_merge( $links, array( '<a href="http://codecanyon.net/item/advanced-iframe-pro/5344999?ref=webvitaly">Advanced iFrame Pro</a>' ) ); |
| 65 |
} |
| 66 |
return $links; |
| 67 |
} |
| 68 |
add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 ); |
| 69 |
|