4

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()?

4

1 回答 1

11

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');
于 2008-10-22T11:32:52.167 回答