Title: register_setting
Published: April 25, 2014
Last modified: February 24, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#wp--skip-link--target)

Registers a setting and its data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#parameters)󠁿

 `$option_group`stringrequired

A settings group name. Should correspond to an allowed option key name.
 Default
allowed option key names include `'general'`, `'discussion'`, `'media'`, `'reading'`,`'
writing'`, and `'options'`.

`$option_name`stringrequired

The name of an option to sanitize and save.

`$args`arrayoptional

Data used to describe the setting when registered.

 * `type` string
 * The type of data associated with this setting.
    Valid values are `'string'`, `'
   boolean'`, `'integer'`, `'number'`, `'array'`, and `'object'`.
 * `label` string
 * A label of the data attached to this setting.
 * `description` string
 * A description of the data attached to this setting.
 * `sanitize_callback` callable
 * A callback function that sanitizes the option’s value.
 * `show_in_rest` bool|array
 * Whether data associated with this setting should be included in the REST API.
   
   When registering complex settings, this argument may optionally be an array with
   a `'schema'` key.
 * `default` mixed
 * Default value when calling `get_option()`.

Default:`array()`

## 󠀁[Source](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#source)󠁿

    ```php
    function register_setting( $option_group, $option_name, $args = array() ) {
    	global $new_allowed_options, $wp_registered_settings;

    	/*
    	 * In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`.
    	 * Please consider writing more inclusive code.
    	 */
    	$GLOBALS['new_whitelist_options'] = &$new_allowed_options;

    	$defaults = array(
    		'type'              => 'string',
    		'group'             => $option_group,
    		'label'             => '',
    		'description'       => '',
    		'sanitize_callback' => null,
    		'show_in_rest'      => false,
    	);

    	// Back-compat: old sanitize callback is added.
    	if ( is_callable( $args ) ) {
    		$args = array(
    			'sanitize_callback' => $args,
    		);
    	}

    	/**
    	 * Filters the registration arguments when registering a setting.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array  $args         Array of setting registration arguments.
    	 * @param array  $defaults     Array of default arguments.
    	 * @param string $option_group Setting group.
    	 * @param string $option_name  Setting name.
    	 */
    	$args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name );

    	$args = wp_parse_args( $args, $defaults );

    	// Require an item schema when registering settings with an array type.
    	if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) {
    		_doing_it_wrong( __FUNCTION__, __( 'When registering an "array" setting to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.4.0' );
    	}

    	if ( ! is_array( $wp_registered_settings ) ) {
    		$wp_registered_settings = array();
    	}

    	if ( 'misc' === $option_group ) {
    		_deprecated_argument(
    			__FUNCTION__,
    			'3.0.0',
    			sprintf(
    				/* translators: %s: misc */
    				__( 'The "%s" options group has been removed. Use another settings group.' ),
    				'misc'
    			)
    		);
    		$option_group = 'general';
    	}

    	if ( 'privacy' === $option_group ) {
    		_deprecated_argument(
    			__FUNCTION__,
    			'3.5.0',
    			sprintf(
    				/* translators: %s: privacy */
    				__( 'The "%s" options group has been removed. Use another settings group.' ),
    				'privacy'
    			)
    		);
    		$option_group = 'reading';
    	}

    	$new_allowed_options[ $option_group ][] = $option_name;

    	if ( ! empty( $args['sanitize_callback'] ) ) {
    		add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] );
    	}
    	if ( array_key_exists( 'default', $args ) ) {
    		add_filter( "default_option_{$option_name}", 'filter_default_option', 10, 3 );
    	}

    	/**
    	 * Fires immediately before the setting is registered but after its filters are in place.
    	 *
    	 * @since 5.5.0
    	 *
    	 * @param string $option_group Setting group.
    	 * @param string $option_name  Setting name.
    	 * @param array  $args         Array of setting registration arguments.
    	 */
    	do_action( 'register_setting', $option_group, $option_name, $args );

    	$wp_registered_settings[ $option_name ] = $args;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/option.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/option.php#L2996)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/option.php#L2996-L3091)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#hooks)󠁿

 [do_action( ‘register_setting’, string $option_group, string $option_name, array $args )](https://developer.wordpress.org/reference/hooks/register_setting/)

Fires immediately before the setting is registered but after its filters are in 
place.

 [apply_filters( ‘register_setting_args’, array $args, array $defaults, string $option_group, string $option_name )](https://developer.wordpress.org/reference/hooks/register_setting_args/)

Filters the registration arguments when registering a setting.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#related)󠁿

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  | 
| [_deprecated_argument()](https://developer.wordpress.org/reference/functions/_deprecated_argument/)`wp-includes/functions.php` |

Marks a function argument as deprecated and inform when it has been used.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)`wp-includes/plugin.php` |

Adds a callback function to a filter hook.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#)

| Used by | Description | 
| [register_initial_settings()](https://developer.wordpress.org/reference/functions/register_initial_settings/)`wp-includes/option.php` |

Registers default settings available in WordPress.

  | 
| [add_option_update_handler()](https://developer.wordpress.org/reference/functions/add_option_update_handler/)`wp-admin/includes/deprecated.php` |

Register a setting and its sanitization callback

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Added the `label` argument. | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | `$new_whitelist_options` was renamed to `$new_allowed_options`.
 Please consider writing more inclusive code. | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | `$args` can be passed to set flags on the setting, similar to `register_meta()`. | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | The `privacy` option group was deprecated. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | The `misc` option group was deprecated. | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

[Show 1 more](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#)

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 12 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-3050)
 2.    [Bence Szalai](https://profiles.wordpress.org/grapestain/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-3050)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3050)
     Vote results for this note: 10[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3050)
 4.  Some notes about the elements in the **`$args`** parameter:
 5.  `'type'`:
 6.   * Only has an effect if `'show_in_rest'` is set. So if `'show_in_rest'` is false
        or not part of `$args`, do not bother with setting a `'type'`.
      * Only used by the REST API to define the schema associated with the setting 
        and to implement sanitization over the REST API.
      * Has no effect for the workings of the Admin pages or the way the Setting is
        handled by the Options API. (I.e.: although probably you shouldn’t, it is possible
        to submit for example a string value for a setting from the Admin forms that
        has the `'type'` set to `"boolean"`. WP will not complain and will store the
        value in the options table. It would however cause issues with the REST API,
        so be careful!)
      * On top of those listed in this page, it also accepts values such as: `'array'`
        and `'object'`.
 7.  `'description'`:
 8.   * Only has an effect if `'show_in_rest'` is set. So if `'show_in_rest'` is false
        or not part of `$args`, do not bother with setting a `'description'`.
      * Only used by the REST API.
 9.  `'default'`:
 10.  * Affects both the Options API (e.g. `get_option()`) and the REST API.
 11. In conclusion: if you do not plan to include your setting in the REST API, it 
     is perfectly enough to only set the `'default'` and the `'sanitize_callback'` 
     elements in the $args array. Anything else would be ignored anyway.
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D3050%23feedback-editor-3050)
 13.  [Skip to note 13 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-2503)
 14.   [Farhan Noor](https://profiles.wordpress.org/farhannoor/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-2503)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-2503)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-2503)
 16.     ```php
         /**
         * Registers a text field setting for WordPress 4.7 and higher.
         **/
         function register_my_setting() {
         	$args = array(
         			'type' => 'string', 
         			'sanitize_callback' => 'sanitize_text_field',
         			'default' => NULL,
         			);
             register_setting( 'my_options_group', 'my_option_name', $args ); 
         } 
         add_action( 'admin_init', 'register_my_setting' );
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D2503%23feedback-editor-2503)
 18.  [Skip to note 14 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-2488)
 19.   [Andy Schmidt](https://profiles.wordpress.org/andy-schmidt/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-2488)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-2488)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-2488)
 21. The sanitize **callback will be launched twice**! Therefore, if sanitizing involves
     any performance critical or singular tasks, then measures must be taken in the
     callback to avoid duplicate execution of those portions.
 22.     ```php
         const	PLUGIN_SLUG =	'MyPlugin';
     
         /*
          *	Setup Plug-In Hooks (Namespaced Example)
          */
         \add_action( 'wp_loaded', __NAMESPACE__.'\on_wp_loaded' );
     
         if ( is_blog_admin() ) {
         	\register_activation_hook( __FILE__,  __NAMESPACE__.'\on_activate' );
         	\register_deactivation_hook( __FILE__,  __NAMESPACE__.'\on_deactivate' );
     
         	\add_action( 'admin_menu', __NAMESPACE__.'\on_admin_menu' );
         	\add_action( 'admin_init', __NAMESPACE__.'\on_admin_init' );
         	\add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__.'\action_links' );
         }
         return;
     
         /*
          *	Add custom options to whitelist, allowing valiated settings to be saved by form.
          */
         function on_admin_init(): void 
         {
         	\register_setting( PLUGIN_SLUG, PLUGIN_SLUG, [ 'sanitize_callback' => __NAMESPACE__.'\sanitize_settings' ] ); 
         }
     
         /*
          *	Sanitize the form input.
          */
         function sanitize_settings( $input = NULL ):  
         {
         	// Detect multiple sanitizing passes.
         	// Accomodates bug: https://core.trac.wordpress.org/ticket/21989
         	static $pass_count = 0; $pass_count++;
     
         	if ( $pass_count <= 1 ) {
         		// Handle any single-time / performane sensitive actions.
     
         	}
     
         	// Insert regular santizing code here.
         }
         ```
     
 23.  * As pointed out by Andy Schmidt the function defined as sanitize_callback will
        be launched twice, however – at least according to my tests on v4.9.9 – it 
        is only called twice for the first time the setting is submitted and added 
        to the options table in the database. Subsequent updates to the setting execute
        the sanitize_callback function only once. So unless you are performing something
        really-really-really heavy operation to sanitize, there’s no need to worry 
        about it, as any workarounds would only save 1 occasion of call to the function
        per site per plugin installation.
      * [Bence Szalai](https://profiles.wordpress.org/grapestain/) [7 years ago](https://developer.wordpress.org/reference/functions/register_setting/#comment-3051)
      * A small and very important note remains: When the function is executed the 
        first time, the output will be considered as input to the function the second
        time
      * [Mohamed Hamdy](https://profiles.wordpress.org/mohamdy/) [2 years ago](https://developer.wordpress.org/reference/functions/register_setting/#comment-6998)
 24.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D2488%23feedback-editor-2488)
 25.  [Skip to note 15 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-3094)
 26.   [Corey Salzano](https://profiles.wordpress.org/salzano/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-3094)
 27. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3094)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3094)
 28. If you plan to use your setting in the REST API, use both the `rest_api_init` 
     and `admin_init` hooks when calling `register_setting()` instead of just `admin_init`.
     The `show_in_rest` argument is ineffective when hooked into `admin_init` alone.
 29.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D3094%23feedback-editor-3094)
 30.  [Skip to note 16 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-1290)
 31.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-1290)
 32. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-1290)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-1290)
 33. **Basic Example**
 34.     ```php
         /**
          * Registers a setting.
          */
         function wpdocs_register_my_setting() {
         	register_setting( 'my_options_group', 'my_option_name', 'intval' ); 
         } 
         add_action( 'admin_init', 'wpdocs_register_my_setting' );
         ```
     
 35.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D1290%23feedback-editor-1290)
 36.  [Skip to note 17 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-3225)
 37.   [Ian Dunn](https://profiles.wordpress.org/iandunn/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-3225)
 38. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3225)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-3225)
 39. If you want the setting to appear in the `wp-json/wp/v2/settings` endpoint, you’ll
     need to call `register_setting()` on the `rest_api_init` action, in addition to
     the normal `admin_init` action.
 40.     ```php
         add_action( 'admin_init',    'foo_register_settings' );
         add_action( 'rest_api_init', 'foo_register_settings' );
     
         function foo_register_settings() {
         	register_setting(
         		'foo',
         		'foo_my_setting',
         		array(
         			'type'              => 'string',
         			'show_in_rest'      => true,
         			'sanitize_callback' => 'sanitize_text_field',
         		)
         	);
         }
         ```
     
 41.  * Just to add to this, you will also need to use the `rest_api_init` action if
        you’re using the JavaScript method for saving settings in `wp.api.models` (
        since behind the scenes it also uses the same endpoint)
      * [Benjamin Intal](https://profiles.wordpress.org/bfintal/) [3 years ago](https://developer.wordpress.org/reference/functions/register_setting/#comment-6582)
      * calling `[add_settings_section()](https://developer.wordpress.org/reference/functions/add_settings_section/)`
        when using the `rest_api_init` hook results in `Fatal error: Uncaught Error:
        Call to undefined function [add_settings_section()](https://developer.wordpress.org/reference/functions/add_settings_section/)`(
        environment: Studio for WordPress / WordPress version 6.8.1)
      * [dj.cowan](https://profiles.wordpress.org/djcowan/) [9 months ago](https://developer.wordpress.org/reference/functions/register_setting/#comment-7362)
 42.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D3225%23feedback-editor-3225)
 43.  [Skip to note 18 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-6848)
 44.   [Gerard Reches](https://profiles.wordpress.org/gerardreches/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-6848)
 45. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-6848)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-6848)
 46. Notice that the `sanitization_callback` of all the registered settings that share
     the same `$option_group` will be executed when saving that option group.
 47. This sounds obvious, but notice that it will also happen even when the settings
     that belong to this group are not present in the current page but in a different
     one.
 48. For example if we have the following option pages and settings:
 49. **admin.php?page=settings_page_1** containing the **optionA** form
      **admin.php?
     page=settings_page_2** containing the **optionB** form
 50. Where each setting has been registered with their own `register_setting()` in 
     different files and being output in different pages but the same $option_group
     string has been used for both of them.
 51. Saving the page **admin.php?page=settings_page_1** will not only trigger the `
     sanitization_callback` from **optionA**, but also the `sanitization_callback` 
     from **optionB**.
 52.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D6848%23feedback-editor-6848)
 53.  [Skip to note 19 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-4127)
 54.   [Suman](https://profiles.wordpress.org/sumanm/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-4127)
 55. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-4127)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-4127)
 56. An example of array settings. if you want to save an array in settings and also
     show the array setting to appear in the `wp-json/wp/v2/settings` endpoint, then
     you have to register show_in_rest schema.
 57.     ```php
         add_action( 'admin_init',    'wpdocs_foo_register_settings' );
         add_action( 'rest_api_init', 'wpdocs_foo_register_settings' );
         function wpdocs_foo_register_settings() {
         	register_setting( 'general_setting', 'id' );
         	register_setting( 'general_setting', 'order' );
         	register_setting(
         		'general_setting',
         		'slider-data',
         		array(
         			'show_in_rest' => array(
         				'name' => 'images_slide',
         				'schema' => array(
         					'type'  => 'array',
         					'items' => array(
         						'id'    => 'string',
         						'order' => 'string',
         					),
         				),
         			),
         			'type' => 'array',
         			'sanitize_callback' => array( $this, 'wpdocs_admin_post_save_data' ),
         		)
         	);
         }
         ```
     
 58.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D4127%23feedback-editor-4127)
 59.  [Skip to note 20 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-5289)
 60.   [Cloud Stone](https://profiles.wordpress.org/cloudinstone/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-5289)
 61. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-5289)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-5289)
 62. Example for `object` and `array` types:
 63.     ```php
         register_setting(
         	'dp_example_settings_group',
         	'dp_example_array_settings',
         	array(
         		'type'         => 'object',
         		'default'      => array(
         			'A',
         			'B',
         			'C',
         		),
         		'show_in_rest' => array(
         			'schema' => array(
         				'type'  => 'object',
         				'items' => array(
         					'type' => 'string',
         				),
         			),
         		),
         	)
         );
     
         register_setting(
         	'dp_example_settings_group',
         	'dp_example_object_settings',
         	array(
         		'type'         => 'object',
         		'default'      => array(
         			'some_str' => 'A',
         			'some_int' => 3,
         		),
         		'show_in_rest' => array(
         			'schema' => array(
         				'type'       => 'object',
         				'properties' => array(
         					'some_str' => array(
         						'type' => 'string',
         					),
         					'some_int' => array(
         						'type' => 'integer',
         					),
         				),
         			),
         		),
         	)
         );
         ```
     
 64.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D5289%23feedback-editor-5289)
 65.  [Skip to note 21 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-5349)
 66.   [kyajfx](https://profiles.wordpress.org/kyajfx/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-5349)
 67. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-5349)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-5349)
 68.     ```php
         // Registering the field
         function wpdocs_add_option_field_to_general_admin_page() {
     
         	register_setting( 'general', 'Field_Name_To_Add' );
     
         	add_settings_field( 
         		'field_id-to-add', 
         		'Field Name To Display', 
         		'wpdocs_setting_callback_function', //Function to Call
         		'general', 
         		'default', 
         		array( 
         			'id' => 'field_id-to-add', 
         			'option_name' => 'Field_Name_To_Add' 
         		)
         	);
         }
     
         // Adding options to registered field
         add_action( 'admin_menu', 'wpdocs_add_option_field_to_general_admin_page' ); // CallBack Function
     
         function wpdocs_setting_callback_function( $val ) {
         	$id = $val['id'];
         	$option_name = $val['option_name'];
         	?>
         	<input 
         		type="tel" //this can be any HTML input type: date, number, text etc.
         		name="<?php echo esc_attr( $option_name ) ?>"
         		id="<?php echo esc_attr( $id ) ?>" 
         		value="<?php echo esc_attr( get_option( $option_name ) ) ?>" // Displays the value stored in DB
         	/> 
         	<?php
         }
         ```
     
 69.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D5349%23feedback-editor-5349)
 70.  [Skip to note 22 content](https://developer.wordpress.org/reference/functions/register_setting/?output_format=md#comment-content-7180)
 71.   [Tunn](https://profiles.wordpress.org/iuriem/)  [  1 year ago  ](https://developer.wordpress.org/reference/functions/register_setting/#comment-7180)
 72. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-7180)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%23comment-7180)
 73. **Avoid duplicate execution of sanitizing callback!!!**
 74. What to do (two steps):
 75. 1. Initialize your setting before to register it.
 76.     ```php
         // Example for a plugin.
         function activate_my_plugin() {
             add_option( "my-option", "", "", false );
         }
         register_activation_hook( __FILE__, "activate_my_plugin" );
         ```
     
 77. 2. Register the setting a) without the “_default_” parameter **OR** b) with the
     not-empty “_default_” parameter (so, not “” and not []).
 78.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F%3Freplytocom%3D7180%23feedback-editor-7180)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_setting%2F)
before being able to contribute a note or feedback.