WordPress Admin Plugin

I’m wondering 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()?

Related posts

Leave a Reply

1 comment

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

    1. One of many tutorials on writing a WordPress plugin. Plugins subscribe to actions (amongst other things) and can emit HTML when an action is triggered by the WordPress engine.
    2. The list on the WordPress codex of actions to which plugins can subscribe to trigger their own code. Adding actions is defined in that tutorial. 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 (not tested!):

    /*
    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');