-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathiframe.php
92 lines (79 loc) · 2.78 KB
/
iframe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
Plugin Name: iframe
Plugin URI: http://wordpress.org/plugins/iframe/
Description: [iframe src="http://www.youtube.com/embed/dUpTjDqjQoo" width="100%" height="500"] shortcode
Version: 5.1
Author: webvitaly
Author URI: http://web-profile.net/wordpress/plugins/
License: GPLv3
*/
if ( ! defined( 'ABSPATH' ) ) { // Avoid direct calls to this file and prevent full path disclosure
exit;
}
define('IFRAME_PLUGIN_VERSION', '5.1');
function iframe_plugin_add_shortcode_cb( $atts ) {
$defaults = array(
//'src' => 'http://www.youtube.com/embed/dUpTjDqjQoo',
'width' => '100%',
'height' => '500',
'scrolling' => 'yes',
'class' => 'iframe-class',
'frameborder' => '0'
);
if ( ! is_array( $atts ) ) {
$atts = array();
}
foreach ( $defaults as $default => $value ) { // add defaults
if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all
$atts[$default] = $value;
}
}
$html = "\n".'<!-- iframe plugin v.'.IFRAME_PLUGIN_VERSION.' wordpress.org/plugins/iframe/ -->'."\n";
$html .= '<iframe';
foreach( $atts as $attr => $value ) {
if ( strtolower($attr) == 'src' ) { // sanitize url
$value = esc_url( $value );
}
// Remove 'srcdoc' attribute
if ( strtolower($attr) == 'srcdoc' ) {
continue;
}
// Skip attributes starting with "on". Examples: onload, onmouseover, onfocus, onpageshow, onclick
if ( strpos( strtolower( $attr ), 'on' ) === 0 ) {
continue;
}
if ($value !== '') { // adding all attributes
$html .= ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"';
} else { // adding empty attributes
$html .= ' ' . esc_attr($attr);
}
}
$html .= '></iframe>'."\n";
if ( isset( $atts["same_height_as"] ) ) {
$html .= '
<script>
document.addEventListener("DOMContentLoaded", function(){
var target_element, iframe_element;
iframe_element = document.querySelector("iframe.' . esc_attr( $atts["class"] ) . '");
target_element = document.querySelector("' . esc_attr( $atts["same_height_as"] ) . '");
iframe_element.style.height = target_element.offsetHeight + "px";
});
</script>
';
}
return $html;
}
add_shortcode( 'iframe', 'iframe_plugin_add_shortcode_cb' );
function iframe_plugin_row_meta_cb( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
$row_meta = array(
'support' => '<a href="http://web-profile.net/wordpress/plugins/iframe/" target="_blank">' . __( 'Iframe', 'iframe' ) . '</a>',
'donate' => '<a href="http://web-profile.net/donate/" target="_blank">' . __( 'Donate', 'iframe' ) . '</a>',
'pro' => '<a href="https://1.envato.market/Ym5aq" target="_blank">' . __( 'Advanced iFrame Pro', 'iframe' ) . '</a>'
);
$links = array_merge( $links, $row_meta );
}
return (array) $links;
}
add_filter( 'plugin_row_meta', 'iframe_plugin_row_meta_cb', 10, 2 );