Version Description
Performance improvements - don't check if sidebar has any widgets on every widget load.
=
Download this release
Release Info
Developer | kasparsd |
Plugin | Widget Context |
Version | 0.6 |
Comparing to | |
See all releases |
Code changes from version 0.4.5 to 0.6
- admin-style.css +1 -0
- readme.txt +24 -8
- screenshot-1.png +0 -0
- widget-context.php +47 -17
admin-style.css
CHANGED
@@ -13,6 +13,7 @@
|
|
13 |
.wl-column-2-2 { float:right; width:52%; }
|
14 |
.wl-columns label { display:block; }
|
15 |
|
|
|
16 |
.wl-word-count .wl-check_wordcount_type select { font-size:1.1em; padding:0; }
|
17 |
.wl-word-count label { display:inline; }
|
18 |
.wl-word-count .wl-word_count input { display:inline; width:3em; padding:0; }
|
13 |
.wl-column-2-2 { float:right; width:52%; }
|
14 |
.wl-columns label { display:block; }
|
15 |
|
16 |
+
.wl-word-count { clear:both; }
|
17 |
.wl-word-count .wl-check_wordcount_type select { font-size:1.1em; padding:0; }
|
18 |
.wl-word-count label { display:inline; }
|
19 |
.wl-word-count .wl-word_count input { display:inline; width:3em; padding:0; }
|
readme.txt
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
=== Widget Context ===
|
2 |
Contributors: kasparsd
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kaspars%40konstruktors%2ecom&item_name=Widget%20Context%20Plugin%20for%20WordPress&no_shipping=1&no_note=1&tax=0¤cy_code=EUR&lc=LV&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
-
Tags: widget, widget context, context, logic, widget logic
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to: 2.
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
-
Show widgets in context
|
10 |
|
11 |
== Description ==
|
12 |
|
@@ -14,12 +14,28 @@ Widget Context allows you to specify widget visibility settings.
|
|
14 |
|
15 |
For news and updates regarding this plugin, check http://konstruktors.com/blog/
|
16 |
|
|
|
17 |
== Installation ==
|
18 |
|
19 |
-
Install the plugin through **Add New Plugin** feature in your WordPress dashboard.
|
|
|
|
|
20 |
|
21 |
== Changelog ==
|
22 |
|
23 |
-
* **0.
|
24 |
-
* **0.
|
25 |
-
* **0.4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
=== Widget Context ===
|
2 |
Contributors: kasparsd
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kaspars%40konstruktors%2ecom&item_name=Widget%20Context%20Plugin%20for%20WordPress&no_shipping=1&no_note=1&tax=0¤cy_code=EUR&lc=LV&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
+
Tags: widget, widget context, context, logic, widget logic, cms
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 2.9
|
7 |
+
Stable tag: 0.6
|
8 |
|
9 |
+
Show widgets in context - only on certain posts, front page, category or tag pages etc.
|
10 |
|
11 |
== Description ==
|
12 |
|
14 |
|
15 |
For news and updates regarding this plugin, check http://konstruktors.com/blog/
|
16 |
|
17 |
+
|
18 |
== Installation ==
|
19 |
|
20 |
+
* Install the plugin through **Add New Plugin** feature in your WordPress dashboard -- search for Widget Context.
|
21 |
+
* Widget Context settings will appear automatically under each widget in Design > Widgets.
|
22 |
+
|
23 |
|
24 |
== Changelog ==
|
25 |
|
26 |
+
* **0.6** - Don't check for used sidebars on each widget load. Allow absolute URLs in the URL check.
|
27 |
+
* **0.5** - Added distinction between is_front_page() and is_home(). Remove widgets from wp_get_sidebars_widgets() if they are not being displayed -- this way you can check if a particular sidebar is empty.
|
28 |
+
* **0.4.5** - Widget output callback couldn't determine the widget_id.
|
29 |
+
* **0.4.4** - Fixed widget control parameter transfer for widgets that don't use the new widget api.
|
30 |
+
* **0.4.2** - Initial release on Plugin repository.
|
31 |
+
|
32 |
+
|
33 |
+
== Upgrade Notice ==
|
34 |
+
|
35 |
+
= 0.6 =
|
36 |
+
Performance improvements - don't check if sidebar has any widgets on every widget load.
|
37 |
+
|
38 |
+
|
39 |
+
== Screenshots ==
|
40 |
+
|
41 |
+
1. Widget Context settings added at the end of every widget settings
|
screenshot-1.png
ADDED
Binary file
|
widget-context.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Widget Context
|
4 |
Plugin URI: http://konstruktors.com/blog/
|
5 |
Description: Display widgets in context.
|
6 |
-
Version: 0.
|
7 |
Author: Kaspars Dambis
|
8 |
Author URI: http://konstruktors.com/blog/
|
9 |
|
@@ -67,6 +67,21 @@ class widget_context {
|
|
67 |
if (isset($_POST['wl']) && !empty($_POST['wl']) && is_admin()) {
|
68 |
$this->save_widget_context();
|
69 |
unset($_POST['wl']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
return $sidebars_widgets;
|
@@ -128,14 +143,24 @@ class widget_context {
|
|
128 |
function replace_widget_output_callback() {
|
129 |
global $wp_registered_widgets;
|
130 |
|
|
|
|
|
|
|
|
|
131 |
foreach ($wp_registered_widgets as $widget_id => $widget_data) {
|
132 |
-
//if
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
// Save the original widget id
|
134 |
$wp_registered_widgets[$widget_id]['params'][]['widget_id'] = $widget_id;
|
135 |
// Store original widget callbacks
|
136 |
$wp_registered_widgets[$widget_id]['callback_original_wc'] = $wp_registered_widgets[$widget_id]['callback'];
|
137 |
$wp_registered_widgets[$widget_id]['callback'] = array($this, 'replace_widget_output');
|
138 |
-
|
139 |
}
|
140 |
}
|
141 |
|
@@ -152,13 +177,7 @@ class widget_context {
|
|
152 |
|
153 |
$widget_callback = $wp_registered_widgets[$widget_id]['callback_original_wc'];
|
154 |
|
155 |
-
|
156 |
-
if (empty($this->context_options))
|
157 |
-
$this->context_options = get_option($this->options_name);
|
158 |
-
|
159 |
-
$do_show = $this->check_widget_visibility($this->context_options[$widget_id]);
|
160 |
-
|
161 |
-
if (is_callable($widget_callback) && $do_show) {
|
162 |
call_user_func_array($widget_callback, $all_params);
|
163 |
return true;
|
164 |
} elseif (!is_callable($widget_callback)) {
|
@@ -219,11 +238,20 @@ class widget_context {
|
|
219 |
// add trailing slash if missing
|
220 |
if (substr($home_url, -1) !== '/')
|
221 |
$home_url = $home_url . '/';
|
222 |
-
|
223 |
-
// if
|
224 |
-
|
|
|
225 |
$path = str_replace($home_url, '', $path);
|
226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
if (!isset($regexps[$patterns])) {
|
228 |
$regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<home\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote($home_url, '/') .'\2'), preg_quote($patterns, '/')) .')$/';
|
229 |
}
|
@@ -290,8 +318,9 @@ class widget_context {
|
|
290 |
// Check by tag settings
|
291 |
if (!empty($vis_settings['location'])) {
|
292 |
$currently = array();
|
293 |
-
|
294 |
-
if (
|
|
|
295 |
if (is_page() && !is_attachment()) $currently['is_page'] = true;
|
296 |
if (is_single() && !is_attachment()) $currently['is_single'] = true;
|
297 |
if (is_archive()) $currently['is_archive'] = true;
|
@@ -381,7 +410,8 @@ class widget_context {
|
|
381 |
|
382 |
. '<div class="wl-columns">'
|
383 |
. '<div class="wl-column-2-1"><p>'
|
384 |
-
. $this->make_simple_checkbox($options, $wid, $group, 'is_front_page', __('
|
|
|
385 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_single', __('Single Post'))
|
386 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_page', __('Single Page'))
|
387 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_attachment', __('Attachment'))
|
@@ -404,7 +434,7 @@ class widget_context {
|
|
404 |
. '</div>'
|
405 |
|
406 |
. '<div class="wl-options">'
|
407 |
-
. $this->make_simple_textarea($options, $wid, 'url', 'urls', __('
|
408 |
. '</div>'
|
409 |
|
410 |
. '</div>'
|
3 |
Plugin Name: Widget Context
|
4 |
Plugin URI: http://konstruktors.com/blog/
|
5 |
Description: Display widgets in context.
|
6 |
+
Version: 0.6
|
7 |
Author: Kaspars Dambis
|
8 |
Author URI: http://konstruktors.com/blog/
|
9 |
|
67 |
if (isset($_POST['wl']) && !empty($_POST['wl']) && is_admin()) {
|
68 |
$this->save_widget_context();
|
69 |
unset($_POST['wl']);
|
70 |
+
|
71 |
+
} elseif (!is_admin() && empty($this->context_options)) {
|
72 |
+
// This way we can check if a particular sidebar is empty
|
73 |
+
if (empty($this->context_options)) // Get widget context options and check visibility settings
|
74 |
+
$this->context_options = get_option($this->options_name);
|
75 |
+
|
76 |
+
foreach ($sidebars_widgets as $sidebar_id => $widgets) {
|
77 |
+
// Check if widget will be shown
|
78 |
+
if ($sidebar_id != 'wp_inactive_widgets' && !empty($widgets)) {
|
79 |
+
foreach ($widgets as $widget_no => $widget_id) {
|
80 |
+
if (!$this->check_widget_visibility($this->context_options[$widget_id]))
|
81 |
+
unset($sidebars_widgets[$sidebar_id][$widget_no]);
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
}
|
86 |
|
87 |
return $sidebars_widgets;
|
143 |
function replace_widget_output_callback() {
|
144 |
global $wp_registered_widgets;
|
145 |
|
146 |
+
// Get widget logic options and check visibility settings
|
147 |
+
if (empty($this->context_options))
|
148 |
+
$this->context_options = get_option($this->options_name);
|
149 |
+
|
150 |
foreach ($wp_registered_widgets as $widget_id => $widget_data) {
|
151 |
+
// Check if widget will be shown
|
152 |
+
$do_show = $this->check_widget_visibility($this->context_options[$widget_id]);
|
153 |
+
|
154 |
+
if (!$do_show) { // If not shown, remove it temporeraly from the list of existing widgets
|
155 |
+
unregister_sidebar_widget($widget_id);
|
156 |
+
} else {
|
157 |
+
//if (!$wp_registered_widgets[$widget_id]['params'][0]['widget_id']) {
|
158 |
// Save the original widget id
|
159 |
$wp_registered_widgets[$widget_id]['params'][]['widget_id'] = $widget_id;
|
160 |
// Store original widget callbacks
|
161 |
$wp_registered_widgets[$widget_id]['callback_original_wc'] = $wp_registered_widgets[$widget_id]['callback'];
|
162 |
$wp_registered_widgets[$widget_id]['callback'] = array($this, 'replace_widget_output');
|
163 |
+
}
|
164 |
}
|
165 |
}
|
166 |
|
177 |
|
178 |
$widget_callback = $wp_registered_widgets[$widget_id]['callback_original_wc'];
|
179 |
|
180 |
+
if (is_callable($widget_callback)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
call_user_func_array($widget_callback, $all_params);
|
182 |
return true;
|
183 |
} elseif (!is_callable($widget_callback)) {
|
238 |
// add trailing slash if missing
|
239 |
if (substr($home_url, -1) !== '/')
|
240 |
$home_url = $home_url . '/';
|
241 |
+
|
242 |
+
// Check if user has specified the absolute url
|
243 |
+
// else strip home url and check only REQUEST_URI part
|
244 |
+
if ($path !== $home_url && !strstr($patterns, $_SERVER['SERVER_NAME']))
|
245 |
$path = str_replace($home_url, '', $path);
|
246 |
|
247 |
+
// Remove http:// from the url user has specified
|
248 |
+
if (strstr($patterns, 'http://'))
|
249 |
+
$patterns = str_replace('http://', '', $patterns);
|
250 |
+
|
251 |
+
// Remove http:// from the current url
|
252 |
+
if (strstr($path, 'http://'))
|
253 |
+
$path = str_replace('http://', '', $path);
|
254 |
+
|
255 |
if (!isset($regexps[$patterns])) {
|
256 |
$regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<home\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote($home_url, '/') .'\2'), preg_quote($patterns, '/')) .')$/';
|
257 |
}
|
318 |
// Check by tag settings
|
319 |
if (!empty($vis_settings['location'])) {
|
320 |
$currently = array();
|
321 |
+
|
322 |
+
if (is_front_page() && $paged < 2) $currently['is_front_page'] = true;
|
323 |
+
if (is_home() && $paged < 2) $currently['is_home'] = true;
|
324 |
if (is_page() && !is_attachment()) $currently['is_page'] = true;
|
325 |
if (is_single() && !is_attachment()) $currently['is_single'] = true;
|
326 |
if (is_archive()) $currently['is_archive'] = true;
|
410 |
|
411 |
. '<div class="wl-columns">'
|
412 |
. '<div class="wl-column-2-1"><p>'
|
413 |
+
. $this->make_simple_checkbox($options, $wid, $group, 'is_front_page', __('Front Page'))
|
414 |
+
. $this->make_simple_checkbox($options, $wid, $group, 'is_home', __('Blog Index'))
|
415 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_single', __('Single Post'))
|
416 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_page', __('Single Page'))
|
417 |
. $this->make_simple_checkbox($options, $wid, $group, 'is_attachment', __('Attachment'))
|
434 |
. '</div>'
|
435 |
|
436 |
. '<div class="wl-options">'
|
437 |
+
. $this->make_simple_textarea($options, $wid, 'url', 'urls', __('or target by URL'), __('Enter one location fragment per line. Use <strong>*</strong> character as a wildcard. Use <strong><code><home></code></strong> to select front page. Examples: <strong><code>category/peace/*</code></strong> to target all <em>peace</em> category posts; <strong><code>2012/*</code></strong> to target articles written in year 2012.'))
|
438 |
. '</div>'
|
439 |
|
440 |
. '</div>'
|