Created
December 13, 2018 17:11
-
-
Save plugin-republic/d2a9b106168ed007e30b0e7c084e3156 to your computer and use it in GitHub Desktop.
Programmatically prevent a widget from being rendered
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 | |
/** | |
* This will hide widgets | |
* @param array $instance The current widget instance's settings. | |
* @param WP_Widget $this The current widget instance. | |
* @param array $args An array of default widget arguments. | |
*/ | |
function wcmo_filter_widget_display_callback( $settings, $widget, $args ) { | |
$can_access = false; // You need to set your conditions here | |
if( $can_access || in_array( $widget->name, $whitelist ) ) { | |
// If the user can view the widget, just return the settings | |
return $settings; | |
} | |
// Otherwise, return false to prevent the widget from rendering | |
return false; | |
} | |
add_filter( 'widget_display_callback', 'wcmo_filter_widget_display_callback', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment