Version Description
Bug fix: check for active sidebars only after $paged has been set.
Download this release
Release Info
Developer | kasparsd |
Plugin | Widget Context |
Version | 0.7 |
Comparing to | |
See all releases |
Code changes from version 0.6 to 0.7
- readme.txt +5 -1
- widget-context.php +20 -9
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kaspa
|
|
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.
|
8 |
|
9 |
Show widgets in context - only on certain posts, front page, category or tag pages etc.
|
10 |
|
@@ -23,6 +23,7 @@ For news and updates regarding this plugin, check http://konstruktors.com/blog/
|
|
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.
|
@@ -32,6 +33,9 @@ For news and updates regarding this plugin, check http://konstruktors.com/blog/
|
|
32 |
|
33 |
== Upgrade Notice ==
|
34 |
|
|
|
|
|
|
|
35 |
= 0.6 =
|
36 |
Performance improvements - don't check if sidebar has any widgets on every widget load.
|
37 |
|
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.7
|
8 |
|
9 |
Show widgets in context - only on certain posts, front page, category or tag pages etc.
|
10 |
|
23 |
|
24 |
== Changelog ==
|
25 |
|
26 |
+
* **0.7** - Bug fix: check for active sidebars only after $paged has been set.
|
27 |
* **0.6** - Don't check for used sidebars on each widget load. Allow absolute URLs in the URL check.
|
28 |
* **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.
|
29 |
* **0.4.5** - Widget output callback couldn't determine the widget_id.
|
33 |
|
34 |
== Upgrade Notice ==
|
35 |
|
36 |
+
= 0.7 =
|
37 |
+
Bug fix: check for active sidebars only after $paged has been set.
|
38 |
+
|
39 |
= 0.6 =
|
40 |
Performance improvements - don't check if sidebar has any widgets on every widget load.
|
41 |
|
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 |
|
@@ -28,12 +28,12 @@ For changelog see readme.txt
|
|
28 |
// Go!
|
29 |
new widget_context();
|
30 |
|
31 |
-
|
32 |
class widget_context {
|
33 |
|
34 |
var $options_name = 'widget_logic_options'; // Widget context settings (visibility, etc)
|
35 |
var $context_options = array();
|
36 |
var $words_on_page = 0;
|
|
|
37 |
|
38 |
|
39 |
function widget_context() {
|
@@ -47,7 +47,7 @@ class widget_context {
|
|
47 |
// add_action('admin_menu', array($this, 'addAdminOptions'));
|
48 |
add_action('admin_enqueue_scripts', array($this, 'adminCSS'));
|
49 |
// Save widget context settings, when in admin area
|
50 |
-
add_filter('sidebars_widgets', array($this, 'filter_widgets'));
|
51 |
// Check the number of words on page
|
52 |
add_action('wp_print_scripts', array($this, 'count_words_on_page'), 750);
|
53 |
}
|
@@ -64,24 +64,35 @@ class widget_context {
|
|
64 |
|
65 |
|
66 |
function filter_widgets($sidebars_widgets) {
|
|
|
|
|
67 |
if (isset($_POST['wl']) && !empty($_POST['wl']) && is_admin()) {
|
68 |
$this->save_widget_context();
|
69 |
unset($_POST['wl']);
|
70 |
-
|
71 |
-
} elseif (!is_admin() &&
|
72 |
-
|
73 |
-
|
|
|
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;
|
3 |
Plugin Name: Widget Context
|
4 |
Plugin URI: http://konstruktors.com/blog/
|
5 |
Description: Display widgets in context.
|
6 |
+
Version: 0.7
|
7 |
Author: Kaspars Dambis
|
8 |
Author URI: http://konstruktors.com/blog/
|
9 |
|
28 |
// Go!
|
29 |
new widget_context();
|
30 |
|
|
|
31 |
class widget_context {
|
32 |
|
33 |
var $options_name = 'widget_logic_options'; // Widget context settings (visibility, etc)
|
34 |
var $context_options = array();
|
35 |
var $words_on_page = 0;
|
36 |
+
var $did_filter_sidebars = false;
|
37 |
|
38 |
|
39 |
function widget_context() {
|
47 |
// add_action('admin_menu', array($this, 'addAdminOptions'));
|
48 |
add_action('admin_enqueue_scripts', array($this, 'adminCSS'));
|
49 |
// Save widget context settings, when in admin area
|
50 |
+
add_filter('sidebars_widgets', array($this, 'filter_widgets'), 50);
|
51 |
// Check the number of words on page
|
52 |
add_action('wp_print_scripts', array($this, 'count_words_on_page'), 750);
|
53 |
}
|
64 |
|
65 |
|
66 |
function filter_widgets($sidebars_widgets) {
|
67 |
+
global $_wp_sidebars_widgets, $paged;
|
68 |
+
|
69 |
if (isset($_POST['wl']) && !empty($_POST['wl']) && is_admin()) {
|
70 |
$this->save_widget_context();
|
71 |
unset($_POST['wl']);
|
72 |
+
|
73 |
+
} elseif (!is_admin() && isset($paged)) {
|
74 |
+
|
75 |
+
// Get widget context options and check visibility settings
|
76 |
+
if (empty($this->context_options))
|
77 |
$this->context_options = get_option($this->options_name);
|
78 |
+
|
79 |
+
// If we have done this before, return the truth
|
80 |
+
if ($this->did_filter_sidebars)
|
81 |
+
return $sidebars_widgets; //return $this->active_sidebars;
|
82 |
+
|
83 |
foreach ($sidebars_widgets as $sidebar_id => $widgets) {
|
84 |
// Check if widget will be shown
|
85 |
if ($sidebar_id != 'wp_inactive_widgets' && !empty($widgets)) {
|
86 |
foreach ($widgets as $widget_no => $widget_id) {
|
87 |
+
if (!$this->check_widget_visibility($this->context_options[$widget_id])) {
|
88 |
unset($sidebars_widgets[$sidebar_id][$widget_no]);
|
89 |
+
unset($_wp_sidebars_widgets[$sidebar_id][$widget_no]);
|
90 |
+
}
|
91 |
}
|
92 |
}
|
93 |
}
|
94 |
+
|
95 |
+
$this->did_filter_sidebars = true;
|
96 |
}
|
97 |
|
98 |
return $sidebars_widgets;
|