Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/ab9a20838a863633d61d04be3ca5af14 to your computer and use it in GitHub Desktop.
Save andrewlimaza/ab9a20838a863633d61d04be3ca5af14 to your computer and use it in GitHub Desktop.
Hide widgets by sidebar ID on members only content when the current user does not have access.
<?php
/*
Update line 8 with the array of sidebar IDs you want to filter.
Add this code to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_widget_display_callback($instance, $widget, $args) {
$hide_sidebars_array = array('sidebar-1','sidebar-2');
global $post;
//check if current user has an active membership level and hide the sidebars.
if( pmpro_hasMembershipLevel() ) {
if(in_array($args['id'], $hide_sidebars_array) )
return false;
else
return $instance;
}
}
add_filter('widget_display_callback','my_pmpro_widget_display_callback', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment