⚡ Rocket.net – Managed WordPress Hosting

MiltonMarketing.com  Powered by Rocket.net – Managed WordPress Hosting

Bernard Aybouts - Blog - MiltonMarketing.com

Approx. read time: 27.5 min.

Post: Extending WordPress with Plugins

Creating an admin interface

The first step in creating a Copyright plugin is to create a function that generates the HTML that is going to be used inside the WordPress Admin. Most of the administrative duties will be done in this function, as shown below:

[html] function copyright_notices_admin()
{
?>

<div class=”wrap”>
<?php screen_icon(); ?>

<h2>Copyright Notices Configuration</h2>

On this page, you will configure all the aspects of this
plugins.

<form action=”” method=”post” id=”copyright-notices-conf-form”>

<h3><label for=”copyright_text”>Copyright Text to be inserted
in the footer of your theme:</label></h3>

<input type=”text” name=”copyright_text” id=”copyright_
text” value=”<?php echo esc_attr( get_option(‘copyright_notices_text’) ) ?> “ />

<input type=”submit” name=”submit” value=”Update options &raquo;” />

</form>

</div>

<?php
}[/html]

The first thing you might notice about the code above is that we have used very specific HTML markup to create an administrative panel. For consistency with the rest of the WordPress Admin, it is a good practice to fall into.

The entirety of the panel should be wrapped in < div class=”wrap” >< /div > to inherit the default formatting for the page. Main titles of sections of the panel should be wrapped in < h2 > tags.

The screen_icon() function inserts an appropriate icon, associated with the section of the WordPress Admin that the page will be loaded under, next to the header. You’ll use a lot of form fields, and so you’ll want to wrap the < label > tags in < h3 > tags.

 

To avoid the possibility of function names colliding, adopt a naming convention that is unique to you personally.

It could be an abbreviation for the plugin followed by an underscore (like hwp_doit()) or it could mean using a class to “namespace” your functions.

If a user activates your plugin and it has the same function name as a core function or a function provided elsewhere in WordPress, they will get errors and not be able to use your plugin.

Having observed standard formatting (which, of course, you can depart from with varying results), you’ll notice that when you try to activate the plugin on the Plugins page, it will activate, but nothing will happen. Looking further at the code, the second thing you’ll notice is the use of the get_option() function.

Don’t worry about this too much right now. Until you tie the plugin to the database, nothing will actually be displayed here. Later, it will show saved text and can be updated at will.

Adding an admin panel to the WordPress Admin navigation menu

Next you need to hook this function into WordPress itself by adding an Admin panel to the WordPress Admin navigation menu. Right now, this function is merely a standalone function. You need to tell WordPress about it and give it a menu position.

To do this, you will create a new function and use the add_submenu_page() function to register the new panel. The add_submenu_page() function exists to enable you to insert new WordPress Admin pages under top-level navigation items. It takes six parameters:

  • $parent. The filename of the parent page. In this case, you are using plugins.php, which is the page that controls the Plugins top-level navigation item. Others might be dashboard.php, edit.php, and so on.
  • $page_title. The name of the page you want to add.
  • $menu_title. How the page will be displayed in the navigation.
  • $access_level A capability synonymous with the permission level that should have access (such as edit_options for the blog admin).
  • $handle. A unique text string (“handle”) to identify your menu item.
  • $callback. The function that is handling the initialization/execution of this page.

Finally, you’ll want to plug that function into the menu using the admin_menu action, as shown below:

[html] function copyright_notices_admin_page() {
add_submenu_page( ‘plugins.php’,’Copyright Notices Configuration’,
‘Copyright Notices Configuration’, ‘manage_options’, ‘copyright-notices’
‘copyright_notices_admin’);
}
add_action(‘admin_menu’, ‘copyright_notices_admin_page’);[/html]

As an alternative to the add_submenu_page() function, you can use one of the wrapper functions that WordPress provides around this function. These alternative functions are listed below:

Function Name: Function Syntax: Function Description:
add_management_
page()
add_management_page(‘Name of
Plugin’, ‘Menu Title’, ‘capability’,
‘handle’, callback);
Adds a submenu page under the
Tools primary navigation.
add_options_page() add_options_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the
Settings primary navigation.
add_theme_page() add_theme_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the
Appearance primary navigation.
add_users_page() add_users_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the
Users primary navigation.
add_dashboard_
page()
add_dashboard_page(‘Name of
Plugin’, ‘Menu Title’, ‘capability’,
‘handle’, callback);
Adds a submenu page under the
Dashboard primary navigation.
add_posts_page() add_posts_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the Posts
primary navigation.
add_media_page() add_media_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the
Media primary navigation.
add_links_page() add_links_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the Links
primary navigation.
add_pages_page() add_pages_page(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback);
Adds a submenu page under the
Pages primary navigation.
add_comments_
page()
add_comments_page(‘Name of
Plugin’, ‘Menu Title’, ‘capability’,
‘handle’, callback);
Adds a submenu page under the
Comments primary navigation.
add_page_menu() add_page_menu(‘Name of Plugin’,
‘Menu Title’, ‘capability’, ‘handle’,
callback, ‘Custom icon URL’);
Adds a new primary navigation menu
item with the added benefit of being
able to specify an Icon for the menu.
If no icon is specified, a default will
be used.

About the Author: Bernard Aybout (Virii8)

Avatar of Bernard Aybout (Virii8)
I am a dedicated technology enthusiast with over 45 years of life experience, passionate about computers, AI, emerging technologies, and their real-world impact. As the founder of my personal blog, MiltonMarketing.com, I explore how AI, health tech, engineering, finance, and other advanced fields leverage innovation—not as a replacement for human expertise, but as a tool to enhance it. My focus is on bridging the gap between cutting-edge technology and practical applications, ensuring ethical, responsible, and transformative use across industries. MiltonMarketing.com is more than just a tech blog—it's a growing platform for expert insights. We welcome qualified writers and industry professionals from IT, AI, healthcare, engineering, HVAC, automotive, finance, and beyond to contribute their knowledge. If you have expertise to share in how AI and technology shape industries while complementing human skills, join us in driving meaningful conversations about the future of innovation. 🚀