iframe - Version 3.0

Version Description

  • 2015-01-25 =
  • removed same_height_as="content", same_height_as="window", same_height_as="document" features because it was not working properly
  • rewrote the javascript-code using pure JavaScript and without jQuery - no need to load jQuery for every site using iframe plugin
  • removed function_exists check because each function has unique prefix
  • code refactored
  • update docs
  • set height="500" instead of 480 by default
  • set scrolling="yes" instead of "no" by default
Download this release

Release Info

Developer webvitaly
Plugin Icon wp plugin iframe
Version 3.0
Comparing to
See all releases

Code changes from version 2.9 to 3.0

Files changed (2) hide show
  1. iframe.php +63 -95
  2. readme.txt +29 -19
iframe.php CHANGED
@@ -2,116 +2,84 @@
2
  /*
3
  Plugin Name: iframe
4
  Plugin URI: http://wordpress.org/plugins/iframe/
5
- Description: [iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"] shortcode
6
- Version: 2.9
7
  Author: webvitaly
8
  Author URI: http://web-profile.com.ua/wordpress/plugins/
9
  License: GPLv3
10
  */
11
 
12
 
13
- if ( ! function_exists( 'iframe_unqprfx_embed_shortcode' ) ) :
 
 
 
 
 
 
 
 
14
 
15
- function iframe_unqprfx_enqueue_script() {
16
- wp_enqueue_script( 'jquery' );
 
 
17
  }
18
- add_action( 'wp_enqueue_scripts', 'iframe_unqprfx_enqueue_script' );
19
-
20
-
21
- function iframe_unqprfx_embed_shortcode( $atts, $content = null ) {
22
- $defaults = array(
23
- 'src' => 'http://www.youtube.com/embed/A3PDXmYoF5U',
24
- 'width' => '100%',
25
- 'height' => '480',
26
- 'scrolling' => 'no',
27
- 'class' => 'iframe-class',
28
- 'frameborder' => '0'
29
- );
30
 
31
- foreach ( $defaults as $default => $value ) { // add defaults
32
- if ( ! @array_key_exists( $default, $atts ) ) { // hide warning with "@" when no params at all
33
- $atts[$default] = $value;
 
 
 
 
 
34
  }
35
- }
36
-
37
- // get_params_from_url
38
- if ( isset( $atts["get_params_from_url"] ) && ( $atts["get_params_from_url"] == '1' || $atts["get_params_from_url"] == 1 ) ) {
39
- $encode_string = '';
40
- if ( $_GET != NULL ) {
41
- if ( strpos( $atts["src"], '?' ) ) { // if we already have '?' and GET params
42
- $encode_string = '&';
43
- } else {
44
- $encode_string = '?';
45
- }
46
- foreach( $_GET as $key => $value ) {
47
- $encode_string .= $key.'='.$value.'&';
48
- }
49
  }
50
- $encode_string = rtrim($encode_string, '&'); // remove last '&'
51
- $atts["src"] .= $encode_string;
52
  }
 
 
 
53
 
54
- $html = '';
55
- if ( isset( $atts["same_height_as"] ) ) {
56
- $same_height_as = $atts["same_height_as"];
57
- } else {
58
- $same_height_as = '';
59
- }
60
-
61
- if ( $same_height_as != '' ) {
62
- $atts["same_height_as"] = '';
63
- if ( $same_height_as != 'content' ) { // we are setting the height of the iframe like as target element
64
- if ( $same_height_as == 'document' || $same_height_as == 'window' ) { // remove quotes for window or document selectors
65
- $target_selector = $same_height_as;
66
- } else {
67
- $target_selector = '"' . $same_height_as . '"';
68
- }
69
- $html .= '
70
- <script>
71
- jQuery(function($){
72
- var target_height = $(' . $target_selector . ').height();
73
- $("iframe.' . $atts["class"] . '").height(target_height);
74
- });
75
- </script>
76
- ';
77
- } else { // set the actual height of the iframe (show all content of the iframe without scroll)
78
- $html .= '
79
- <script>
80
- jQuery(function($){
81
- $("iframe.' . $atts["class"] . '").bind("load", function() {
82
- var embed_height = $(this).contents().find("body").height();
83
- $(this).height(embed_height);
84
- });
85
- });
86
- </script>
87
- ';
88
- }
89
- }
90
- $html .= "\n".'<!-- iframe plugin v.2.9 wordpress.org/plugins/iframe/ -->'."\n";
91
- $html .= '<iframe';
92
- foreach( $atts as $attr => $value ) {
93
- if ( $attr != 'same_height_as' ) { // remove some attributes
94
- if ( $value != '' ) { // adding all attributes
95
- $html .= ' ' . $attr . '="' . $value . '"';
96
- } else { // adding empty attributes
97
- $html .= ' ' . $attr;
98
- }
99
  }
100
  }
101
- $html .= '></iframe>'."\n";
102
- return $html;
103
  }
104
- add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' );
105
-
106
 
107
- function iframe_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row
108
- if ( strpos( $file, 'iframe.php' ) !== false ) {
109
- $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" title="Plugin page">Iframe</a>' ) );
110
- $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">Donate</a>' ) );
111
- $links = array_merge( $links, array( '<a href="http://codecanyon.net/item/advanced-iframe-pro/5344999?ref=webvitaly">Advanced iFrame Pro</a>' ) );
112
- }
113
- return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  }
115
- add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 );
116
-
117
- endif; // end of (function_exists('iframe_unqprfx_embed_shortcode'))
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: 3.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, $content = null ) {
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
+ // get_params_from_url
30
+ if ( isset( $atts["get_params_from_url"] ) && ( $atts["get_params_from_url"] == '1' || $atts["get_params_from_url"] == 1 ) ) {
31
+ $encode_string = '';
32
+ if ( $_GET != NULL ) {
33
+ if ( strpos( $atts["src"], '?' ) ) { // if we already have '?' and GET params
34
+ $encode_string = '&';
35
+ } else {
36
+ $encode_string = '?';
37
  }
38
+ foreach( $_GET as $key => $value ) {
39
+ $encode_string .= $key.'='.$value.'&';
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
 
 
41
  }
42
+ $encode_string = rtrim($encode_string, '&'); // remove last '&'
43
+ $atts["src"] .= $encode_string;
44
+ }
45
 
46
+ $html = "\n".'<!-- iframe plugin v.3.0 wordpress.org/plugins/iframe/ -->'."\n";
47
+ $html .= '<iframe';
48
+ foreach( $atts as $attr => $value ) {
49
+ if ( $attr != 'same_height_as' ) { // remove some attributes
50
+ if ( $value != '' ) { // adding all attributes
51
+ $html .= ' ' . $attr . '="' . $value . '"';
52
+ } else { // adding empty attributes
53
+ $html .= ' ' . $attr;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
55
  }
 
 
56
  }
57
+ $html .= '></iframe>'."\n";
 
58
 
59
+ if ( isset( $atts["same_height_as"] ) ) {
60
+ $html .= '
61
+ <script>
62
+ document.addEventListener("DOMContentLoaded", function(){
63
+ var target_element, iframe_element;
64
+ iframe_element = document.querySelector("iframe.' . $atts["class"] . '");
65
+ target_element = document.querySelector("' . $atts["same_height_as"] . '");
66
+ iframe_element.style.height = target_element.offsetHeight + "px";
67
+ });
68
+ </script>
69
+ ';
70
+ }
71
+
72
+ return $html;
73
+ }
74
+ add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' );
75
+
76
+
77
+ function iframe_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row
78
+ if ( strpos( $file, 'iframe.php' ) !== false ) {
79
+ $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" title="Plugin page">Iframe</a>' ) );
80
+ $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">Donate</a>' ) );
81
+ $links = array_merge( $links, array( '<a href="http://codecanyon.net/item/advanced-iframe-pro/5344999?ref=webvitaly">Advanced iFrame Pro</a>' ) );
82
  }
83
+ return $links;
84
+ }
85
+ add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 );
readme.txt CHANGED
@@ -4,11 +4,11 @@ Donate link: http://web-profile.com.ua/donate/
4
  Tags: iframe, embed, youtube, vimeo, google-map, google-maps
5
  Requires at least: 3.0
6
  Tested up to: 4.1
7
- Stable tag: 2.9
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
11
- [iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"] shortcode
12
 
13
  == Description ==
14
 
@@ -17,16 +17,17 @@ License URI: http://www.gnu.org/licenses/gpl.html
17
  > **[All iframe params](http://wordpress.org/plugins/iframe/other_notes/)** |
18
  > **[Donate](http://web-profile.com.ua/donate/ "Support the development")**
19
 
20
- [iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"] shortcode
21
  should show something like this:
22
 
23
- [youtube http://www.youtube.com/watch?v=A3PDXmYoF5U]
24
 
25
 
 
26
  Iframe shortcode is the replacement of the iframe html tag and accepts the same [params as iframe](http://wordpress.org/plugins/iframe/other_notes/) html tag does.
27
  You may use iframe shortcode to embed content from YouTube, Vimeo, Google Maps or from any external page.
28
 
29
- If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitter via direct link, you may use `[embed]http://www.youtube.com/watch?v=A3PDXmYoF5U[/embed]` shortcode.
30
  [embed] shortcode is a core WordPress feature and can [embed content from many resources via direct link](http://codex.wordpress.org/Embeds).
31
 
32
  = Useful: =
@@ -37,18 +38,18 @@ If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitte
37
  == Other Notes ==
38
 
39
  = iframe params: =
40
- * **src** - source of the iframe `[iframe src="http://www.youtube.com/embed/A3PDXmYoF5U"]` (by default src="http://www.youtube.com/embed/A3PDXmYoF5U");
41
- * **width** - width in pixels or in percents `[iframe width="100%" src="http://www.youtube.com/embed/A3PDXmYoF5U"]` or `[iframe width="640" src="http://www.youtube.com/embed/A3PDXmYoF5U"]` (by default width="100%");
42
- * **height** - height in pixels `[iframe height="480" src="http://www.youtube.com/embed/A3PDXmYoF5U"]` (by default height="480");
43
- * **scrolling** - parameter `[iframe scrolling="yes"]` (by default scrolling="no");
44
- * **frameborder** - parameter `[iframe frameborder="0"]` (by default frameborder="0");
45
- * **marginheight** - parameter `[iframe marginheight="0"]` (removed by default);
46
- * **marginwidth** - parameter `[iframe marginwidth="0"]` (removed by default);
47
- * **allowtransparency** - allows to set transparency of the iframe `[iframe allowtransparency="true"]` (removed by default);
48
- * **id** - allows to add the id of the iframe `[iframe id="my-id"]` (removed by default);
49
- * **class** - allows to add the class of the iframe `[iframe class="my-class"]` (by default class="iframe-class");
50
- * **style** - allows to add the css styles of the iframe `[iframe style="margin-left:-30px;"]` (removed by default);
51
- * **same_height_as** - allows to set the height of iframe same as target element `[iframe same_height_as="body"]`, `[iframe same_height_as="div.sidebar"]`, `[iframe same_height_as="div#content"]`, `[iframe same_height_as="window"]` - iframe will have the height of the viewport (visible area), `[iframe same_height_as="document"]` - iframe will have the height of the document, `[iframe same_height_as="content"]` - auto-height feature, so the height of the iframe will be the same as embedded content. [same_height_as="content"] works only with the same domain and subdomain. Will not work if you want to embed page "sub.site.com" on page "site.com". (removed by default);
52
  * **get_params_from_url** - allows to add GET params from url to the src of iframe; Example: page url - `site.com/?prm1=11`, shortcode - `[iframe src="embed.com" get_params_from_url="1"]`, iframe src - `embed.com?prm1=11` (disabled by default);
53
  * **any_other_param** - allows to add new parameter of the iframe `[iframe any_other_param="any_value"]`;
54
  * **any_other_empty_param** - allows to add new empty parameter of the iframe (like "allowfullscreen" on youtube) `[iframe any_other_empty_param=""]`;
@@ -59,6 +60,15 @@ If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitte
59
 
60
  == Changelog ==
61
 
 
 
 
 
 
 
 
 
 
62
  = 2.9 - 2014-05-31 =
63
  * remove '&' from the end of the string in 'get_params_from_url' param
64
 
@@ -79,7 +89,7 @@ If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitte
79
 
80
  = 2.3 - 2012.09.09 =
81
  * small fixes
82
- * added (src="http://www.youtube.com/embed/A3PDXmYoF5U") by default
83
 
84
  = 2.2 =
85
  * fixed bug (Notice: Undefined index: same_height_as)
@@ -124,4 +134,4 @@ If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitte
124
  == Installation ==
125
 
126
  1. install and activate the plugin on the Plugins page
127
- 2. add shortcode `[iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"]` to page or post content
4
  Tags: iframe, embed, youtube, vimeo, google-map, google-maps
5
  Requires at least: 3.0
6
  Tested up to: 4.1
7
+ Stable tag: 3.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl.html
10
 
11
+ [iframe src="http://www.youtube.com/embed/4qsGTXLnmKs" width="100%" height="500"] shortcode
12
 
13
  == Description ==
14
 
17
  > **[All iframe params](http://wordpress.org/plugins/iframe/other_notes/)** |
18
  > **[Donate](http://web-profile.com.ua/donate/ "Support the development")**
19
 
20
+ [iframe src="http://www.youtube.com/embed/4qsGTXLnmKs" width="100%" height="500"] shortcode
21
  should show something like this:
22
 
23
+ [youtube http://www.youtube.com/watch?v=4qsGTXLnmKs]
24
 
25
 
26
+ WordPress removes iframe html tags because of security reasons.
27
  Iframe shortcode is the replacement of the iframe html tag and accepts the same [params as iframe](http://wordpress.org/plugins/iframe/other_notes/) html tag does.
28
  You may use iframe shortcode to embed content from YouTube, Vimeo, Google Maps or from any external page.
29
 
30
+ If you need to embed content from YouTube, Vimeo, SlideShare, SoundCloud, Twitter via direct link, you may use `[embed]http://www.youtube.com/watch?v=4qsGTXLnmKs[/embed]` shortcode.
31
  [embed] shortcode is a core WordPress feature and can [embed content from many resources via direct link](http://codex.wordpress.org/Embeds).
32
 
33
  = Useful: =
38
  == Other Notes ==
39
 
40
  = iframe params: =
41
+ * **src** - source of the iframe: `[iframe src="http://www.youtube.com/embed/4qsGTXLnmKs"]`; by default src="http://www.youtube.com/embed/4qsGTXLnmKs";
42
+ * **width** - width in pixels or in percents: `[iframe width="100%"]` or `[iframe width="600"]`; by default width="100%";
43
+ * **height** - height in pixels: `[iframe height="500"]`; by default height="500";
44
+ * **scrolling** - with or without the scrollbar: `[iframe scrolling="no"]`; by default scrolling="yes";
45
+ * **frameborder** - with or without the frame border: `[iframe frameborder="0"]`; by default frameborder="0";
46
+ * **marginheight** - height of the margin: `[iframe marginheight="0"]`; removed by default;
47
+ * **marginwidth** - width of the margin: `[iframe marginwidth="0"]`; removed by default;
48
+ * **allowtransparency** - allows to set transparency of the iframe: `[iframe allowtransparency="true"]`; removed by default;
49
+ * **id** - allows to add the id of the iframe: `[iframe id="custom_id"]`; removed by default;
50
+ * **class** - allows to add the class of the iframe: `[iframe class="custom_class"]`; by default class="iframe-class";
51
+ * **style** - allows to add the css styles of the iframe: `[iframe style="margin-left:-30px;"]`; removed by default;
52
+ * **same_height_as** - allows to set the height of iframe same as target element: `[iframe same_height_as="div.sidebar"]`, `[iframe same_height_as="div#content"]`, `[iframe same_height_as="body"]`, `[iframe same_height_as="html"]`; removed by default;
53
  * **get_params_from_url** - allows to add GET params from url to the src of iframe; Example: page url - `site.com/?prm1=11`, shortcode - `[iframe src="embed.com" get_params_from_url="1"]`, iframe src - `embed.com?prm1=11` (disabled by default);
54
  * **any_other_param** - allows to add new parameter of the iframe `[iframe any_other_param="any_value"]`;
55
  * **any_other_empty_param** - allows to add new empty parameter of the iframe (like "allowfullscreen" on youtube) `[iframe any_other_empty_param=""]`;
60
 
61
  == Changelog ==
62
 
63
+ = 3.0 - 2015-01-25 =
64
+ * removed same_height_as="content", same_height_as="window", same_height_as="document" features because it was not working properly
65
+ * rewrote the javascript-code using pure JavaScript and without jQuery - no need to load jQuery for every site using iframe plugin
66
+ * removed function_exists check because each function has unique prefix
67
+ * code refactored
68
+ * update docs
69
+ * set height="500" instead of 480 by default
70
+ * set scrolling="yes" instead of "no" by default
71
+
72
  = 2.9 - 2014-05-31 =
73
  * remove '&' from the end of the string in 'get_params_from_url' param
74
 
89
 
90
  = 2.3 - 2012.09.09 =
91
  * small fixes
92
+ * added (src="http://www.youtube.com/embed/4qsGTXLnmKs") by default
93
 
94
  = 2.2 =
95
  * fixed bug (Notice: Undefined index: same_height_as)
134
  == Installation ==
135
 
136
  1. install and activate the plugin on the Plugins page
137
+ 2. add shortcode `[iframe src="http://www.youtube.com/embed/4qsGTXLnmKs" width="100%" height="500"]` to page or post content