WordPress Settings Sandbox: A Working Example of the Settings API

A few months ago, I completed a series of articles for Envato called The Complete Guide To The WordPress Settings API.

The purpose of the series was to walkthrough the WordPress Settings API taking a look at sections, settings, fields, and how they all fit together to properly build a WordPress project using menus, tabbed navigation, input elements, and data sanitization all of which interact properly with the WordPress database.

As part of the article, I also provided an open-source project called the WordPress Settings Sandbox that was to serve as a working demonstration of the WordPress Settings API.

The WordPress Settings API Example

Since that time and thanks to several contributors, the project has received a few updates and has also been fully localized. As such, I’m going to officially begin versioning the project and am tagging it as 1.0.

Overall, I’m excited that people have used and contributed to the project considering it was initially written as a simple demonstration for a series of blog posts.

With that said, if you’re just learning the WordPress Settings API, be sure to check it out. If you’re a developer, please consider contributing. It’s a light project and even the smallest of changes can help make this the definitive guide for budding WordPress developers.

13 Comments

I have an example of my own inside of my plugin for learning WordPress plugin dev – http://wordpress.org/extend/plugins/dx-plugin-base/ . It contains sample simple snippets for standard WordPress features.

Hi, do you know if it’s possible to use the settings API in custom menu pages?

Do you still have a tutorial of how to create a plugin panel properly using the settings API? The envato link is no longer live, and I could really use an educated, concise tutorial. Not sure if I am still supposed to use add_menu_page() or if there is a standardized set of settings functions I am not seeing. Would like to avoid coding this plugin panel incorrectly!

Hi Tom
Thanks very much for this series! I was wondering if there is a way to state:

globally so that the $display_options variable can be called in any theme file without the variable being set at the top of the document.

    In Sarah’s 2011 article she does have a function for this but then indicated it doesn’t work in header, sidebar or footer.php. I’m not sure she really explains why that is the case.
    My earlier comment lost the PHP I inserted. The question is basically, can we rather have a function for get_option instead of needing to state the variable at the top of the document as you did in sandbox-theme-options, index.php, display_options = get_option. Sorry if this is badly written.

      This isn’t badly written!

      The question is basically, can we rather have a function for get_option instead of needing to state the variable at the top of the document as you did in sandbox-theme-options, index.php, display_options = get_option

      You could declare a global variable that’s accessible everywhere but I highly recommend against doing that. Using the WordPress API to retrieve the data via the get_option function is exactly what the function is used for.

      Another alternative would be to move the code into a helper class that could retrieve it and echo it, but all that really does is kick the can a little further down the road.

Trackbacks and Pingbacks

This Week In WordPress: Nov. 29, 2012November 26, 2012 at 3:19 pm

[...] WordPress Settings API Example [...]

[...] View article: A Working WordPress Settings API Example – Tom McFarlin [...]

[…] I’ve also released a simple project on GitHub that’s meant to accompany the above series to show a practical application of the Settings […]

[…] bit easier to understand, I’ve written a series that takes a long look at the API as well as an example project that’s available for download for others to study (and to contribute to in order to […]

Leave a Reply

Name and email address are required. Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>