Building a Settings Page

Many plugins offer a settings page that allows the user to customize plugin options. The options offered by a settings page varies from a few check boxes, drop downs, or text inputs to multiple advanced editors that allow the user to build data sets, set up forums, or do advanced content management. Although this section focuses on building a simple settings page, you can expand the concept to fill any type of need that your plugin has.

When reduced to a bare minimum, a basic settings page consists of code that displays the page, stores the settings, and adds the page to the WordPress admin menu. The plugin created in this section will give you a solid foundation that you can use to build your own plugin settings pages.

Setting up the plugin structure

The plugin you create in this section is Example: Settings Page. To get started with this plugin, create a new plugins directory named /example-settings-page. All the files for this plugin go in this new directory. That's right, files. We're going to change up the structure a little bit in this plugin by adding multiple plugin files to the plugin directory.

As plugins get larger, having everything in one file quickly becomes hard to manage. A good practice is to separate different functionality into separate files. Similar to the way the init.php file is named because it initializes the plugin, the other files used by the plugin should be named so the purpose of each file is easy to discern when looking at ...

Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.