iframe - Version 2.0

Version Description

  • plugin core rebuild (thanks to Gregg Tavares);
  • remove not setted params except the defaults;
  • added support for all params, which user will set;
  • added support for empty params (like "allowfullscreen" on youtube);
Download this release

Release Info

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

Code changes from version 1.8 to 2.0

Files changed (2) hide show
  1. iframe.php +36 -37
  2. readme.txt +19 -11
iframe.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /*
3
- Plugin Name: Iframe
4
  Plugin URI: http://web-profile.com.ua/wordpress/plugins/iframe/
5
  Description: Plugin shows iframe with [iframe src="http://player.vimeo.com/video/3261363" width="100%" height="480"] shortcode.
6
- Version: 1.8
7
  Author: webvitaly
8
  Author Email: webvitaly(at)gmail.com
9
  Author URI: http://web-profile.com.ua/wordpress/
@@ -17,47 +17,47 @@ if ( !function_exists( 'iframe_embed_shortcode' ) ) :
17
  add_action('wp_enqueue_scripts', 'iframe_enqueue_script');
18
 
19
  function iframe_embed_shortcode($atts, $content = null) {
20
- extract(shortcode_atts(array(
21
  'width' => '100%',
22
  'height' => '480',
23
- 'src' => '',
24
- 'frameborder' => '0',
25
  'scrolling' => 'no',
26
- 'marginheight' => '0',
27
- 'marginwidth' => '0',
28
- 'allowtransparency' => 'true',
29
- 'id' => '',
30
- 'class' => 'iframe-class',
31
- 'style' => '',
32
- 'same_height_as' => ''
33
- ), $atts));
34
- $src_cut = substr($src, 0, 35);
 
35
  if(strpos($src_cut, 'maps.google' )){
36
- $google_map_fix = '&output=embed';
37
- }else{
38
- $google_map_fix = '';
39
  }
40
- $return = '';
 
41
  if( $same_height_as != '' ){
 
42
  if( $same_height_as != 'content' ){ // we are setting the height of the iframe like as target element
43
  if( $same_height_as == 'document' || $same_height_as == 'window' ){ // remove quotes for window or document selectors
44
  $target_selector = $same_height_as;
45
  }else{
46
- $target_selector = '"'.$same_height_as.'"';
47
  }
48
- $return .= '
49
  <script>
50
  jQuery(document).ready(function($) {
51
- var target_height = $('.$target_selector.').height();
52
- $("iframe.'.$class.'").height(target_height);
 
53
  });
54
  </script>
55
  ';
56
  }else{ // set the actual height of the iframe (show all content of the iframe without scroll)
57
- $return .= '
58
  <script>
59
  jQuery(document).ready(function($) {
60
- $("iframe.'.$class.'").bind("load", function() {
61
  var embed_height = $(this).contents().find("body").height();
62
  $(this).height(embed_height);
63
  });
@@ -66,20 +66,19 @@ if ( !function_exists( 'iframe_embed_shortcode' ) ) :
66
  ';
67
  }
68
  }
69
- if( $id != '' ){
70
- $id_text = 'id="'.$id.'" ';
71
- }else{
72
- $id_text = '';
73
- }
74
- if( $style != '' ){
75
- $style_text = 'style="'.$style.'" ';
76
- }else{
77
- $style_text = '';
 
78
  }
79
- $return .= "\n".'<!-- powered by Iframe plugin ver. 1.8 (wordpress.org/extend/plugins/iframe/) -->'."\n";
80
- $return .= '<iframe '.$id_text.'class="'.$class.'" '.$style_text.'width="'.$width.'" height="'.$height.'" src="'.$src.$google_map_fix.'" frameborder="'.$frameborder.'" scrolling="'.$scrolling.'" marginheight="'.$marginheight.'" marginwidth="'.$marginwidth.'" allowtransparency="'.$allowtransparency.'"></iframe>';
81
- // &amp;output=embed
82
- return $return;
83
  }
84
  add_shortcode('iframe', 'iframe_embed_shortcode');
85
 
1
  <?php
2
  /*
3
+ Plugin Name: iframe
4
  Plugin URI: http://web-profile.com.ua/wordpress/plugins/iframe/
5
  Description: Plugin shows iframe with [iframe src="http://player.vimeo.com/video/3261363" width="100%" height="480"] shortcode.
6
+ Version: 2.0
7
  Author: webvitaly
8
  Author Email: webvitaly(at)gmail.com
9
  Author URI: http://web-profile.com.ua/wordpress/
17
  add_action('wp_enqueue_scripts', 'iframe_enqueue_script');
18
 
19
  function iframe_embed_shortcode($atts, $content = null) {
20
+ $defaults = array(
21
  'width' => '100%',
22
  'height' => '480',
 
 
23
  'scrolling' => 'no',
24
+ 'class' => 'iframe-class'
25
+ );
26
+ // add defaults
27
+ foreach ($defaults as $default => $value) {
28
+ if (!array_key_exists($default, $atts)) {
29
+ $atts[$default] = $value;
30
+ }
31
+ }
32
+ // special case maps
33
+ $src_cut = substr($atts["src"], 0, 35);
34
  if(strpos($src_cut, 'maps.google' )){
35
+ $atts["src"] .= '&output=embed';
 
 
36
  }
37
+ $html = '';
38
+ $same_height_as = $atts["same_height_as"];
39
  if( $same_height_as != '' ){
40
+ $atts["same_height_as"] = '';
41
  if( $same_height_as != 'content' ){ // we are setting the height of the iframe like as target element
42
  if( $same_height_as == 'document' || $same_height_as == 'window' ){ // remove quotes for window or document selectors
43
  $target_selector = $same_height_as;
44
  }else{
45
+ $target_selector = '"' . $same_height_as . '"';
46
  }
47
+ $html .= '
48
  <script>
49
  jQuery(document).ready(function($) {
50
+ var target_height = $(' . $target_selector . ').height();
51
+ $("iframe.' . $atts["class"] . '").height(target_height);
52
+ //alert(target_height);
53
  });
54
  </script>
55
  ';
56
  }else{ // set the actual height of the iframe (show all content of the iframe without scroll)
57
+ $html .= '
58
  <script>
59
  jQuery(document).ready(function($) {
60
+ $("iframe.' . $atts["class"] . '").bind("load", function() {
61
  var embed_height = $(this).contents().find("body").height();
62
  $(this).height(embed_height);
63
  });
66
  ';
67
  }
68
  }
69
+ $html .= "\n".'<!-- powered by Iframe plugin ver.2.0 (wordpress.org/extend/plugins/iframe/) -->'."\n";
70
+ $html .= '<iframe';
71
+ foreach ($atts as $attr => $value) {
72
+ if( $attr != 'same_height_as' ){ // remove some attributes
73
+ if( $value != '' ) { // adding all attributes
74
+ $html .= ' ' . $attr . '="' . $value . '"';
75
+ } else { // adding empty attributes
76
+ $html .= ' ' . $attr;
77
+ }
78
+ }
79
  }
80
+ $html .= '></iframe>';
81
+ return $html;
 
 
82
  }
83
  add_shortcode('iframe', 'iframe_embed_shortcode');
84
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: iframe, embed, youtube, vimeo, google-map, google-maps
5
  Author URI: http://web-profile.com.ua/wordpress/
6
  Requires at least: 3.0
7
  Tested up to: 3.3
8
- Stable tag: 1.8
9
 
10
  You can embed iframe with [iframe src="http://vimeo.com/123" width="100%" height="480"] shortcode.
11
 
@@ -16,18 +16,20 @@ WordPress removes iframe when you switch from "HTML" to "Visual" tab because of
16
  So you can embed iframe code using this shortcode `[iframe src="http://player.vimeo.com/video/3261363" width="100%" height="480"]`.
17
 
18
  = Usage (allowed parameters) =
 
19
  * **width** - width in pixels or in percents `[iframe width="100%" src="http://player.vimeo.com/video/3261363"]` or `[iframe width="640" src="http://player.vimeo.com/video/3261363"]` (by default width="100%");
20
  * **height** - height in pixels `[iframe height="480" src="http://player.vimeo.com/video/3261363"]` (by default height="480");
21
- * **src** - source of the iframe `[iframe src="http://player.vimeo.com/video/3261363"]` (by default src="");
22
- * **frameborder** - parameter of the iframe `[iframe frameborder="0" src="http://player.vimeo.com/video/3261363"]` (by default frameborder="0");
23
- * **scrolling** - parameter of the iframe `[iframe scrolling="no" src="http://player.vimeo.com/video/3261363"]` (by default scrolling="no");
24
- * **marginheight** - parameter of the iframe `[iframe marginheight="0" src="http://player.vimeo.com/video/3261363"]` (by default marginheight="0");
25
- * **marginwidth** - parameter of the iframe `[iframe marginwidth="0" src="http://player.vimeo.com/video/3261363"]` (by default marginwidth="0");
26
- * **allowtransparency** - allows to set transparency of the iframe `[iframe allowtransparency="true" src="http://player.vimeo.com/video/3261363"]` (by default allowtransparency="true");
27
- * **id** - allows to add the id of the iframe `[iframe id="my-id" src="http://player.vimeo.com/video/3261363"]` (by default id="");
28
- * **class** - allows to add the class of the iframe `[iframe class="my-class" src="http://player.vimeo.com/video/3261363"]` (by default class="iframe-class");
29
- * **style** - allows to add the css styles of the iframe `[iframe style="margin-left:-30px;" src="http://player.vimeo.com/video/3261363"]` (by default style="");
30
- * **same_height_as** - allows to set the height of iframe same as target element `[iframe same_height_as="body" src="http://player.vimeo.com/video/3261363"]`, `[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 parent document (not the height of the embedded document), `[iframe same_height_as="content"]` - auto-height feature, so the height of the iframe will be the same as embedded content (works only with the same domain) (by default same_height_as="");
 
31
 
32
  [Iframe plugin page](http://web-profile.com.ua/wordpress/plugins/iframe/)
33
 
@@ -35,6 +37,12 @@ So you can embed iframe code using this shortcode `[iframe src="http://player.vi
35
 
36
  == Changelog ==
37
 
 
 
 
 
 
 
38
  = 1.8 =
39
  * Added style parameter;
40
 
5
  Author URI: http://web-profile.com.ua/wordpress/
6
  Requires at least: 3.0
7
  Tested up to: 3.3
8
+ Stable tag: 2.0
9
 
10
  You can embed iframe with [iframe src="http://vimeo.com/123" width="100%" height="480"] shortcode.
11
 
16
  So you can embed iframe code using this shortcode `[iframe src="http://player.vimeo.com/video/3261363" width="100%" height="480"]`.
17
 
18
  = Usage (allowed parameters) =
19
+ * **src** - source of the iframe `[iframe src="http://player.vimeo.com/video/3261363"]` (empty by default src="");
20
  * **width** - width in pixels or in percents `[iframe width="100%" src="http://player.vimeo.com/video/3261363"]` or `[iframe width="640" src="http://player.vimeo.com/video/3261363"]` (by default width="100%");
21
  * **height** - height in pixels `[iframe height="480" src="http://player.vimeo.com/video/3261363"]` (by default height="480");
22
+ * **scrolling** - parameter `[iframe scrolling="yes"]` (by default scrolling="no");
23
+ * **frameborder** - parameter `[iframe frameborder="0"]` (removed by default);
24
+ * **marginheight** - parameter `[iframe marginheight="0"]` (removed by default);
25
+ * **marginwidth** - parameter `[iframe marginwidth="0"]` (removed by default);
26
+ * **allowtransparency** - allows to set transparency of the iframe `[iframe allowtransparency="true"]` (removed by default);
27
+ * **id** - allows to add the id of the iframe `[iframe id="my-id"]` (removed by default);
28
+ * **class** - allows to add the class of the iframe `[iframe class="my-class"]` (by default class="iframe-class");
29
+ * **style** - allows to add the css styles of the iframe `[iframe style="margin-left:-30px;"]` (removed by default);
30
+ * **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 (works only with the same domain) (removed by default);
31
+ * **any_other_param** - allows to add new parameter of the iframe `[iframe any_other_param="any_value"]`;
32
+ * **any_other_empty_param** - allows to add new empty parameter of the iframe (like "allowfullscreen" on youtube) `[iframe any_other_empty_param=""]`;
33
 
34
  [Iframe plugin page](http://web-profile.com.ua/wordpress/plugins/iframe/)
35
 
37
 
38
  == Changelog ==
39
 
40
+ = 2.0 =
41
+ * plugin core rebuild (thanks to Gregg Tavares);
42
+ * remove not setted params except the defaults;
43
+ * added support for all params, which user will set;
44
+ * added support for empty params (like "allowfullscreen" on youtube);
45
+
46
  = 1.8 =
47
  * Added style parameter;
48