Registering Custom Options
From WordPress Codex:
<php register_setting( $option_group, $option_name, $sanitize_callback ); ?>
Register a setting and its sanitization callback.
This is part of the Settings API, which lets you automatically generate wp-admin settings pages by registering your settings and using a few callbacks to control the output.
This function can also be used to register settings that will be shown on some default WP settings pages like "media"
or "general"
. (As of WordPress 4.1 this function does not save settings if added to the "permalink"
page.) Once the setting is registered you can add it to an existing section withadd_settings_field() or create a new section with add_settings_section() and add it to that.
- $option_group
- (string) (required) A settings group name. Must exist prior to the register_setting call. This must match the group name insettings_fields()
- Default: None
- $sanitize_callback
- (callback) (optional) A callback function that sanitizes the option’s value.
- Default: None
<?php add_settings_section( $id, $title, $callback, $page ); ?>
Add a new section to a settings page.
Settings Sections are the groups of settings you see on WordPress settings pages with a shared heading. In your plugin you can add new sections to existing settings pages rather than creating a whole new page. This makes your plugin simpler to maintain and creates fewer new pages for users to learn. You just tell them to change your setting on the relevant existing 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
- Default: None
<?php add_settings_field( $id, $title, $callback, $page, $section, $args ); ?>
- Register a settings field to a settings page and section.
This is part of the Settings API, which lets you automatically generate wp-admin settings pages by registering your settings and using a few callbacks to control the output.
This function assumes you already know the settings
$page
and the page$section
that the field should be shown on.You MUST register any options used by this function with register_setting() or they won’t be saved and updated automatically.
The callback function needs to output the appropriate html input and fill it with the old value, the saving will be done behind the scenes.
The html input field’s name attribute must match $option_name in register_setting(), and value can be filled using get_option().
This function can also be used to add extra settings fields to the default WP settings pages like media or general. You can add them to an existing section, or use add_settings_section() to create a new section to add the fields to.
- $id
- (string) (required) String for use in the ‘id’ attribute of tags.
- Default: None
- $title
- (string) (required) Title of the field.
- Default: None
- $callback
- (string) (required) Function that fills the field with the desired inputs as part of the larger form. Passed a single argument, the $argsarray. 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 fromdo_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 withadd_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()
- Default: None
- Default: None