Replacing the WordPress Dashboard with your own plugin page.

On Custom WordPress Installations, you may want to remove the wordpress dashboard completely and add your own dashboard or plugin page. Of course you can hide the other dashboard widgets and leave only your own, but if you want complete control, this is one solution. I was able to do this using the following approach:

On WordPress 3.1.1, the /wp-admin/index.php provides no support for overriding the wp_dashboard() function. After digging around for an hour or two and finding no hooks inside wp_dashboard(), I thought the best way to remove the dashboard would be to redirect the user from index.php to admin.php?page=your-page and modifying the admin menu item for the ‘Dashboard’ by using admin_init, and admin_menu hooks.

Redirecting from the dashboard to your plugin page:

function my_plugin_admin_init(){
global $pagenow;
		if(current_user_can('plugin_user_role') && $pagenow == 'index.php' && empty($_GET['page']))
		{
			wp_redirect(admin_url('admin.php?page=manage-applications'));
			exit;
		}
}
add_action('admin_init', 'my_plugin_admin_init');

In the code above, I only wanted to remove the dashboard for users under ‘plugin_user_role’, to remove the dashboard for all non-admin users, you can check if !current_user_can(‘manage_options’) in place of current_user_can(‘plugin_user_role’)

The second part is modifying the Admin Menu so that the dashboard menu item title is changed. It will still point to index.php, but index.php will now redirect to our page.

function my_admin_menu()
{
// create a menu page, this will be hidden later
		add_menu_page('Membership Applications', 'Reviews', 'review_members', 'manage-applications', $page_handler);

		global $submenu_file, $pagenow, $menu;

// rename this to change the 'Dashboard' Menu Title.
		$menu[2][0] = __('Applications');

// i only want to remove the dashboard for a specific user role
		if(current_user_can('plugin_user_role'))
		{
// if the current page is my the dashboard replacement, then highlight the 'Dashboard' menu item
			if(@$_GET['page'] == 'manage-applications')
			{
				$submenu_file = 'index.php';
				$pagenow = 'index.php';
			}
		}

// now remove the page from the menu, we have already linked
		remove_menu_page('manage-applications');
}
add_action('admin_menu', 'my_admin_menu');

On Custom WordPress Installations, you may want to remove the wordpress dashboard completely and add your own dashboard or plugin page. Of course you can hide the other dashboard widgets and leave only your own, but if you want complete control, this is one solution. I was able to do this using the following approach:

On WordPress 3.1.1, the /wp-admin/index.php provides no support for overriding the wp_dashboard() function. After digging around for an hour or two and finding no hooks inside wp_dashboard(), I thought the best way to remove the dashboard would be to redirect the user from index.php to admin.php?page=your-page and modifying the admin menu item for the ‘Dashboard’ by using admin_init, and admin_menu hooks.

Redirecting from the dashboard to your plugin page:

function my_plugin_admin_init(){
		if(current_user_can('plugin_user_role') && $pagenow == 'index.php' && empty($_GET['page']))
		{
			wp_redirect(admin_url('admin.php?page=manage-applications'));
			exit;
		}
}
add_action('admin_init', 'my_plugin_admin_init');

In the code above, I only wanted to remove the dashboard for users under ‘plugin_user_role’, to remove the dashboard for all non-admin users, you can check if !current_user_can(‘manage_options’) in place of current_user_can(‘plugin_user_role’)

The second part is modifying the Admin Menu so that the dashboard menu item title is changed. It will still point to index.php, but index.php will now redirect to our page.

function my_admin_menu()
{
// create a menu page, this will be hidden later
		add_menu_page('Membership Applications', 'Reviews', 'review_members', 'manage-applications', $page_handler);

		global $submenu_file, $pagenow, $menu;

// rename this to change the 'Dashboard' Menu Title.
		$menu[2][0] = __('Applications');

// i only want to remove the dashboard for a specific user role
		if(current_user_can('plugin_user_role'))
		{
// if the current page is my the dashboard replacement, then highlight the 'Dashboard' menu item
			if(@$_GET['page'] == 'manage-applications')
			{
				$submenu_file = 'index.php';
				$pagenow = 'index.php';
			}
		}

// now remove the page from the menu, we have already linked
		remove_menu_page('manage-applications');
}