WordPress Admin Plugin

Mar 13, 2012   //   by phpfreelancer.biz   //   Blog, Wordpress Plugin Tutorial  //  No Comments

How I can make a plugin to output some data via the admin panel. Just to get me going what code would make a page in the admin panel (for only administrators) to display time()?

It’s actually very easy, you only need two things:

writing a WordPress plugin and Plugins subscribe to actions (amongst other things) and can emit HTML when an action is triggered by the WordPress engine.

The list on the WordPress codex of actions to which plugins can subscribe to trigger their own code. Adding actions is defined in that, Specifically you want the administrative actions. e.g.: the admin_footer action will cause your plugin’s output to be displayed in the footer of the admin page. There’s a wide range of actions for all kinds of situations and conditions.

The PHP date() function will give you the current time, so you just need to write a function in your plugin that does echo date(), and then use add_action to get your PHP function executed in response to the appropriate WordPress action.

So to make it completely clear, your plugin code would look like this:

Plugin Name: Admin Date Displayer
Plugin URI: http://example.com/
Description: Displays the current datetime on the admin page
Author: Stewart
Version: 1.0
Author URI: http://bolidian.com/

function display_date()
    echo date();

add_action('admin_footer', 'display_date');

Leave a comment

Share This Post

RSS Wordpress News