WordPress.org

Ready to get started?Download WordPress

Forums

Widget Logic
is_active_sidebar() doesn't work (17 posts)

  1. Vasya Pupkin
    Member
    Posted 3 years ago #

    When I hide all widgets in my sidebar, the function is_active_sidebar() returns "true" instead of "false". Is it possible to deactivate sidebar with no visible widgets?

    http://wordpress.org/extend/plugins/widget-logic/

  2. Vasya Pupkin
    Member
    Posted 3 years ago #

    I've rewritten the function widget_logic_redirect_callback()and removed widget_logic_redirected_callback(). Now it works as I want.

    function widget_logic_redirect_callback(){
      global $_wp_sidebars_widgets;
      $wl_options = get_option('widget_logic');
      $sidebars_widgets = get_option('sidebars_widgets');
      foreach ($sidebars_widgets as $id => $widgets) {
        if ($id != 'wp_inactive_widgets' && !empty($widgets)) {
          foreach ($widgets as $widget => $widget_id) {
            $wl_value=($wl_options[$widget_id])?stripslashes($wl_options[$widget_id]):"true";
            $wl_value=(stristr($wl_value, "return"))?$wl_value:"return (".$wl_value.");";
            if(!eval($wl_value)){
              unset($sidebars_widgets[$id][$widget]);
              unset($_wp_sidebars_widgets[$id][$widget]);
            }
          }
        }
      }
    }
  3. alanft
    Member
    Plugin Author

    Posted 3 years ago #

    * speechless *

    well almost.

    i've sat on my code for far too long (since WP2.1??) happy that it did the job. But you may have hit on a much simpler approach. not only simpler, but less prone to some of the problems caused by themes that play games with bespoke queries that mess up the conditional tags.

    I'll do some testing and if it works out and you have no objection I'll consider incorporating that approach (and a variation on the code above) in the next beta/release.

    (though it would mean rethinking how to do the widget_content filter)

  4. Vasya Pupkin
    Member
    Posted 3 years ago #

    It will be good if you take this code to your next release.
    I've seen how it is done in 'Widget context' plugin, but that plugin less flexible and takes more resources.

    For less resources consumption it will be good to divide plugin into 'admin' and 'front-end' parts like this:

    if (is_admin())
      include_once 'wl-admin.php';
    else
      include_once 'wl-frontend.php';}

    PS: The string 'unset($sidebars_widgets[$id][$widget]);' in the code above is redundant.

  5. Johan van der Wijk
    Member
    Posted 3 years ago #

    This is the fix that I have been looking for! Unfortunately I get an error after editing the plugin code:

    Warning: Invalid argument supplied for foreach() in /home/.../public_html/wp-content/plugins/widget-logic/widget_logic.php on line 140

    This is the line that causes the error:

    foreach ($widgets as $widget => $widget_id) {

    How can I fix this?

  6. aap411vm
    Member
    Posted 3 years ago #

    Got the same message. Would love to hear the solutions.

  7. Vasya Pupkin
    Member
    Posted 3 years ago #

    Sorry, but I cann't reproduce this error.
    My WP 3.0.1 and fixed Widget Logic 0.47 works fine.

  8. Johan van der Wijk
    Member
    Posted 3 years ago #

    I am using WP 3.1 but it might be that I made an error when changing the plugin with code.

    I would therefore really appreciate it if you therefore could upload the complete version of your modified plugin.

    Thanks!

  9. Vasya Pupkin
    Member
    Posted 3 years ago #

    This is the full code of fixed widget_logic.php:
    pastebin.me/002f3ec3145f4e1896a9cf79e72aebb2

  10. Johan van der Wijk
    Member
    Posted 3 years ago #

    Thanks Vasya! The code you uploaded works!

  11. deadhippo
    Member
    Posted 2 years ago #

    Awesome. Thanks!

  12. deadhippo
    Member
    Posted 2 years ago #

    I have found that updating this breaks the layout again though.

  13. deadhippo
    Member
    Posted 2 years ago #

    Updating to 0.48 that is. I fixed the issue by updating the version number on this code. Thanks again.

  14. Johan van der Wijk
    Member
    Posted 2 years ago #

    It is a pitty that the author of this plugin still has not implemented this solution. In the plugin code there even is a comment about the issue:

    // intercept  registered widgets - redirect them and put each ID on the end of the params
    // perhaps there is a way to just intercept the ones that are used??

    So yes, there is a way to do this :)

  15. deadhippo
    Member
    Posted 2 years ago #

    Yes, it is a pity. I think the best solution is for you to release your version while giving credit to this author and then everyone should be happy.

  16. alanft
    Member
    Plugin Author

    Posted 2 years ago #

    I am a lazy lazy coder. also very conservative. If I get time to update I'll look at a beta that includes this alternative approach and see what sort of reaction it gets - I'm just wary of breaking lots of sites, to the point where I'd consider having *both* approaches in and a setting to toggle between them to maximise compatibility.

    as you can see I'm basically making excuses to do nothing. sorry. never say never though. i'll take a look at that pastbin code - and again thanks to the original contributor and everyone else who's chipped in.

  17. Bryan Hoffman
    Member
    Posted 2 years ago #

    Vasya's pastebin code worked for me as well. I edited the version number to .48 to keep auto update from barking.

    Thanks Vasya!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic