Last active
August 22, 2018 14:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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