Widget Logic - Version 0.50

Version Description

For the first time since this started on WP 2.3, I've rewritten how the core widget logic function works, so there may be 'bumps ahead'.

It now uses the 'sidebars_widgets' filter (as it should have done when that was introduced in WP2.8 by the look of it). The upshot is that is_active_sidebar should behave properly.

Widget callbacks only get intercepted if the 'widget_content' filter is activated, and much more briefly. (A widget's 'callback' is rewired within the 'dynamic_sidebar' function just before the widget is called, by the 'dynamic_sidebar_param' filter, and is restored when the callback function is invoked.)

Download this release

Release Info

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

Code changes from version 0.48 to 0.50

Files changed (2) hide show
  1. readme.txt +29 -11
  2. widget_logic.php +136 -96
readme.txt CHANGED
@@ -2,28 +2,28 @@
2
  Contributors: alanft
3
  Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
4
  Tags: widget, admin, conditional tags, filter, context
5
- Requires at least: 2.5
6
- Tested up to: 3.1
7
- Stable tag: 0.48
8
 
9
- Widget Logic lets you control on which pages widgets appear. It uses any of WP's conditional tags. It also adds a 'widget_content' filter.
10
 
11
  == Description ==
12
- This plugin gives every widget an extra control field called "Widget logic" that lets you control the pages that the widget will appear on.
13
 
14
- The text field lets you use WP's [Conditional Tags](http://codex.wordpress.org/Conditional_Tags), or any general PHP code.
15
 
16
- There is also an option to add a wordpress 'widget_content' filter -- this lets you tweak standard widgets to suit your theme without editing plugins and core code.
17
 
18
  = Donations =
19
 
20
- If you like and use Widget Logic you could consider a small donation to Cancer Research UK. I have a [JustGiving.com donation link](http://www.justgiving.com/widgetlogic_cancerresearchuk) above with the aim of raising 500 UKP in the next 12 months.
21
 
22
  == Installation ==
23
 
24
  1. Upload `widget-logic.php` to the `/wp-content/plugins/` directory
25
  2. Activate the plugin through the 'Plugins' menu in WordPress
26
- 3. That's it. All the configuring is in the usual widget admin interface.
27
 
28
  == Frequently Asked Questions ==
29
 
@@ -34,9 +34,12 @@ Try switching to the WP default theme - if the problem goes away, there is somet
34
  The most common sources of problems are:
35
 
36
  * The logic text on one of your widgets is invalid PHP
37
- * Your theme doesn't call wp_head()
38
  * Your theme performs custom queries before calling the dynamic sidebar -- if so, try ticking the `wp_reset_query` option.
39
 
 
 
 
 
40
  = Widgets appear when they shouldn't =
41
 
42
  It might be that your theme performs custom queries before calling the sidebar. Try the `wp_reset_query` option.
@@ -102,8 +105,15 @@ where `[priority]` is the optional priority parameter for the [add_filter](http:
102
 
103
  The second parameter ($widget_id) can be used to target specific widgets if needed.
104
 
 
 
105
  _Example filters_
106
 
 
 
 
 
 
107
  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:
108
 
109
  `add_filter('widget_content', 'ttftext_widget_title');
@@ -127,8 +137,16 @@ function make_alternating_widget_styles($content='')
127
 
128
  == Changelog ==
129
 
 
 
 
 
 
 
 
 
130
  = 0.48 =
131
- Kill some poor coding practices that throws debug notices - thanks to John James Jacoby.
132
 
133
  = 0.47 =
134
  FINALLY tracked down the elusive 'wp_reset_query' option resetting bug.
2
  Contributors: alanft
3
  Donate link: http://www.justgiving.com/widgetlogic_cancerresearchuk
4
  Tags: widget, admin, conditional tags, filter, context
5
+ Requires at least: 2.8
6
+ Tested up to: 3.3
7
+ Stable tag: 0.50
8
 
9
+ Widget Logic lets you control on which pages widgets appear using WP's conditional tags. It also adds a 'widget_content' filter.
10
 
11
  == Description ==
12
+ This plugin gives every widget an extra control field called "Widget logic" that lets you control the pages that the widget will appear on. The text field lets you use WP's [Conditional Tags](http://codex.wordpress.org/Conditional_Tags), or any general PHP code.
13
 
14
+ ** PLEASE NOTE ** The widget logic you introduce is EVAL'd directly. Anyone who has access to edit widget appearance will have the right to add any code, including malicious and possibly destructive functions. If you are worried about the security implications, please let me know how you think I could guard against this without compromising the general power and flexibility of Widget Logic too much.
15
 
16
+ There is also an option to add a wordpress 'widget_content' filter -- this lets you tweak any widget's HTML to suit your theme without editing plugins and core code.
17
 
18
  = Donations =
19
 
20
+ If you like and use Widget Logic you could consider a small donation to Cancer Research UK. I have a [JustGiving.com donation link](http://www.justgiving.com/widgetlogic_cancerresearchuk). As of December 2011 we have raised 440 UKP. I'm going to aim to have upped that to 750 UKP by the end of 2012.
21
 
22
  == Installation ==
23
 
24
  1. Upload `widget-logic.php` to the `/wp-content/plugins/` directory
25
  2. Activate the plugin through the 'Plugins' menu in WordPress
26
+ 3. That's it. All the configuring and options are in the usual widget admin interface.
27
 
28
  == Frequently Asked Questions ==
29
 
34
  The most common sources of problems are:
35
 
36
  * The logic text on one of your widgets is invalid PHP
 
37
  * Your theme performs custom queries before calling the dynamic sidebar -- if so, try ticking the `wp_reset_query` option.
38
 
39
+ = Use 'wp_reset_query' fix option isn't working properly any more =
40
+
41
+ In version 0.50 I made some fundamental changes to how Widget Logic works. The result was that the wp_reset_query was less targeted in the code. If lots of people find this problematic I will look at a general solution, but the main workround is to put wp_reset_query() into your code just before calling a dynamic sidebar.
42
+
43
  = Widgets appear when they shouldn't =
44
 
45
  It might be that your theme performs custom queries before calling the sidebar. Try the `wp_reset_query` option.
105
 
106
  The second parameter ($widget_id) can be used to target specific widgets if needed.
107
 
108
+ A [Wordpress filter function](http://codex.wordpress.org/Plugin_API#Filters) 'takes as input the unmodified data, and returns modified data' which means that widget_content filters are provided with the raw HTML output by the widget, and you are then free to return something else entirely:
109
+
110
  _Example filters_
111
 
112
+ `add_filter('widget_content', 'basic_widget_content_filter');
113
+ function basic_widget_content_filter($content='')
114
+ { return $content."<PRE>THIS APPEARS AFTER EVERY WIDGET</PRE>";
115
+ }`
116
+
117
  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:
118
 
119
  `add_filter('widget_content', 'ttftext_widget_title');
137
 
138
  == Changelog ==
139
 
140
+ = 0.50 =
141
+ For the first time since this started on WP 2.3, I've rewritten how the core widget logic function works, so there may be 'bumps ahead'.
142
+
143
+ It now uses the 'sidebars_widgets' filter (as it should have done when that was
144
+ introduced in WP2.8 by the look of it). The upshot is that is_active_sidebar should behave properly.
145
+
146
+ Widget callbacks only get intercepted if the 'widget_content' filter is activated, and much more briefly. (A widget's 'callback' is rewired within the 'dynamic_sidebar' function just before the widget is called, by the 'dynamic_sidebar_param' filter, and is restored when the callback function is invoked.)
147
+
148
  = 0.48 =
149
+ Kill some poor coding practices that throws debug notices - thanks to John James Jacoby. This is currently the 'last stable release'
150
 
151
  = 0.47 =
152
  FINALLY tracked down the elusive 'wp_reset_query' option resetting bug.
widget_logic.php CHANGED
@@ -4,39 +4,35 @@ 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.48
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
 
 
11
 
12
- add_filter( 'widget_update_callback', 'widget_logic_widget_update_callback', 10, 3);
13
- add_filter( "plugin_action_links", "wl_charity", 10, 2);
14
-
15
- function wl_charity($links, $file) {
16
- if ($file == plugin_basename(__FILE__))
17
- array_push($links, '<a href="http://www.justgiving.com/widgetlogic_cancerresearchuk/">Charity Donation</a>');
18
- return $links;
19
  }
 
 
 
20
 
21
- // new in 2.8 - ajaxy update of a single widget
22
- function widget_logic_widget_update_callback($instance, $new_instance, $this_widget)
23
- { $widget_id=$this_widget->id;
24
- if ( isset($_POST[$widget_id.'-widget_logic']))
25
- { if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
26
- $wl_options[$widget_id]=$_POST[$widget_id.'-widget_logic'];
27
- update_option('widget_logic', $wl_options);
28
- }
29
- return $instance;
30
  }
31
 
32
- add_action( 'sidebar_admin_setup', 'widget_logic_expand_control');
33
 
34
- function widget_logic_expand_control()
35
- { global $wp_registered_widgets, $wp_registered_widget_controls;
36
 
37
- if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
38
 
39
- // if we're just updating the widgets, just read in the widget logic settings - makes this WP2.5+ only i think
 
 
 
 
40
  if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) )
41
  { foreach ( (array) $_POST['widget-id'] as $widget_number => $widget_id )
42
  if (isset($_POST[$widget_id.'-widget_logic']))
@@ -49,38 +45,65 @@ function widget_logic_expand_control()
49
  unset($wl_options[$key]);
50
  }
51
 
52
- foreach ( $wp_registered_widgets as $id => $widget )
53
- { if (!$wp_registered_widget_controls[$id])
54
- wp_register_widget_control($id,$widget['name'], 'widget_logic_empty_control');
55
-
56
- if (!array_key_exists(0,$wp_registered_widget_controls[$id]['params']) || is_array($wp_registered_widget_controls[$id]['params'][0]))
57
- $wp_registered_widget_controls[$id]['params'][0]['id_for_wl']=$id;
58
- else
59
- { // some older widgets put number in to params directly (which messes up the 'templates' in WP2.5)
60
- array_push($wp_registered_widget_controls[$id]['params'],$id);
61
- $wp_registered_widget_controls[$id]['height']+=40; // this is really a pre2.5 thing - discard?
62
- }
63
-
64
- // do the redirection
65
- $wp_registered_widget_controls[$id]['callback_wl_redirect']=$wp_registered_widget_controls[$id]['callback'];
66
- $wp_registered_widget_controls[$id]['callback']='widget_logic_extra_control';
67
- }
68
-
69
-
70
  // check the 'widget content' filter option
71
  if ( isset($_POST['widget_logic-options-submit']) )
72
  { $wl_options['widget_logic-options-filter']=$_POST['widget_logic-options-filter'];
73
  $wl_options['widget_logic-options-wp_reset_query']=$_POST['widget_logic-options-wp_reset_query'];
74
  }
 
 
 
 
75
  update_option('widget_logic', $wl_options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
 
78
 
79
- add_action( 'sidebar_admin_page', 'widget_logic_options_filter');
80
 
 
81
  function widget_logic_options_filter()
82
- {
83
- if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
84
  ?><div class="wrap">
85
  <form method="POST">
86
  <h2>Widget Logic options</h2>
@@ -99,76 +122,93 @@ function widget_logic_options_filter()
99
  }
100
 
101
 
102
- function widget_logic_empty_control() {}
103
 
104
- function widget_logic_extra_control()
105
- { global $wp_registered_widget_controls;
106
- $params=func_get_args();
 
 
 
 
 
 
 
107
 
108
- // find the widget id that we have sneaked into the params
109
- $id=(is_array($params[0]))?$params[0]['id_for_wl']:array_pop($params);
110
- $id_disp=$id;
111
 
112
- if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
113
-
114
- $callback=$wp_registered_widget_controls[$id]['callback_wl_redirect'];
115
- if (is_callable($callback))
116
- call_user_func_array($callback, $params); // go to the original control function
117
 
118
- $value = !empty( $wl_options[$id ] ) ? htmlspecialchars( stripslashes( $wl_options[$id ] ),ENT_QUOTES ) : '';
 
 
 
 
 
119
 
120
- // dealing with multiple widgets - get the number. if -1 this is the 'template' for the admin interface
121
- if (is_array($params[0]) && isset($params[0]['number'])) $number=$params[0]['number'];
122
- if ($number==-1) {$number="%i%"; $value="";}
123
- if (isset($number)) $id_disp=$wp_registered_widget_controls[$id]['id_base'].'-'.$number;
124
 
125
- // output our extra widget logic field
126
- echo "<p><label for='".$id_disp."-widget_logic'>Widget logic <input type='text' name='".$id_disp."-widget_logic' id='".$id_disp."-widget_logic' value='".$value."' /></label></p>";
127
 
128
- }
129
 
130
 
131
- // intercept registered widgets - redirect them and put each ID on the end of the params
132
- // perhaps there is a way to just intercept the ones that are used??
133
- add_action('wp_head', 'widget_logic_redirect_callback');
134
- function widget_logic_redirect_callback()
135
- { global $wp_registered_widgets;
136
- foreach ( $wp_registered_widgets as $id => $widget )
137
- { if ( empty( $wp_registered_widgets[$id]['callback_wl_redirect'] ) )
138
- { array_push($wp_registered_widgets[$id]['params'],$id);
139
- $wp_registered_widgets[$id]['callback_wl_redirect']=$wp_registered_widgets[$id]['callback'];
140
- $wp_registered_widgets[$id]['callback']='widget_logic_redirected_callback';
 
 
 
 
 
 
 
 
 
141
  }
142
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
 
145
  // the redirection comes here
146
  function widget_logic_redirected_callback()
147
  { global $wp_registered_widgets, $wp_reset_query_is_done;
148
 
149
- $params=func_get_args(); // get all the passed params
150
- $id=array_pop($params); // take off the widget ID
151
- $callback=$wp_registered_widgets[$id]['callback_wl_redirect']; // find the real callback
152
-
153
- $wl_options = get_option('widget_logic'); // do we want the widget?
154
- $wl_value = ( !empty( $wl_options[$id] ) ) ? stripslashes( $wl_options[$id] ) : "true";
155
- $wl_value = ( stristr( $wl_value, "return" ) ) ? $wl_value : "return (" . $wl_value . ");";
156
-
157
- // before we execute the condtional code, perhaps we want to wp_reset_query...
158
- if ( !empty( $wl_options['widget_logic-options-wp_reset_query'] ) && ( $wl_options['widget_logic-options-wp_reset_query'] == 'checked' ) && empty( $wp_reset_query_is_done ) )
159
- { wp_reset_query(); $wp_reset_query_is_done=true; }
160
-
161
- $wl_value=(eval($wl_value) && is_callable($callback));
162
- if ( $wl_value )
163
- { if ( !empty( $wl_options['widget_logic-options-filter'] ) && ( $wl_options['widget_logic-options-filter'] != 'checked' ) )
164
- call_user_func_array($callback, $params); // if so callback with original params!
165
- else
166
- { ob_start();
167
- call_user_func_array($callback, $params); // if so callback with original params!
168
- $widget_content = ob_get_contents();
169
- ob_end_clean();
170
- echo apply_filters( 'widget_content', $widget_content, $id);
171
- }
172
  }
173
  }
 
 
 
174
  ?>
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.50
8
  Author URI: http://freakytrigger.co.uk/author/alan/
9
  */
10
 
11
+ global $wl_options;
12
+ if((!$wl_options = get_option('widget_logic')) || !is_array($wl_options) ) $wl_options = array();
13
 
14
+ if (is_admin())
15
+ { add_action( 'sidebar_admin_setup', 'widget_logic_expand_control'); // save widget changes and add controls to each widget on the widget admin page
16
+ add_action( 'sidebar_admin_page', 'widget_logic_options_filter'); // add extra Widget Logic specific options on the widget admin page
17
+ add_filter( 'widget_update_callback', 'widget_logic_widget_update_callback', 10, 3); // save individual widget changes submitted by ajax method
18
+ add_filter( 'plugin_action_links', 'wl_charity', 10, 2); // add my justgiving page
 
 
19
  }
20
+ else
21
+ {
22
+ add_filter( 'sidebars_widgets', 'widget_logic_filter_sidebars_widgets', 10); // actually remove the widgets from the front end depending on widget logic provided
23
 
24
+ if ( isset($wl_options['widget_logic-options-filter']) && $wl_options['widget_logic-options-filter'] == 'checked' )
25
+ add_filter( 'dynamic_sidebar_params', 'widget_logic_widget_display_callback', 10); // redirect the widget callback so the output can be buffered and filtered
 
 
 
 
 
 
 
26
  }
27
 
 
28
 
 
 
29
 
 
30
 
31
+ // CALLED VIA 'sidebar_admin_setup' ACTION
32
+ function widget_logic_expand_control()
33
+ { global $wp_registered_widgets, $wp_registered_widget_controls, $wl_options;
34
+
35
+ // if we're updating the widgets, read in the widget logic settings (makes this WP2.5+ only?)
36
  if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) )
37
  { foreach ( (array) $_POST['widget-id'] as $widget_number => $widget_id )
38
  if (isset($_POST[$widget_id.'-widget_logic']))
45
  unset($wl_options[$key]);
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  // check the 'widget content' filter option
49
  if ( isset($_POST['widget_logic-options-submit']) )
50
  { $wl_options['widget_logic-options-filter']=$_POST['widget_logic-options-filter'];
51
  $wl_options['widget_logic-options-wp_reset_query']=$_POST['widget_logic-options-wp_reset_query'];
52
  }
53
+
54
+ // before updating widget logic options (which gets EVALd)
55
+ // we could test current_user_can('edit_theme_options')
56
+ // although we shouldn't be able to get here without that capability anyway?
57
  update_option('widget_logic', $wl_options);
58
+
59
+ // intercept the widget controls to add in our extra text field
60
+ // pop the widget id on the params array (as it's not in the main params so not provided to the callback)
61
+ foreach ( $wp_registered_widgets as $id => $widget )
62
+ { // controll-less widgets need an empty function so the callback function is called.
63
+ if (!$wp_registered_widget_controls[$id])
64
+ wp_register_widget_control($id,$widget['name'], 'widget_logic_empty_control');
65
+ $wp_registered_widget_controls[$id]['callback_wl_redirect']=$wp_registered_widget_controls[$id]['callback'];
66
+ $wp_registered_widget_controls[$id]['callback']='widget_logic_extra_control';
67
+ array_push($wp_registered_widget_controls[$id]['params'],$id);
68
+ }
69
+ }
70
+
71
+
72
+
73
+ // added to widget functionality in 'widget_logic_expand_control' (above)
74
+ function widget_logic_empty_control() {}
75
+
76
+
77
+
78
+ // added to widget functionality in 'widget_logic_expand_control' (above)
79
+ function widget_logic_extra_control()
80
+ { global $wp_registered_widget_controls, $wl_options;
81
+
82
+ $params=func_get_args();
83
+ $id=array_pop($params);
84
+
85
+ // go to the original control function
86
+ $callback=$wp_registered_widget_controls[$id]['callback_wl_redirect'];
87
+ if (is_callable($callback))
88
+ call_user_func_array($callback, $params);
89
+
90
+ $value = !empty( $wl_options[$id ] ) ? htmlspecialchars( stripslashes( $wl_options[$id ] ),ENT_QUOTES ) : '';
91
+
92
+ // dealing with multiple widgets - get the number. if -1 this is the 'template' for the admin interface
93
+ $number=$params[0]['number'];
94
+ if ($number==-1) {$number="%i%"; $value="";}
95
+ $id_disp=$id;
96
+ if (isset($number)) $id_disp=$wp_registered_widget_controls[$id]['id_base'].'-'.$number;
97
+
98
+ // output our extra widget logic field
99
+ echo "<p><label for='".$id_disp."-widget_logic'>Widget logic <input type='text' name='".$id_disp."-widget_logic' id='".$id_disp."-widget_logic' value='".$value."' /></label></p>";
100
  }
101
 
102
 
 
103
 
104
+ // CALLED VIA 'sidebar_admin_page' ACTION
105
  function widget_logic_options_filter()
106
+ { global $wp_registered_widget_controls, $wl_options;
 
107
  ?><div class="wrap">
108
  <form method="POST">
109
  <h2>Widget Logic options</h2>
122
  }
123
 
124
 
 
125
 
126
+ // CALLED VIA 'widget_update_callback' ACTION (ajax update of a widget)
127
+ function widget_logic_widget_update_callback($instance, $new_instance, $this_widget)
128
+ { global $wl_options;
129
+ $widget_id=$this_widget->id;
130
+ if ( isset($_POST[$widget_id.'-widget_logic']))
131
+ { $wl_options[$widget_id]=$_POST[$widget_id.'-widget_logic'];
132
+ update_option('widget_logic', $wl_options);
133
+ }
134
+ return $instance;
135
+ }
136
 
 
 
 
137
 
 
 
 
 
 
138
 
139
+ // CALLED ON 'plugin_action_links' ACTION
140
+ function wl_charity($links, $file)
141
+ { if ($file == plugin_basename(__FILE__))
142
+ array_push($links, '<a href="http://www.justgiving.com/widgetlogic_cancerresearchuk/">Charity Donation</a>');
143
+ return $links;
144
+ }
145
 
 
 
 
 
146
 
 
 
147
 
148
+ // FRONT END FUNCTIONS...
149
 
150
 
151
+
152
+ // CALLED ON 'sidebars_widgets' FILTER
153
+ function widget_logic_filter_sidebars_widgets($sidebars_widgets)
154
+ { global $wp_reset_query_is_done, $wl_options;
155
+
156
+ // reset any database queries done now that we're about to make decisions based on the context given in the WP query for the page
157
+ // add && empty( $wp_reset_query_is_done ) to the next line to only exec the reset once per page
158
+ if ( !empty( $wl_options['widget_logic-options-wp_reset_query'] ) && ( $wl_options['widget_logic-options-wp_reset_query'] == 'checked' ))
159
+ { wp_reset_query(); $wp_reset_query_is_done=true; }
160
+
161
+ // loop through every widget in every sidebar (barring 'wp_inactive_widgets') checking WL for each one
162
+ foreach($sidebars_widgets as $widget_area => $widget_list)
163
+ { if ($widget_area=='wp_inactive_widgets') next;
164
+ foreach($widget_list as $pos => $widget_id)
165
+ {
166
+ $wl_value=(!empty($wl_options[$widget_id]))? stripslashes($wl_options[$widget_id]) : "true";
167
+ $wl_value =(stristr($wl_value,"return"))? $wl_value: "return (" . $wl_value . ");";
168
+ if (!eval($wl_value))
169
+ unset($sidebars_widgets[$widget_area][$pos]);
170
  }
171
  }
172
+ return $sidebars_widgets;
173
+ }
174
+
175
+
176
+
177
+ // If 'widget_logic-options-filter' is selected the widget_content filter is implemented...
178
+
179
+
180
+
181
+ // CALLED ON 'dynamic_sidebar_params' FILTER - this is called during 'dynamic_sidebar' just before each callback is run
182
+ // swap out the original call back and replace it with our own
183
+ function widget_logic_widget_display_callback($params)
184
+ { global $wp_registered_widgets;
185
+ $id=$params[0]['widget_id'];
186
+ $wp_registered_widgets[$id]['callback_wl_redirect']=$wp_registered_widgets[$id]['callback'];
187
+ $wp_registered_widgets[$id]['callback']='widget_logic_redirected_callback';
188
+ return $params;
189
  }
190
 
191
+
192
  // the redirection comes here
193
  function widget_logic_redirected_callback()
194
  { global $wp_registered_widgets, $wp_reset_query_is_done;
195
 
196
+ // replace the original callback data
197
+ $params=func_get_args();
198
+ $id=$params[0]['widget_id'];
199
+ $callback=$wp_registered_widgets[$id]['callback_wl_redirect'];
200
+ $wp_registered_widgets[$id]['callback']=$callback;
201
+
202
+ // run the callback but capture and filter the output using PHP output buffering
203
+ if ( is_callable($callback) )
204
+ { ob_start();
205
+ call_user_func_array($callback, $params);
206
+ $widget_content = ob_get_contents();
207
+ ob_end_clean();
208
+ echo apply_filters( 'widget_content', $widget_content, $id);
 
 
 
 
 
 
 
 
 
 
209
  }
210
  }
211
+
212
+
213
+
214
  ?>