prefix . 'capabilities'; $current_user->role = array_keys($current_user->$role); $role = $current_user->role[0]; if (array_key_exists($role, (array)$active_roles)) { add_action('wp_dashboard_setup', 'abd_dwm_remove_dashboard_widgets' ); add_action('wp_dashboard_setup', 'abd_dwm_add_dashboard_widget' ); } } } function abd_dwm_install() { add_option('abd_dwm_user_roles', array('administrator' => 'true')); add_option('abd_dwm_show_widgets', array('dashboard_right_now' => 'true')); add_option('abd_dwm_widget_content', 'Edit this text or use html, the media uploader, and shortcodes to create your own widget.'); add_option('abd_dwm_widget_title', 'Custom Widget'); add_option('abd_dwm_avail_dashboard_widgets'); } function abd_dwm_uninstall() { delete_option('abd_dwm_user_roles'); delete_option('abd_dwm_show_widgets'); delete_option('abd_dwm_widget_content'); delete_option('abd_dwm_widget_title'); delete_option('abd_dwm_avail_dashboard_widgets'); } function abd_dwm_get_core_dashboard_widgets() { $dashboard_widgets = get_option('abd_dwm_avail_dashboard_widgets'); if(empty($dashboard_widgets)) { $dashboard_widgets = array ( 'dashboard_right_now' => array ( 'name' => 'Right Now', 'context' => 'normal' ), 'dashboard_recent_comments' => array ( 'name' => 'Recent Comments', 'context' => 'normal' ), 'dashboard_incoming_links' => array ( 'name' => 'Incoming Links', 'context' => 'normal' ), 'dashboard_plugins' => array ( 'name' => 'Plugins', 'context' => 'normal' ), 'dashboard_quick_press' => array ( 'name' => 'Quick Press', 'context' => 'side' ), 'dashboard_recent_drafts' => array ( 'name' => 'Recent Drafts', 'context' => 'side' ), 'dashboard_primary' => array ( 'name' => 'Primary', 'context' => 'side' ), 'dashboard_secondary' => array ( 'name' => 'Secondary', 'context' => 'side' ) ); } $custom_widget = array ( 'abd_dwm_custom_widget' => array( 'name' => 'Custom Widget', 'context' => 'side' ) ); $dashboard_widgets = array_merge($dashboard_widgets, $custom_widget); return $dashboard_widgets; } function abd_dwm_settings_page() { global $wpdb, $wp_roles, $current_user; $dashboard_widgets = abd_dwm_get_core_dashboard_widgets(); ?>
$widget) { if(!isset($active_widgets[$widget_key])) { remove_meta_box($widget_key, 'dashboard', $widget['context']); } } } } function abd_dwm_dashboard_widget() { $widget_content = get_option('abd_dwm_widget_content'); if($widget_content != '') { echo wpautop(do_shortcode(stripcslashes($widget_content))); echo ''; //clearing floating content } else { echo 'Missing content for widget'; } } function abd_dwm_add_dashboard_widget() { $widget_title = get_option('abd_dwm_widget_title'); if($widget_title == '') { $widget_title = 'Custom Widget'; } wp_add_dashboard_widget('abd_dwm_custom_widget', $widget_title, 'abd_dwm_dashboard_widget'); } function abd_dwm_find_core_dashboard_widgets() { global $wp_meta_boxes; if (is_array($wp_meta_boxes['dashboard'])) { $avail_widgets = array(); $normal_core_widgets = $wp_meta_boxes['dashboard']['normal']['core']; $side_core_widgets = $wp_meta_boxes['dashboard']['side']['core']; foreach($normal_core_widgets as $key => $widget) { if($key != 'abd_dwm_custom_widget') { //removing out custom widget from array to store add back on later $search = array("dashboard_", "_", "-"); $replace = array("", " ", " "); $name = ucwords(str_replace($search, $replace, $key)); $avail_widgets[$key] = array( 'name' => $name, 'context' => 'normal' ); } } foreach($side_core_widgets as $key => $widget) { $search = array("dashboard_", "_"); $replace = array("", " "); $name = ucwords(str_replace($search, $replace, $key)); $avail_widgets[$key] = array( 'name' => $name, 'context' => 'side' ); } if(!empty($avail_widgets)) { update_option('abd_dwm_avail_dashboard_widgets', $avail_widgets); } } }