0

I'm trying to develop a wordpress theme with a hero slider, I use some 3rd party slider widget inserted to the hero widget area I've defined as sidebar-hero in my functions.php file.

I'm using this code to display the hero slider:

<?php if(is_active_sidebar("sidebar-hero")) : ?>
    <?php dynamic_sidebar("sidebar-hero");?>
    <script type="text/javascript">document.body.classList.add("hero-widget-enabled");</script>
<?php else: ?>
<div class="carousel-page-container container">
    <div class="header-filter" style='background-image: url(/wp-content/themes/sometheme/assets/images/demo/back.png)'>
        <div class="header-filter-gradient"></div>
        </div>
    </div>
</div>
<?php endif;?>

Now the problem is, I add the custom slider to the sidebar-hero widget area, it shows the slider. I remove the slider from the widgets, it shows the default image. But when I disable the slider from the extensions page without removing it from the widget area, it still tries to show the dynamic sidebar.

The is_active_sidebar() method returns true even if there are any widgets displayed in the widget settings page on the sidebar-hero widget area.

Do you have any solutions for this issue? Is it a wordpress bug, or am I doing something wrong?

Update

wp_get_sidebars_widgets() shows this output (which smartslider3-2 should not be included because it's plugin is disabled):

array(6) {
  ["wp_inactive_widgets"]=>
  array(11) {
    [0]=>
    string(10) "archives-2"
    [1]=>
    string(10) "archives-4"
    [2]=>
    string(6) "meta-2"
    [3]=>
    string(8) "search-2"
    [4]=>
    string(8) "search-4"
    [5]=>
    string(6) "text-2"
    [6]=>
    string(12) "categories-2"
    [7]=>
    string(14) "recent-posts-2"
    [8]=>
    string(17) "recent-comments-2"
    [9]=>
    string(6) "text-3"
    [10]=>
    string(11) "tag_cloud-2"
  }
  ["sidebar-primary"]=>
  array(3) {
    [0]=>
    string(12) "categories-3"
    [1]=>
    string(11) "tag_cloud-1"
    [2]=>
    string(10) "calendar-1"
  }
  ["sidebar-footer-1"]=>
  array(1) {
    [0]=>
    string(14) "recent-posts-3"
  }
  ["sidebar-footer-2"]=>
  array(1) {
    [0]=>
    string(7) "pages-2"
  }
  ["sidebar-footer-3"]=>
  array(1) {
    [0]=>
    string(11) "tag_cloud-3"
  }
  ["sidebar-hero"]=>
  array(1) {
    [0]=>
    string(14) "smartslider3-2"
  }
}
  • Where and how are you calling is_active_widget? Please edit your question and add the relevant code. – janh Dec 27 '17 at 12:22
  • That should be is_active_sidebar. Thanks for the heads up. Corrected. – tpaksu Dec 27 '17 at 12:24
0

In this case I would simply check if the slider plugin is activated - so your conditional statement would look like this:

 <?php if ( is_active_sidebar( 'sidebar-hero' ) && 
            is_plugin_active( 'slider-plugin-dir/slider-plugin-base-file.php' ) 
 ) : ?>

wp_get_sidebars_widgets in your case works as expected - it checks for the widgets in wp_options table and keeps the widget because it is still there. It makes sense - deactivating the plugin is not the same as removing the widget and this function is not intended to check for widget's dependencies.

  • The widget that user added to the sidebar may vary. I don't limit the user to use one type of slider plugin. – tpaksu Dec 27 '17 at 13:09
  • Oh, sorry then, I don't understand entirely what you're trying to achieve. What do you insert into widget then if it's supposed to work with any slider plugin? Any shortcode? – Levi Dulstein Dec 27 '17 at 13:14
  • Nope, any slider plugin such as Revo Slider, Smart Slider, Soliloquy slider can be inserted by the user. Or if he/she doesn't care about the display, he/she could insert any other plugin widget as well. I don't care about what's inserted, but the template enforces user to use a slider widget for the completeness of the theme. – tpaksu Dec 27 '17 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.