Forked from strangerstudios/my_pmpro_widget_display_callback.php
Last active
September 4, 2017 08:20
-
-
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.
This file contains 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; | |
//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