We’re going to cover creating a working WordPress options page, without using the Settings API.
I don’t like the WordPress Settings API. And every time we talk about writing about it, I start whining like the most annoying child you can imagine. I whine because the Settings API is the most official way to make admin options pages in WordPress, which is an important thing to do for both public and private plugins. But to put it kindly, I find the WordPress Settings API baffling and more than a little bit quirky.
But there are parts to making options pages that don’t really involve the Settings API. And in fact, you don’t ever need to use it at all. Today we’re going to describe how to create an admin options page, and how to save a site-wide option—but without using the Settings API.
One more thing before we get started. If you’re looking to learn WordPress development, we’ve written the best guide to it out there:
The Best Way to Learn WordPress Development
Get Up and Running Today!
Up and Running is our complete “learn WordPress development” course. Now in its updated and expanded Third Edition, it’s helped hundreds of happy buyers learn WordPress development the fast, smart, and thorough way.
I did it that way
first i check if post is not empty.
if (!empty($_POST))
{
if (! isset( $_POST[‘name_of_nonce_field’] ) || ! wp_verify_nonce( $_POST[‘name_of_nonce_field’], ‘name_of_my_action’ ) )
{
print ‘Sorry, your nonce did not verify.’;
exit;
}
}
….form….
echo wp_nonce_field( ‘name_of_my_action’, ‘name_of_nonce_field’ );
…/form….
Hey Jason!
ACF is great, but we have to be careful.
Using ACF you can…
– Increase by 173% to render page
– Increase by 14% your number of queries
– Increase by 26% memory usage
You really should consider the advantages and disadvantages of using ACF.
See ya!
Hi there!
You are executing
check_admin_referer
without knowing that the request was a POST. This if-logic will effectively prevent all users from ever reaching the option page.Sorry if I have made a mistake and my point is incorrect.
Nice article on a different approach although!
No offense! Settings API is not pretty even tedious, but your way is worse. The Options page creating with Settings API is pluginable, extensible and flexiable, imagine that you created a plugin and an options page for this plugin, then other users or developers want to add extra settings fields or sections to the options page, it’s impossible by your way unless modify your code directly, but with Settings API, we can add/remove/modify a settings sections or fields without modify original file/codes.
I wish I saw this article before…
I am using the setting API hoping that it will keep my admin updated with WP versions
BUT, its complex, simply the wrong way to go.
Soon I will replace using this article to hold my hand…
BIG LIKE and thanks
Thank you for this tut man …very helpful
It is a useful article. How to add the tabbed setting pages for settings panel built with wordpress settings API?
thank you!. i’d rather sanitize teh data myself then having to comprehend the settings api. i have 8 yrs of php and for some reason i cant wrap my head around learning the settings api.
I’m not a huge fan of doing settings pages “The WordPress Way” either. That said, skipping register_setting(), and any sanitization of POST data at all, is a security risk, and is not a step worth skipping.
Nice intro article.
With WP4 however, it’s time to switch to Customizer API, it’s way simplier and allows preview changes while making them.
The customizer’s great for visual things. But it’s hardly a complete one-for-one replacement with other ways to give a plugin feedback about how it should behave.