Wordpress Settings Api Cheat Sheet

ADVERTISEMENT

WordPress Settings API CheatSheet — Short Version
Kenneth John Odle — techblog.kjodle.net
Unless otherwise noted, all parameters are required.
v. 1.0 — 2015.07.15
add_submenu_page(
add_settings_section(
$parent_slug,
Which menu item this panel should appear under.
$id,
For use in HTML tags. Must match
add_settings_field($section).
$page_title,
Appears at top of options page in
tags.
<h2>
$title,
Appears at top of section as an
$menu_title,
Appears in menu in admin sidebar.
<h3>.
$callback,
Function to echo output.
$capability,
Users must be able to do this to access these options.
$page
Must match
and
do_settings_sections($page)
$menu_slug,
Appears in URL
add_settings_field($page).
$function
Optional. A function that outputs the content for the page.
)
)
creates a section of settings on your options page. Optional if only
add_settings_section()
adds an options page for a plugin under the menu item in
add_submenu_page()
a handful of settings are needed.
. If you need to add a top-level options page, use
instead.
$parent_slug
add_menu_page()
Hook this in the
init.
admin_menu
add_settings_field(
$id,
For use in HTML tags
register_setting(
$title,
Displayed to left of option input
$option_group,
Must match
settings_field($option_group).
$callback,
Function that fills the field with the desired inputs as part
$option_name,
The name of the option stored in the database.
of the larger form. The
and
of the input should
name
id
$sanitize_callback
Optional. A function to sanitize inputs.
match the
given to this function. This information can
$id
)
be contained as an array in the options
parameter.
$args
registers a settings ($option_name) in the
table.
register_setting()
wp-options
$page,
Must match
(for plugins)
do_settings_sections($page)
and
.
add_settings_section($page)
$section,
Optional. Must match
.
add_settings_section($id)
settings_fields(
$args
Optional. Additional arguments in an
that are
array
$option_group
Must match
register_settings($option_group).
passed to the
function. The
$callback
'label_for'
)
key/value pair can be used to format the field title like so:
.
outputs hidden bits that make the Settings API work. Include it after your
<label for="value">$title</label>
settings_fields()
opening
tag.
)
<form>
creates individual settings within a settings section on your options
add_settings_field()
do_settings_sections(
page. You must register any options used by this function with
or they
register_setting()
$page
Must match
and
won't be saved and updated automatically.
add_settings_section($page)
The callback function needs to output the appropriate html
and fill it with the old
add_settings_field($page).
input
value; the saving will then be done behind the scenes.
)
The html
field's
attribute must match in
input
name
outputs all the input fields created with
.
do_settings_sections()
add_settings_field()
, and value can be filled using
.
register_setting($option_name)
get_option()
Include it after the
call.
settings_fields()

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go