Codeable info

Creating a WordPress Admin Page Plugin

Posted on by in WordPress Tutorials

In this tutorial we will create an easy-to-use admin page for users who may not appreciate the complexity of the stock WordPress admin page. Our new admin page will be an add-on to the current admin section rather than a replacement for it. We are simply adding a new alternate, easy-to-use admin page for managing pages and posts as those are two of the most used actions for beginning WordPress users. The goal of this plugin’s admin page is to lessen the learning curve for the average user to get started with WordPress. But, as stated earlier, we will also be leaving the more complex options in place for when they are needed by more advanced users or for when the beginner learns more about WordPress. Things you will learn in this tutorial will include: creating a plugin, adding menu items to the dashboard, how to enable a WordPress function, creating an admin page and how to activate plugins.

Before you begin, there are some simple prerequisites you should be aware of. For instance, you need to have FTP access. We recommend FileZilla because it’s available on all major software platforms, it’s free and it is not CPU heavy. You can download a copy of FileZilla from filezilla-project.org/download.php. The other prerequisite is to know the basics of WordPress, HTML and PHP — all things that can be learned with some Googling and reading.

Creating a plugin:

1) Using your FTP client, browse to the folder called wp_content/plugins and open it.
2) Add a new PHP file in the plugins directory and enter the following content into the file:

/*
  Plugin Name: WP Easy Admin
  Plugin URI: [Enter the URL of a page that will explain your new plugin to users]
  Description: This plugin makes it easier to manage your WordPress pages and posts.
  Version: 1.00
	Author: Your Name
	Author URI: Your URL
	License: GPL2  - (this is common, but change according to your own license terms)
*/

Okay, now that you have your standard plugin file started, it’s time to add some PHP code! The comment tags in the code above are used to display details in the WordPress admin area regarding your plugin, so be mindful of what you include.

Adding a Menu Option to the WordPress Dashboard

Now we need to create a new menu option in our WordPress dashboard that will take us to our new easy-to-use admin page. To accomplish this, we will use the add_menu_page native WordPress function. We also need to create a new function called “WP_easy_admin”. A nice descriptive function name helps you remember what functions do when you or someone else is maintaining the code down the line. The add_menu_page function is used to create a new top level menu option in the admin sidebar. Here is what your WP_easy_admin PHP function should look like:

function WP_easy_admin() {
add_menu_page(‘WP Easy Admin’,'Easy Admin’,'manage_options’,wp_easy_admin’, WPS_easy_admin_pg);
}//end WP_easy_admin  function.

The add_menu_page function has several mandatory parameters, explained below:

  • Title ($page_title) – is what appears in the title tag, here we are using “WP Easy Admin”.
  • Menu Text ($menu_title) – is what actually show up on the new menu button. Here we are using “Easy Admin”.
  • Access ($capability) – Controls who will be able to access the new admin page. In this case we used “manage_options” which means anyone who has permission to manage options will also have access to the new admin page we are creating.
  • URL parameter ($menu_slug) – is what will appear in the URL when clicking on the new menu button. i.e.: admin.php?page=wp_easy_admin
  • Function ($function) – is the name of the function that will call the new admin page. We are naming our function: “WPS_easy_admin_pg”.

The add_menu_page function also has the following optional parameters:

  • Icon URL ($icon_url) – optionally adds a small icon to the left of the menu text in the menu’s button.
  • Position ($position) – optionally tells WordPress where to place the new menu item.

Enabling WordPress Functions:

In WordPress you must create an “action” (a WordPress programming term) to enable functions before you can use them. This is done with another WordPress native function simply called, “add_action”. Therefore, to enable the new WP_easy_admin function you have created, use the following PHP code:

add_action('admin_menu', 'WP_easy_admin');

The add_menu function takes two parameters: the first is the “hook” and the second is the name of the function you want enabled. The “hook” tells WordPress where to add the new function and the function name tells WordPress which function to enable when it reaches the hook in the WordPress initialization process (the process that WordPress goes through whenever a page is loaded).

Creating a New WordPress Admin Page:

Now comes the fun part! It’s time to create the new admin page. To accomplish this, we need to create the function that calls the new page. In our case, we already picked the name above, so we have to call our function “WPS_easy_admin_pg” as in the following example:

WPS_easy_admin_pg() {
?>

WP Easy Admin

 

WP Easy Admin

 

Save your file in the WordPress wp-content/plugins directory. Now you are ready to activate the plugin. The file name should be similar to the plugin name. In our case, we would probably use “wp_easy_admin.php”.

Activating a WordPress Plugin

The next step is to activate the new plugin. Simply go to your WordPress dashboard and click on “Plugins”, then click “activate” under your new plugin’s name.

If you get an error while activating the plugin at this juncture, it means you probably had a typographical mistake somewhere in your PHP file. If you used copy and paste to enter any of the code, you may have unknowingly included some unfriendly characters such as non-standard quotation marks, so start by manually typing in and replacing any funny looking quotation marks and try to activate it again. If that didn’t do it, recheck all of your PHP code for syntax errors or fix whatever the error report said was wrong.

Upon successfully activating a plugin, the words “Plugin activated” should appear towards the top of the page. You should now see a new menu item with the text “Easy Admin” below the other menu items in your main WordPress dashboard. Compare your admin section to the image below to be sure you have done it correctly.

Does your WordPress dashboard look like ours with the new “Easy Admin” menu option? When you click on the new “Easy Admin” option in the dashboard, your page should look like the above image. If it does, congratulations! You have just created a WordPress Plugin! If it was your first time, you are doing great so far, but hang on to your hats because now we need to create the content for the page that does all of the work to enable users to more readily manage pages and posts on their WordPress sites.

To complete your new easy-to-use admin user interface, see part two of this tutorial.

Comments Closed

Codeable info