Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active August 22, 2018 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save strangerstudios/b81443b278a6b27102b666c36084d624 to your computer and use it in GitHub Desktop.
Save strangerstudios/b81443b278a6b27102b666c36084d624 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;
if( is_user_logged_in() && function_exists('pmpro_has_membership_access') && !pmpro_has_membership_access($post->ID)) {
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