Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for is_active_sidebar & is_dynamic_sidebar issues #4

Merged
merged 1 commit into from

3 participants

@emhr

Hiding by filtering widget_display_callback makes is_active_sidebar
return TRUE on sidebars with only one widget which happen to be
contextually hidden.

Unsetting the contextually hidden widget from the sidebar on the front
end restores the desired behavior

Props to Widget Logic.

@emhr emhr Unset widget from sidebar instead of hiding from display
Hiding by filtering widget_display_callback makes is_active_sidebar
return TRUE on  sidewars with only one widget which happens to be
contextually hidden.

Usetting the contextually hidden widget from the sidebar on the front
end restores the desired behavior

Props to Widget Logic.
78e6a80
@TristanRineer

Excellent! The solution works perfectly.

Hopefully it will be merged into the official release soon, I have a lot of clients who depend on Widget Context; a majority of them do their own updates, and without this fix, their sites will all have broken layouts.

@kasparsd kasparsd merged commit cb761dd into kasparsd:master
@saas786 saas786 referenced this pull request
Closed

is_dynamic_sidebar broke #3

@om4james om4james referenced this pull request from a commit
@om4james om4james Changelog update for #4 0543a48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2013
  1. @emhr

    Unset widget from sidebar instead of hiding from display

    emhr authored
    Hiding by filtering widget_display_callback makes is_active_sidebar
    return TRUE on  sidewars with only one widget which happens to be
    contextually hidden.
    
    Usetting the contextually hidden widget from the sidebar on the front
    end restores the desired behavior
    
    Props to Widget Logic.
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 7 deletions.
  1. +14 −7 widget-context.php
View
21 widget-context.php
@@ -40,8 +40,9 @@ function widget_context() {
add_action( 'init', array( $this, 'load_plugin_settings' ) );
// Amend widget controls with Widget Context controls
add_action( 'sidebar_admin_setup', array( $this, 'attach_widget_context_controls' ) );
- // Hide the widget if necessary
- add_filter( 'widget_display_callback', array( $this, 'maybe_hide_widget' ), 10, 3 );
+ // Remove widget from widetized area (sidebar) on front end only
+ if ( !is_admin() )
+ add_filter( 'sidebars_widgets', array( $this, 'maybe_unset_widget' ), 10 );
// Add admin menu for config
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
// Save widget context settings, when in admin area
@@ -92,11 +93,17 @@ function attach_widget_context_controls() {
}
- function maybe_hide_widget( $instance, $widget_object, $args ) {
- if ( ! $this->check_widget_visibility( $args['widget_id'] ) )
- return false;
-
- return $instance;
+ function maybe_unset_widget( $sidebars_widgets ) {
+ foreach( $sidebars_widgets as $widget_area => $widget_list ) {
+ if ( $widget_area == 'wp_inactive_widgets' || empty( $widget_list ))
+ continue;
+
+ foreach( $widget_list as $pos => $widget_id ) {
+ if ( ! $this->check_widget_visibility( $widget_id ) )
+ unset( $sidebars_widgets[$widget_area][$pos] );
+ }
+ }
+ return $sidebars_widgets;
}
Something went wrong with that request. Please try again.