Friday, February 3, 2012

WordPress Administration menu example


Here is a very simple example of the three steps just described. This plugin will add a sub-level menu item under the Settings top-level menu, and when selected, that menu item will cause a very basic screen to display

In this example, the function, my_plugin_menu(), adds a new item to the Administration menu via the add_options_page function.
<?php
add_action('admin_menu', 'my_plugin_menu');

function my_plugin_menu() {
add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');
}

function my_plugin_options() {
if (!current_user_can('manage_options'))  {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
echo '<div class="wrap">';
echo '<p>Here is where the form would go if I actually had options.</p>';
echo '</div>';
}
?>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.