Creating a WordPress Plugin Admin Page
I have covered building WordPress plugin with database queries before but previously, my plugin did not require a special plugin page in the Administration section. Since this is a common use case, I wanted to go through these steps while making a sample WP plugin that explores the users you have saved in your blog. Our plugin will simply grab the wp_users mySQL table and dump it into the plugin page with HTML table markup. I will include special JS and CSS files, a jQuery table plugin, to give the table some rich features.
First lets start with some error debugging. When WordPress plugins fail or have errors, you often do not have visibility into the problem. The following function can be used to grab any plugin activation errors and send them to a file in your plugins folder:
Now, there are a few options when making a WordPress Plugin page. First, you need to decide where to put the link to the page. It could be a top level menu link like Posts, Media, Appearance, etc or it could go under an already created menu like Settings. Next, I could make the page using a function in our main plugin file or I could use a separate PHP file. Here’s how you make a sub-menu link to a page that is rendered using a function:
While this is really simple, I will be loading custom JS, CSS, and querying the database on our backend page so I prefer to actually use a separate PHP file. Also, I am not using this page for plugin settings or options so I prefer to have a top level menu link. Here is how to do that:
Here is the WordPress Plugin: WP Database Explorer.
Build an Option Panel for your WordPress Plugin
Building your first WordPress plugin
WordPress Settings API Tutorial