| 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.3 |
| 7 |
Author: webvitaly |
| 8 |
Author URI: http://web-profile.net/wordpress/plugins/ |
| 9 |
License: GPLv3 |
| 10 |
*/ |
| 11 |
|
| 12 |
define('IFRAME_PLUGIN_VERSION', '4.3'); |
| 13 |
|
| 14 |
function iframe_plugin_add_shortcode_cb( $atts ) { |
| 15 |
$defaults = array( |
| 16 |
'src' => 'http://www.youtube.com/embed/4qsGTXLnmKs', |
| 17 |
'width' => '100%', |
| 18 |
'height' => '500', |
| 19 |
'scrolling' => 'yes', |
| 20 |
'class' => 'iframe-class', |
| 21 |
'frameborder' => '0' |
| 22 |
); |
| 23 |
|
| 24 |
foreach ( $defaults as $default => $value ) { // add defaults |
| 25 |
if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all |
| 26 |
$atts[$default] = $value; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
$html = "\n".'<!-- iframe plugin v.'.IFRAME_PLUGIN_VERSION.' wordpress.org/plugins/iframe/ -->'."\n"; |
| 31 |
$html .= '<iframe'; |
| 32 |
foreach( $atts as $attr => $value ) { |
| 33 |
if ( strtolower($attr) != 'same_height_as' AND strtolower($attr) != 'onload' |
| 34 |
AND strtolower($attr) != 'onpageshow' AND strtolower($attr) != 'onclick') { // remove some attributes |
| 35 |
if ( $value != '' ) { // adding all attributes |
| 36 |
$html .= ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; |
| 37 |
} else { // adding empty attributes |
| 38 |
$html .= ' ' . esc_attr( $attr ); |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
$html .= '></iframe>'."\n"; |
| 43 |
|
| 44 |
if ( isset( $atts["same_height_as"] ) ) { |
| 45 |
$html .= ' |
| 46 |
<script> |
| 47 |
document.addEventListener("DOMContentLoaded", function(){ |
| 48 |
var target_element, iframe_element; |
| 49 |
iframe_element = document.querySelector("iframe.' . esc_attr( $atts["class"] ) . '"); |
| 50 |
target_element = document.querySelector("' . esc_attr( $atts["same_height_as"] ) . '"); |
| 51 |
iframe_element.style.height = target_element.offsetHeight + "px"; |
| 52 |
}); |
| 53 |
</script> |
| 54 |
'; |
| 55 |
} |
| 56 |
|
| 57 |
return $html; |
| 58 |
} |
| 59 |
add_shortcode( 'iframe', 'iframe_plugin_add_shortcode_cb' ); |
| 60 |
|
| 61 |
|
| 62 |
function iframe_plugin_row_meta_cb( $links, $file ) { |
| 63 |
if ( $file == plugin_basename( __FILE__ ) ) { |
| 64 |
$row_meta = array( |
| 65 |
'support' => '<a href="http://web-profile.net/wordpress/plugins/iframe/" target="_blank"><span class="dashicons dashicons-editor-help"></span> ' . __( 'Iframe', 'iframe' ) . '</a>', |
| 66 |
'donate' => '<a href="http://web-profile.net/donate/" target="_blank"><span class="dashicons dashicons-heart"></span> ' . __( 'Donate', 'iframe' ) . '</a>', |
| 67 |
'iframe_pro' => '<a href="http://codecanyon.net/item/advanced-iframe-pro/5344999?ref=webvitalii" target="_blank"><span class="dashicons dashicons-star-filled"></span> ' . __( 'Advanced iFrame Pro', 'iframe' ) . '</a>', |
| 68 |
'pro' => '<a href="http://codecanyon.net/item/silver-bullet-pro/15171769?ref=webvitalii" target="_blank" title="Speedup and protect WordPress in a smart way"><span class="dashicons dashicons-star-filled"></span> ' . __( 'Silver Bullet Pro', 'iframe' ) . '</a>' |
| 69 |
); |
| 70 |
$links = array_merge( $links, $row_meta ); |
| 71 |
} |
| 72 |
return (array) $links; |
| 73 |
} |
| 74 |
add_filter( 'plugin_row_meta', 'iframe_plugin_row_meta_cb', 10, 2 ); |
| 75 |
|