Last active
August 1, 2023 12:42
-
-
Save kimcoleman/227edd825acbfd7aaaf5ba334c8c1482 to your computer and use it in GitHub Desktop.
Hide widgets by widget instance ID and membership level to protect specific widgets for members only.
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 | |
/** | |
* Hide widgets by widget instance ID for protected members only content. | |
* Update the $hide_widget_instances_array with the array of widget instance IDs you want to filter. | |
* Update the pmpro_hasMembershipLevel check for your membership level IDs. | |
* | |
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_widgets_by_membership_level( $instance, $widget, $args ) { | |
// Set an array of widget areas by ID to filter. | |
$hide_widget_instances_array = array( 'text-3', 'recent-comments-1' ); | |
// Check if this widget instance should be filtered. | |
if ( in_array($widget->id, $hide_widget_instances_array ) && ! pmpro_hasMembershipLevel( 1 ) ) { | |
return false; | |
} | |
return $instance; | |
} | |
add_filter('widget_display_callback','my_pmpro_widgets_by_membership_level', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@produktivweb please open a support ticket on www.paidmembershipspro.com/support for help with this as it would require a bit more work and explanation than we can provide in the comment section here.