WordPress: Creating Theme Options in Admin

Categorised in:

These are the WP functions in the Settings API:

Register Setting

register_setting( string $option_group, string $option_name, array $args = array() )

$option_group (string) (Required) A settings group name. Should correspond to a whitelisted option key name. Default whitelisted option key names include “general,” “discussion,” and “reading,” among others.

$option_name (string) (Required) The name of an option to sanitize and save.

$args (array) (Optional) Data used to describe the setting when registered.

Default value: array()

add_settings_field( $id, $title, $callback, $page, $section, $args )

$id(string) (required) String for use in the ‘id’ attribute of tags.Default: None

$title(string) (required) Title of the field.Default: None

$callback(callback) (required) Function that fills the field with the desired inputs as part of the larger form. Passed a single argument, the $args array. Name and id of the input should match the $id given to this function. The function should echo its output.Default: None

$page(string) (required) The menu page on which to display this field. Should match $menu_slug from add_theme_page() or from do_settings_sections().Default: None

$section(string) (optional) The section of the settings page in which to show the box (default or a section you added with add_settings_section(), look at the page in the source to see what the existing ones are.)Default: default

$args(array) (optional) Additional arguments that are passed to the $callback function. The ‘label_for’ key/value pair can be used to format the field title like so: <label for=”value”>$title</label>.Default: array()

add_settings_section( $id, $title, $callback, $page )

$id(string) (required) String for use in the ‘id’ attribute of tags.Default: None

$title(string) (required) Title of the section.Default: None

$callback(string) (required) Function that fills the section with the desired content. The function should echo its output.Default: None

$page(string) (required) The menu page on which to display this section. Should match $menu_slug from Function Reference/add theme page if you are adding a section to an ‘Appearance’ page, or Function Reference/add options page if you are adding a section to a ‘Settings’ page.Default: None

settings_fields( $option_group )

$option_group(string) (required) A settings group name. This should match the group name used in register_setting().Default: None

do_settings_sections( $page )

$page(string) (required) The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section().

do_settings_fields( $page, $section )

$page(string) (required) Slug title of the admin page whose settings fields you want to show. This should match the page name used in add_settings_section().Default: None

$section(string) (required) Slug title of the settings section whose fields you want to show. This should match the section ID used in add_settings_section().Default: None

Leave a Reply

Your email address will not be published. Required fields are marked *

Tagged with ,

Available Tags

api finder foreach functions json oscommerce php programming sudoku themes webp wordpress