WidgetOptions / widget-options

Additional Widget options for better widget control. Available on
https://widget-options.com/
GNU General Public License v3.0
34 stars 16 forks source link

Tag Archive Pages Show ALL widgets #23

Closed fkildoo closed 7 years ago

fkildoo commented 7 years ago

I have many of my widgets set to only show on select post type/pages or taxonomy/categories. It is working fine for all the assigned pages and categories, only showing the correct widget on the associated page or category. Having a problem on the tag archive pages. These pages are showing ALL of my widgets.

For example, see this tag archive page that shows all widgets. No widgets should appear. -- http://www.zekiah.com/zekiah_wordpress/tag/arcmap

I thought about making my archive pages full width in my theme files, but that also affects my category pages that need the sidebar.

capture

fkildoo commented 7 years ago

As a workaround, I was able to edit my archive.php theme file so that the sidebar (containing the widgets) would not appear on those pages. I'd say the problem or bug still exists but this bandaid is good enough for now.

pankamilr commented 7 years ago

Here's a workaround that works. We can fix this by using add_filter function.

add_filter( 'widget_display_callback', 'custom_widgetopts_display_callback', 51, 3 );
function custom_widgetopts_display_callback($instance, $widget, $args) {
  global $widget_options, $current_user;

  $hidden     = false;
  $opts       = ( isset( $instance[ 'extended_widget_opts-'. $widget->id ] ) ) ? $instance[ 'extended_widget_opts-'. $widget->id ] : array();
  $visibility = array( 'show' => array(), 'hide' => array() );

  //wordpress pages
  $visibility         = isset( $opts['visibility'] ) ? $opts['visibility'] : array();
  $visibility_opts    = isset( $opts['visibility']['options'] ) ? $opts['visibility']['options'] : 'hide';

  $is_tax     = ( 'activate' == $widget_options['visibility'] && isset( $widget_options['settings']['visibility'] ) && isset( $widget_options['settings']['visibility']['taxonomies'] ) ) ? true : false;

  if ( $is_tax && is_tag() ) {
    if( !isset( $visibility['tags'] ) ){
        $visibility['tags'] = array();
    }

    if(  ( isset( $visibility['taxonomies']['post_tag'] ) && $visibility_opts == 'hide' ) ||
         ( !isset( $visibility['taxonomies']['post_tag'] ) && $visibility_opts == 'show' ) 
    ) {
        $hidden = true; //hide to all tags
    }elseif( isset( $visibility['taxonomies']['post_tag'] ) && $visibility_opts == 'show' ){
        $hidden = false; //hide to all tags
    }

    //do return to bypass other conditions
    $hidden = apply_filters( 'widget_options_visibility_tags', $hidden );
    if( $hidden ){
        return false;
    }
  }
  return $instance;
}
pankamilr commented 7 years ago

I've made a pull request to this issue.

phpbits commented 7 years ago

@pankamilr Thank you very much! Will check and add the fixes on the next update. Thanks again!

Cheers, Jeffrey