%s

', 'To complete the installation of Dashboard Commander you must visit your dashboard once and then go to Settings > Dashboard Commander to configure who has access to each widget.'); } } /** * Initialize plugin * @args none * @return void */ function dcmd_admin_init() { $widgets = get_option('dcmd_dashboard_widgets'); if($widgets){ foreach($widgets as $widget) { register_setting('dcmd_options', 'dcmd_'.$widget['id']); } } } /** * Display Settings link on Plugins admin page * @args array * @return array */ function dcmd_plugin_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } /** * Deactivate plugin * @args none * @return void */ function dcmd_deactivate() { $widgets = get_option('dcmd_dashboard_widgets'); foreach($widgets as $widget) { delete_option('dcmd_'.$widget['id']); } delete_option('dcmd_dashboard_widgets'); } /** * Loop through the dashboard widgets and remove depending on current user capabilities * @args none * @return void */ function dcmd_wp_dashboard_setup() { global $wp_meta_boxes; $widgets = dcmd_get_dashboard_widgets(); update_option('dcmd_dashboard_widgets', $widgets); foreach ($widgets as $widget){ if(!current_user_can(get_option('dcmd_'.$widget['id']))) { unset($wp_meta_boxes['dashboard'][$widget['context']][$widget['priority']][$widget['id']]); } } } /** * Get array of capabilities or generate dropdown list for options page * @args bool (optional) $selectlist, bool (optional) $name * @return array|string */ function dcmd_get_capabilities($selectlist = FALSE, $name = FALSE) { global $wp_roles; $option = get_option($name); if ($selectlist) { $cap = ''; return $cap; } else { return $wp_roles->roles['administrator']['capabilities']; } } /** * Generate an array of registered dashboard widgets * @args none * @return array */ function dcmd_get_dashboard_widgets() { global $wp_meta_boxes; $widgets = array(); if (isset($wp_meta_boxes['dashboard'])) { foreach($wp_meta_boxes['dashboard'] as $context=>$data){ foreach($data as $priority=>$data){ foreach($data as $widget=>$data){ //echo $context.' > '.$priority.' > '.$widget.' > '.$data['title']."\n"; $widgets[$widget] = array('id' => $widget, 'title' => strip_tags(preg_replace('/ /im', '', $data['title'])), 'context' => $context, 'priority' => $priority ); } } } } return $widgets; } /** * Add options page to admin menu * @args none * @return void */ function dcmd_admin_menu() { if (function_exists('add_options_page')) { add_options_page('Dashboard Commander', 'Dashboard Commander', 'manage_options', __FILE__, 'dcmd_admin_page'); } } /** * Generate options page content * @args none * @return string */ function dcmd_admin_page() { if (empty($title)) $title = __('Dashboard Commander Options'); $widgets = get_option('dcmd_dashboard_widgets'); ?>

Select the minimum access level you want to make a dashboard widget visible to.

Note: You cannot force a widget to be visible if it was never visible to a capability to begin with. Example: It is not possible to make the 'Recent Comments' widget visible to a user with an 'edit_published_posts' or lower capability. This is due to the widget's specific add-to-dashboard code and not a limitation of this plugin.

Not familiar with WordPress capabilities? Refer to the WordPress Codex to see how capabilities relate to user roles