Widget Logic - Version 0.31

Version Description

Download this release

Release Info

Developer alanft
Plugin Icon 128x128 Widget Logic
Version 0.31
Comparing to
See all releases

Code changes from version 0.3 to 0.31

Files changed (2) hide show
  1. readme.txt +31 -11
  2. widget_logic.php +4 -4
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Widget Logic ===
2
  Contributors: alanft
3
- Tags: widget, admin, conditional tags
4
  Requires at least: 2.1
5
  Tested up to: 2.3.2
6
- Stable tag: 0.3
7
 
8
- Widget Logic lets you add 'conditional tags' logic from the usual widget admin interface. It optionally adds a 'widget_content' filter.
9
 
10
  == Description ==
11
  This plugin gives every widget (even widgets lacking controls) an extra control called "Widget logic".
@@ -39,35 +39,55 @@ I've tested it looks OK on Safari, Firefox and even PC IE6. But let me know what
39
 
40
  == Writing Logic Code ==
41
 
42
- The text you write in the 'Widget logic' field can currently be full PHP code so long as it returns 'true' when you need the widget to appear - note that you need terminating ';'s.
43
 
44
- If there is no 'return' in the text, there is an implicit 'return ' added on the start and a ';' on the end.
45
 
46
  Examples:
47
 
48
  * is\_home()
49
  * is\_category(5)
50
  * is\_home() || is\_category(5)
51
- * $x=(1==1)?true:false; return ( !is_home && $x);
 
52
 
53
  Note the use of ';' where there is an explicit 'return'.
54
 
55
  == The 'widget_content' filter ==
56
 
57
- To filter widget contents use:
58
 
59
- `add_filter('widget_content', 'your_filter_function' , [priority] ,2);`
60
 
61
  your function can take 2 parameters (hence that final 2) like this:
62
 
63
- `function your_filter_function($content='', $widget_id='')`
64
 
65
- The second parameter (widget_id) allows you to target specific widgets. As an example here is a function I use to render all widget titles with the excellent ttftext plugin:
66
 
67
- `function ttftext_widget_tite($content='', $widget_id='')
 
 
 
 
 
 
 
 
 
68
  { preg_match("/<h2[^>]*>([^<]+)/",$content, $matches))
69
  $heading=$matches[1];
70
  $insert_img=the_ttftext( $heading, false );
71
  $content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
72
  return $content;
 
 
 
 
 
 
 
 
 
 
73
  }`
1
  === Widget Logic ===
2
  Contributors: alanft
3
+ Tags: widget, admin, conditional tags, filter
4
  Requires at least: 2.1
5
  Tested up to: 2.3.2
6
+ Stable tag: 0.31
7
 
8
+ Widget Logic lets you control when widgets appear. Add WP's conditional tags in the normal widget admin. It also adds a 'widget_content' filter.
9
 
10
  == Description ==
11
  This plugin gives every widget (even widgets lacking controls) an extra control called "Widget logic".
39
 
40
  == Writing Logic Code ==
41
 
42
+ The text in the 'Widget logic' field can currently be full PHP code. The code should return 'true' when you need the widget to appear.
43
 
44
+ It is important to include terminating ';'s. If there is no 'return' in the text, an implicit 'return' is added to the start and a final ';' is also added.
45
 
46
  Examples:
47
 
48
  * is\_home()
49
  * is\_category(5)
50
  * is\_home() || is\_category(5)
51
+ * is\_page('about')
52
+ * $x=(1==1)?true:false; return ( !is_home() && $x);
53
 
54
  Note the use of ';' where there is an explicit 'return'.
55
 
56
  == The 'widget_content' filter ==
57
 
58
+ This now needs to be explicitly activated on the widget admin page. To filter widget contents in your themes functions, or in other plugins, use:
59
 
60
+ `add_filter('widget_content', 'your_filter_function', [priority], 2);`
61
 
62
  your function can take 2 parameters (hence that final 2) like this:
63
 
64
+ `function your_filter_function($content='', $widget_id='')`
65
 
66
+ The second parameter (widget_id) can be used to target specific widgets if needed.
67
 
68
+ _Example filters_
69
+
70
+ This adds the widget_id to the foot of every widget:
71
+
72
+ `function reveal_widget_id($content='', $widget_id='')
73
+ { return $content."id=".$widget_id; }`
74
+
75
+ I added this filter in order to render all widget titles with the excellent [ttftext plugin](http://templature.com/2007/10/18/ttftitles-wordpress-plugin/) like this:
76
+
77
+ `function ttftext_widget_title($content='', $widget_id='')
78
  { preg_match("/<h2[^>]*>([^<]+)/",$content, $matches))
79
  $heading=$matches[1];
80
  $insert_img=the_ttftext( $heading, false );
81
  $content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
82
  return $content;
83
+ }`
84
+
85
+ I add a 'all comments' RSS link to the [Brian's Latest Comments Widget](http://www.4null4.de/142/sidebar-widget-brians-latest-comments/) with this:
86
+
87
+ `function blc_add_rss_feed($content='', $widget_id='')
88
+ { if ($widget_id=='brians-latest-comments')
89
+ { $insert_rss='<a href="./comments/feed/" title="Feed of all comments"><img src="' . get_bloginfo('template_url') . '/images/rss.gif" alt="rss" /></a>';
90
+ $content=str_replace("</h2>",$insert_rss."</h2>",$content);
91
+ }
92
+ return $content;
93
  }`
widget_logic.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: Widget Logic
4
- Plugin URI: http://freakytrigger.co.uk/
5
  Description: Allows widgets to appear as directed by WP tags is_home etc
6
  Author: Alan Trewartha
7
- Version: 0.3
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
@@ -38,7 +38,7 @@ function widget_logic_add_control()
38
  nc.innerHTML="<label for='" + id + "-widget_logic'>Widget logic <input type='text' name='" + id + "-widget_logic' id='" + id + "-widget_logic' value='" + value + "' /></label>";
39
  document.getElementById(id + "control").getElementsByTagName("div").item(0).appendChild(nc);
40
  }
41
- <?
42
  foreach ( $wp_registered_widget_controls as $name => $widget )
43
  { $id=$widget['id'];
44
 
@@ -60,7 +60,7 @@ function widget_logic_add_control()
60
  <h2>Widget Logic options</h2>
61
  <p style="line-height: 30px;">
62
  <label for="widget_logic-options-filter">Use 'widget_content' filter?
63
- <input id="widget_logic-options-filter" name="widget_logic-options-filter" type="checkbox" value="checked" class="checkbox" <? echo $wl_options['widget_logic-options-filter'] ?> /></label>
64
  <span class="submit"><input type="submit" name="widget_logic-options-submit" id="widget_logic-options-submit" value="Save" /></span></p>
65
  </form>
66
  </div>
1
  <?php
2
  /*
3
  Plugin Name: Widget Logic
4
+ Plugin URI: http://freakytrigger.co.uk/wordpress-setup/
5
  Description: Allows widgets to appear as directed by WP tags is_home etc
6
  Author: Alan Trewartha
7
+ Version: 0.31
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
38
  nc.innerHTML="<label for='" + id + "-widget_logic'>Widget logic <input type='text' name='" + id + "-widget_logic' id='" + id + "-widget_logic' value='" + value + "' /></label>";
39
  document.getElementById(id + "control").getElementsByTagName("div").item(0).appendChild(nc);
40
  }
41
+ <?php
42
  foreach ( $wp_registered_widget_controls as $name => $widget )
43
  { $id=$widget['id'];
44
 
60
  <h2>Widget Logic options</h2>
61
  <p style="line-height: 30px;">
62
  <label for="widget_logic-options-filter">Use 'widget_content' filter?
63
+ <input id="widget_logic-options-filter" name="widget_logic-options-filter" type="checkbox" value="checked" class="checkbox" <?php echo $wl_options['widget_logic-options-filter'] ?> /></label>
64
  <span class="submit"><input type="submit" name="widget_logic-options-submit" id="widget_logic-options-submit" value="Save" /></span></p>
65
  </form>
66
  </div>