WordPress Plugin – Simple Option Page

After writing your plugin maybe you want to allow the users to costumize it. One way to do this is including an option page on the wordpress admin section.
To write a simple option page I’ll use the previews example  Happy Face Replacer Plugin. And I’ll allow the user to set the happy face image url.

Admin Menus/Submenus

First of all you need to figure out where is the best place to include your administration page on the wordpress admin sections: SettingsManage, PluginsPresentation, Write, Users.
In this case I’ll use the “Manage” panel.

The Action

To tell wordpress about your option page you need to use an action ‘hook’ called admin_menu (on the previews post you can read more about wordpress actions, filters and hooks).
In our main plugin file “happy_face_replacer.php” we need to include something like this:

add_action('admin_menu', 'function_to_create_your_menu');

Inside of the ‘funtion to create your menu’ you need to use one of the ‘add_menu/submenu_page’ functions :

add_menu_page(page_title, menu_title, access_level/capability, file, [function]);

for the menus or:

add_submenu_page(parent, page_title, menu_title, access_level/capability, file, [function]);

for the submenus.

In this example we need to call the function:

add_management_page

As your plugin your admin menu, page and functions must have a unique name. Continue reading WordPress Plugin – Simple Option Page