widgets ) as $widget_key ) { // Multi widgets if ( !isset( $allowed_widgets[ $widget_key ] ) ) unregister_widget( $widget_key ); } } function filter_single() { if ( current_user_can( 'manage_network_themes' ) ) // Disable restrictions for network admins return; $allowed_widgets = get_site_option( 'allowedwidgets' ); if ( !is_array( $allowed_widgets ) ) return $widgets; foreach( array_keys( $this->single_widgets ) as $widget_key ) { // Single widgets if ( !isset( $allowed_widgets[ $widget_key ] ) ) wp_unregister_sidebar_widget( $widget_key ); } } function register( $widget ) { // Register single instance widgets internally since they don't use WP_Widget_Factory if ( isset( $widget['params'][0] ) && ! is_array( $widget['params'][0] ) ) { $this->single_widgets[ $widget['id'] ] = $widget['name']; } return $widget; } function unregister( $widget_id ) { // Unregister single instance widget unset( $this->single_widgets[ $widget_id ] ); } function setup_admin() { if ( function_exists('is_network_admin') ) $page = add_theme_page( __( 'Restricted Widgets', 'restrict-multisite-widgets' ), __( 'Widget Restrictions', 'restrict-multisite-widgets' ), 'manage_network_themes', 'ms-widgets', array(&$this,'admin') ); else $page = add_submenu_page( 'ms-admin.php', __( 'Restricted Widgets', 'restrict-multisite-widgets' ), __('Widgets', 'restrict-multisite-widgets' ), 'manage_network_themes', 'ms-widgets', array(&$this,'admin') ); add_contextual_help( $page, '
' . __( 'This screen enables and disables the inclusion of widgets available to choose in the Widgets menu for each site.', 'restrict-multisite-widgets' ) . '
' . '' . __( 'If the network admin disables a widget that is in use, it will be removed from any sites using it.', 'restrict-multisite-widgets' ) . '
' ); } function admin() { global $wp_widget_factory; if ( isset( $_POST['widget'] ) ) { $widget_states = array(); foreach( (array)$_POST['widget'] as $widget => $widget_state ) { if ( $widget_state == 'enabled' ) $widget_states[ $widget ] = 1; else unset( $widget_states[ $widget ] ); } $updated = update_site_option( 'allowedwidgets', $widget_states ); } if ( isset($updated) && $updated ) { ?>