Settings API in 9 Steps

I’m going to update my DX Plugin Base script soon with sample code, but Settings API are something that needs a few lines of text too.

There are several good resources for that, such as:

http://codex.wordpress.org/Settings_API

http://ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/

http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-2-sections-fields-and-settings/ (awesome btw)

But for the very quick overview of what to be done, that’s needed:

  1. hook to admin_init with a function registering settings
  2. call register_setting to reserve a slot in the DB where the setting is to be stored (setting name for DB, how is it stored in DB)
  3. call add_setting_section to create a section for settings (setting name, setting title, callback func, page on which to display – existing slug or a new one)
  4. call add_setting_field to create a simple setting (field ID, field name, callback, page name, section name)
  5. in the callback function for a field, get the option (param 2 from step 2) and use it as a value from the array, such as $option_arr[specific_field]
  6. in the template, create a form with post submit with an action of options.php
  7. call settings_fields with the parameter from register_setting
  8. call do_settings_sections with the slug of the page where you display it
  9. save the project

Mario Peshev is a serial martech entrepreneur, global business advisor, angel investor, and author, famous for launching a top 20 enterprise WordPress consultancy and authoring the modern startup formation book, “MBA Disrupted.”

His digital footprint includes 25 years of creating and scaling technical solutions, building and growing digital teams, starting and growing companies from zero to seven figures, acquiring and selling assets and businesses, and investing in global startups like beehiiv, doola, the Stacked Marketer, Alcatraz, SeedBlink.

Peshev spent over 10,000 hours in consulting and training activities for organizations like VMware, SAP, Software AG, CERN, Saudi Aramco since 2006. His books and guides are references in over 30 universities in North America, Europe, and Asia.


Follow Mario on social:

Latest Editions:

Browse by Category

Latest Answers: