" "

model trains for beginners 728 x 90 728 x 90

Create a Basic WordPress Plugin to Customize Your Dashboard

By Dipra Sen Our Bestseller: WordPress Themes

There are thousands of WordPress plugins available for free download in WordPress plugin directory . You’ll find plugins for almost all needs to run a WordPress blog but sometimes you may feel to customize your own WordPress plugin to create according to your need.

Either you’ll not find the perfect plugin for your need or you’ll need to install more than one plugin to do your job done right. Sometimes you’ll need only one or two features of a big fat plugin.

Here comes the idea of customizing your own plugin to do a specific job. Also, you will learn to customize your WordPress dashboard according to plugin.

There are many WordPress plugins to customize admin dashboard but sometimes they may fall short. In this tutorial I’ll guide you to write your first WordPress plugin to customize your blog dashboard.

Required Knowledge for This Tutorial Basic WordPress functionalities WordPress plugin system PHP Basic MySQL Basic HTMLPlugin Functionality

The WordPress admin dashboard has some default widgets that can be set to hide by unchecking them from “Screen Options”.

default widget WordPress

This is not problem if you’re the blog admin. But, if you give access to guest bloggers or subscribers and want not to show these widgets to them or want to show some special messages to them then you’ll need to install some plugins or write your own one.

In this tutorial I’ll try to guide you to make a WordPress plugin that will help you to customize your blog admin.

Steps to Customize a Basic Plugin 1. Create the Main Plugin File

WordPress plugin has a standard format and need some compulsory data to make the plugin work. Create a PHP file and name it dashboard-customization.php in your favorite text editor like notepad. Add the code written below.

This is the basic information a WordPress plugin need. You can obviously add more information here like ‘License’ etc. Upload this PHP file to your WordPress plugin directory located at wp-content/plugins/ using an FTP client like FileZilla and refresh the plugins page from your dashboard, you’ll see that a new plugin called ‘Dashboard Customization’ has been appeared in the plugin list.

plugin list

This is the basic structure of the plugin. Now, update the file to add the features you want.

2. Add Customization Functionality to the Plugin

Add a function dashboard_customization() in the file. As we’re customizing the dashboard only for those who do not have administrative role, we must check if the user is a non admin. So, everything will be under the condition of user role check.

function dashboard_customization() { if (!current_user_can('manage_options') ) { /* ALL FUNCTIONALITIES HERE */ } } function dashboard_customization() { if (!current_user_can('manage_options') ) { /* ALL FUNCTIONALITIES HERE */ } }

First, declare $wp_admin_bar and $wp_meta_boxes as global variables. From $wp_admin_bar you can control the admin bar and from $wp_meta_boxes you can control the meta boxes in the dashboard.

meta boxes

Now, it’s time to customize the whole dashboard.

1. Remove Dashboard Widgets

Somewhere, you need to customize your dashboard too. Like, removing some of the unrequired widgets. For e.g. if you want to remove meta boxes from the dashboard you’ll need to unset them.

To remove ‘incoming links’ widget you’ll need to add

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);

incoming links

To remove the ‘plugins’ widget you’ll need to add

unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);

plugins

To remove the ‘WordPress Blog’ widget you’ll need to add

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);

WordPress

To remove ‘Other WordPress News’ widget you’ll need to add

unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

WordPress

2. Remove Toolbar Nodes

toolbar nodes

To remove WordPress logo, comments button, new content button and site name from the admin bar add the following code.

$wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('comments'); $wp_admin_bar->remove_menu('new-content'); $wp_admin_bar->remove_menu('site-name');3. Remove Help Menu

Help-menu

To remove dashboard help menu we’ll need to hook a function to the contextual_help filter action using add_filter .

add_filter( 'contextual_help', 'remove_contextual_help', 999, 3 );  function remove_contextual_help($old_help, $screen_id, $screen){              $screen->remove_help_tabs();              return $old_help; }

Visit WordPress Codex to know more about add _ filter .

4. Remove Update Notification

notification

The following code will remove the update notification from dashboard.

add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );5. Change Footer Message

footer

To change the message in footer you’ll need to hook a function to the admin_footer_text filter action.

function change_footer_admin () { return 'This blog is created with Goodnewstheme.'; } add_filter('admin_footer_text', 'change_footer_admin', 9999);6. Change WordPress Update Notification in Footer

notification

If you want to disable the WordPress update notification in footer then you’ll need to add filter to the update_footer filter action.

function change_footer_version() { return ' '; } add_filter( 'update_footer', 'change_footer_version', 9999);7. Add Menu to Admin Bar

Sometimes you may require to add a custom menu to the admin bar. The following code will add a menu called “Submit Guest Post” to the admin bar.

$wp_admin_bar->add_menu( array(  'parent' => false,  'id' => 'submit-guest-post',  'title' => __('Submit Guest Post'),  'href' => 'http://www.careerenter.com/submit-guest-post/' ));8. Add a Custom Widget

If you want to add a custom widget you’ll need to write two functions,  one for the widget design, another for inserting the widget data to the database. In this tutorial I’ll add a widget containing useful resource for blogging.

resource

function guest_blogger_resource_widget() {     echo ' ';     echo '';     echo '';     echo '';     echo '';     echo ''; }

Function for inserting the widget data into database:

function add_guest_blogger_resource_widget() { wp_add_dashboard_widget( 'guest-blogger-resoure', 'Useful Resources', 'guest_blogger_resource_widget'); }3. Adding the Action Hooks

Till now we’ve added information about the plugin and plugin functionalities in functions. But, there’s no instruction to execute the plugin code. We’ll need to add action hooks to execute the plugin code. Action hooks work like callback function. add actionfunction is a WordPress function made for this purpose. We’ll use this function to tell WordPress to run the plugin code inside the functions we’ve written.

add_action( 'wp_before_admin_bar_render', 'dashboard_customization' ); add_action( 'wp_dashboard_setup', 'add_guest_blogger_resource_widget' );

So, the complete plugin code for dashboard-customization.php is

remove_menu('wp-logo');              $wp_admin_bar->remove_menu('comments');              $wp_admin_bar->remove_menu('new-content');              $wp_admin_bar->remove_menu('site-name');              // Customize dashboard              // Remove help menu              add_filter( 'contextual_help', 'remove_contextual_help', 999, 3 );              function remove_contextual_help($old_help, $screen_id, $screen){                         $screen->remove_help_tabs();                         return $old_help;              }              // Remove update notification              add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );              // Change footer message              function change_footer_admin () {                          return 'This blog is created with Goodnewstheme.';              }              add_filter('admin_footer_text', 'change_footer_admin', 9999);              // Change footer version              function change_footer_version() {                          return ' ';              }              add_filter( 'update_footer', 'change_footer_version', 9999);              // add 'Submit Guest Post' menu to adminbar              $wp_admin_bar->add_menu( array(              'parent' => false,              'id' => 'submit-guest-post',              'title' => __('Submit Guest Post'),              'href' => 'http://www.careerenter.com/submit-guest-post/'              ));              // add custom widget in dashboard              function guest_blogger_dashboard_widget() {                          echo ' ';                          echo '';                          echo '';                          echo '';              }              function add_guest_blogger_dashboard_widget() {                         wp_add_dashboard_widget( 'guest-blogger-resource', 'Useful Resources','guest_blogger_dashboard_widget');              }              add_action('wp_dashboard_setup', 'add_guest_blogger_dashboard_widget');              } } // add custom widget in dashboard function guest_blogger_resource_widget() {     echo ' ';     echo '';     echo '';     echo '';     echo '';     echo ''; } function add_guest_blogger_resource_widget() {             wp_add_dashboard_widget( 'guest-blogger-resoure', 'Useful Resources','guest_blogger_resource_widget'); } /* Hook function */ add_action( 'wp_before_admin_bar_render', 'dashboard_customization' ); add_action( 'wp_dashboard_setup', 'add_guest_blogger_resource_widget' );

And the final result of a subscriber dashboard will look like.

dashboard

I hope the tutorial let’s you understand the insights of customizing your own WordPress plugin and WordPress dashboard. If you have any questions regarding this tutorial feel free to ask. I will get back to you.

About Dipra Sen
contributor

I am a software developer and tech blogger. I love to blog on various subjects but my first love is technology. I have written some blog posts on CareerEnter.com and BloggingSmart.com

Comments and Responses

Share on Google Plus

About Unknown

250 x 250
    Blogger Comment
    Facebook Comment

0 nhận xét:

Đăng nhận xét