Widget Logic - Version 0.44

Version Description

Download this release

Release Info

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

Code changes from version 0.43 to 0.44

Files changed (4) hide show
  1. readme.txt +29 -23
  2. screenshot-1.png +0 -0
  3. screenshot-2.png +0 -0
  4. widget_logic.php +3 -3
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: alanft
3
  Tags: widget, admin, conditional tags, filter
4
  Requires at least: 2.5
5
  Tested up to: 2.7
6
- Stable tag: 0.43
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
 
@@ -14,7 +14,11 @@ The text field lets you use WP's [Conditional Tags](http://codex.wordpress.org/C
14
 
15
  There is also an option to add a wordpress 'widget_content' filter for you to tweak standard widgets to suit your theme.
16
 
17
- = Version HIstory =
 
 
 
 
18
  0.42 - WP 2.5+ only now. WP's widget admin has changed so much and I was getting tied up in knots trying to make it work with them both.
19
 
20
  0.4 - Brings WP 2.5 compatibility. I am trying to make it back compatible. If you have trouble using WL with WP 2.1--2.3 let me know the issue.
@@ -32,15 +36,18 @@ Kjetil Flekkoy for reporting and helping to diagnose errors in the 0.4 version
32
 
33
  == Frequently Asked Questions ==
34
 
35
- = I get no sidebar at all when the plugin is active =
36
 
37
- The logic text on one of your widgets may be invalid PHP.
38
 
39
- (Need more FAQs!)
 
 
 
40
 
41
  == Screenshots ==
42
 
43
- 1. The 'Widget logic' field at work in a widget I use.
44
  2. The 'widget_content' filter option is at the foot of the widget admin page. (Off by default.)
45
 
46
  == Writing Logic Code ==
@@ -51,21 +58,22 @@ It is important to include terminating ';'s. If there is no 'return' in the text
51
 
52
  Examples:
53
 
54
- * is\_home()
55
- * is\_category(5)
56
- * is\_home() || is\_category('baked-goods')
57
- * is\_page('about')
58
- * $x=(1==1)?true:false; return ( !is_home() && $x);
 
59
 
60
- Note the use of ';' where there is an explicit 'return'.
61
 
62
  == The 'widget_content' filter ==
63
 
64
- Once this is active (by the option tickbox at the foot of the widget admin page) you can modify the text displayed by any widget. In your theme's functions.php file use:
65
 
66
  `add_filter('widget_content', 'your_filter_function', [priority], 2);`
67
 
68
- your function can take 2 parameters (hence that final 2) like this:
69
 
70
  `function your_filter_function($content='', $widget_id='')`
71
 
@@ -78,22 +86,20 @@ This adds the widget_id to the foot of every widget:
78
  `function reveal_widget_id($content='', $widget_id='')
79
  { return $content."id=".$widget_id; }`
80
 
81
- I was motivated to make 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:
82
 
83
  `function ttftext_widget_title($content='', $widget_id='')
84
- { preg_match("/<h2[^>]*>([^<]+)/",$content, $matches))
85
  $heading=$matches[1];
86
  $insert_img=the_ttftext( $heading, false );
87
  $content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
88
  return $content;
89
  }`
90
 
91
- I add an 'all comments' RSS link to the [Brian's Latest Comments Widget](http://www.4null4.de/142/sidebar-widget-brians-latest-comments/) with this:
92
 
93
  `function blc_add_rss_feed($content='', $widget_id='')
94
- { if ($widget_id=='brians-latest-comments')
95
- { $insert_rss='<a href="./comments/feed/" title="Feed of all comments"><img src="' . get_bloginfo('template_url') . '/images/rss.gif" alt="rss" /></a>';
96
- $content=str_replace("</h2>",$insert_rss."</h2>",$content);
97
- }
98
- return $content;
99
- }`
3
  Tags: widget, admin, conditional tags, filter
4
  Requires at least: 2.5
5
  Tested up to: 2.7
6
+ Stable tag: 0.44
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
 
14
 
15
  There is also an option to add a wordpress 'widget_content' filter for you to tweak standard widgets to suit your theme.
16
 
17
+ = Version History =
18
+ 0.44 - Officially works with 2.7 now. Documentation changes and minor bug fixes.
19
+
20
+ 0.43 - simple bug fix (form data was being lost when 'Cancel'ing widgets)
21
+
22
  0.42 - WP 2.5+ only now. WP's widget admin has changed so much and I was getting tied up in knots trying to make it work with them both.
23
 
24
  0.4 - Brings WP 2.5 compatibility. I am trying to make it back compatible. If you have trouble using WL with WP 2.1--2.3 let me know the issue.
36
 
37
  == Frequently Asked Questions ==
38
 
39
+ = Why isn't it working? =
40
 
41
+ Try switching to the WP default theme - if the problem goes away, there is something specific to your theme that may be interfering with the WP conditional tags.
42
 
43
+ The most common sources of problems are:
44
+
45
+ * The logic text on one of your widgets may be invalid PHP.
46
+ * Your theme doesn't call wp_head()
47
 
48
  == Screenshots ==
49
 
50
+ 1. The 'Widget logic' field at work in standard widgets.
51
  2. The 'widget_content' filter option is at the foot of the widget admin page. (Off by default.)
52
 
53
  == Writing Logic Code ==
58
 
59
  Examples:
60
 
61
+ * `is_home()`
62
+ * `!is_category(5)`
63
+ * `is_single() && in_category('baked-goods')`
64
+ * `is_page('about')`
65
+ * `current_user_can('level_10')`
66
+ * `global $post; return ((is_page('home') || ($post->post_parent=="13"));`
67
 
68
+ Note the use of ';' where there is an explicit 'return'. Use `||` (OR), `&&` (AND) and `!` (NOT) to make more complex conditions.
69
 
70
  == The 'widget_content' filter ==
71
 
72
+ Once this is active (tick the option tickbox at the foot of the widget admin page) you can modify the text displayed by any widget. In your theme's functions.php file use:
73
 
74
  `add_filter('widget_content', 'your_filter_function', [priority], 2);`
75
 
76
+ where `[priority]` is the optional priority parameter for the [add_filter](http://codex.wordpress.org/Function_Reference/add_filter) function. The filter function can take 2 parameters (hence that final 2) like this:
77
 
78
  `function your_filter_function($content='', $widget_id='')`
79
 
86
  `function reveal_widget_id($content='', $widget_id='')
87
  { return $content."id=".$widget_id; }`
88
 
89
+ I was motivated to make this filter in order to render all widget titles with the excellent [ttftitles plugin](http://templature.com/2007/10/18/ttftitles-wordpress-plugin/) like this:
90
 
91
  `function ttftext_widget_title($content='', $widget_id='')
92
+ { preg_match("/<h2[^>]*>([^<]+)/",$content, $matches);
93
  $heading=$matches[1];
94
  $insert_img=the_ttftext( $heading, false );
95
  $content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
96
  return $content;
97
  }`
98
 
99
+ I add an 'all comments' RSS link to the [Get Recent Comments](http://wordpress.org/extend/plugins/get-recent-comments/) widget with this:
100
 
101
  `function blc_add_rss_feed($content='', $widget_id='')
102
+ { $insert_rss='<a href="./comments/feed/" title="Feed of all our comments"><img src="' . get_bloginfo('template_url') . '/images/rss.gif" alt="rss" /></a>';
103
+ $content=str_replace("</h2>",$insert_rss."</h2>",$content);
104
+ }
105
+ `
 
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
widget_logic.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Widget Logic
4
  Plugin URI: http://freakytrigger.co.uk/wordpress-setup/
5
  Description: Control widgets with WP's conditional tags is_home etc
6
  Author: Alan Trewartha
7
- Version: 0.43
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
@@ -25,7 +25,7 @@ function widget_logic_expand_control()
25
  $wl_options[$widget_id]=$_POST[$widget_id.'-widget_logic'];
26
 
27
  // clean up empty options (in PHP5 use array_intersect_key)
28
- $regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values((array) $_POST['widget-id']));
29
  foreach (array_keys($wl_options) as $key)
30
  if (!in_array($key, $regd_plus_new))
31
  unset($wl_options[$key]);
@@ -127,7 +127,7 @@ function widget_logic_redirected_callback()
127
 
128
  $wl_options = get_option('widget_logic'); // do we want the widget?
129
  $wl_value=($wl_options[$id])?stripslashes($wl_options[$id]):"true";
130
- $wl_value=(stristr($wl_value, "return"))?$wl_value:"return ".$wl_value.";";
131
 
132
  $wl_value=(eval($wl_value) && is_callable($callback));
133
  if ( $wl_value )
4
  Plugin URI: http://freakytrigger.co.uk/wordpress-setup/
5
  Description: Control widgets with WP's conditional tags is_home etc
6
  Author: Alan Trewartha
7
+ Version: 0.44
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
25
  $wl_options[$widget_id]=$_POST[$widget_id.'-widget_logic'];
26
 
27
  // clean up empty options (in PHP5 use array_intersect_key)
28
+ $regd_plus_new=array_merge(array_keys($wp_registered_widgets),array_values((array) $_POST['widget-id']),(array)'widget_logic-options-filter');
29
  foreach (array_keys($wl_options) as $key)
30
  if (!in_array($key, $regd_plus_new))
31
  unset($wl_options[$key]);
127
 
128
  $wl_options = get_option('widget_logic'); // do we want the widget?
129
  $wl_value=($wl_options[$id])?stripslashes($wl_options[$id]):"true";
130
+ $wl_value=(stristr($wl_value, "return"))?$wl_value:"return (".$wl_value.");";
131
 
132
  $wl_value=(eval($wl_value) && is_callable($callback));
133
  if ( $wl_value )