Skip to content

Instantly share code, notes, and snippets.

@ianpegg
Last active October 28, 2024 12:46
Show Gist options
  • Select an option

  • Save ianpegg/0e3beb746757916d46f636f12b6d6a44 to your computer and use it in GitHub Desktop.

Select an option

Save ianpegg/0e3beb746757916d46f636f12b6d6a44 to your computer and use it in GitHub Desktop.
Modify the WP dashboard - remove dashboard widgets and other furniture we don't need.
<?php
/**
* Plugin Name: eggMUP: WP Admin Dashboard Setup
* Plugin URI: https://gist.github.com/ianpegg/0e3beb746757916d46f636f12b6d6a44
* Description: Modify the WP dashboard - remove dashboard widgets & other furniture we don't need.
* Version: 1.1.0
* Author: Ian Pegg
* Author URI: https://eggcupwebdesign.com
* php version 8.2.14
*
* @category Must_Use_Plugin
* @package WordPress_Plugin
* @author Ian Pegg <[email protected]>
* @license GNU/GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
* @link https://eggcupwebdesign.com
*/
namespace EggCup\MUP\DashboardSetup;
if (!defined('ABSPATH')) {
exit;
}
/**
* Adds a reusable blocks menu so that design patterns can be
* easily managed independently of the page editor:
*
* @return void
*/
add_action('admin_menu', function () {
if (true == current_user_can('manage_options')) {
/**
* Add a menu item to manage reusable blocks:
* @link https://www.billerickson.net/reusable-blocks-accessible-in-wordpress-admin-area
*/
add_menu_page(
'Reusable Blocks',
'Reusable Blocks',
'edit_posts',
'edit.php?post_type=wp_block',
'',
'dashicons-welcome-widgets-menus',
20
);
}
}, 999);
/**
* Removes WordPress menu from admin bar:
*
* @param Object $wp_admin_bar Admin bar object provided by core
*
* @return void
*/
add_action('admin_bar_menu', function ( $wp_admin_bar ) {
$wp_admin_bar->remove_node('wp-logo');
}, 999);
/**
* Removes default dashboard widgets:
*
* @return void
*/
add_action('wp_dashboard_setup', function () {
remove_action('welcome_panel', 'wp_welcome_panel');
remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
remove_meta_box('dashboard_activity', 'dashboard', 'normal');
remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
// WordPress blog feed:
remove_meta_box('dashboard_primary', 'dashboard', 'side');
// Other WordPress news:
remove_meta_box('dashboard_secondary', 'dashboard', 'side');
// The new authors of Search Exclude added a dashboard widget nobody wanted:
remove_meta_box('wp-dashboard-widget-news', 'dashboard', 'normal');
// Remove Yoast widget for users without SEO privileges:
if (!current_user_can('wpseo_edit_advanced_metadata')) {
remove_meta_box('wpseo-dashboard-overview', 'dashboard', 'side');
}
});
/**
* Remove meta boxes depending upon user privileges:
*
* @return void
*/
add_action('add_meta_boxes', function () {
/**
* Remove a bunch of boxes for non admins:
*/
if (!current_user_can('manage_options')) {
remove_meta_box('linktargetdiv', 'link', 'normal');
remove_meta_box('linkxfndiv', 'link', 'normal');
remove_meta_box('linkadvanceddiv', 'link', 'normal');
remove_meta_box('postcustom', 'post', 'normal');
remove_meta_box('slugdiv', 'post', 'normal');
}
/**
* Remove Yoast for users without SEO privileges:
*/
if (!current_user_can('wpseo_edit_advanced_metadata')) {
remove_meta_box('wpseo_meta', 'post', 'normal');
remove_meta_box('authordiv', 'post', 'normal');
remove_meta_box('sep_metabox_id', 'post', 'side');
}
});
/**
* Customises the WP admin dashboard footer message:
*
* @return void
*/
add_filter('admin_footer_text', function () {
echo
'<p>'
. 'A bespoke <a href="https://www.wordpress.org">WordPress</a> website. '
. 'Hand crafted in Norwich, England by '
. '<a href="https://eggcupwebdesign.com/">eggcup</a>'
. '</p>';
}, 999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment