register_setting

Advertisement

Summery Summery

Registers a setting and its data.

Syntax Syntax

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

Parameters Parameters

$option_group

(string) (Required) A settings group name. Should correspond to a whitelisted option key name. Default whitelisted option key names include 'general', 'discussion', 'media', 'reading', 'writing', 'misc', 'options', and 'privacy'.

$option_name

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

$args

(array) (Optional) 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'.
  • '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 value: array()

Source Source

File: wp-includes/option.php

		)
	);

	register_setting(
		'writing',
		'use_smilies',
		array(
			'show_in_rest' => true,
			'type'         => 'boolean',
			'description'  => __( 'Convert emoticons like :-) and :-P to graphics on display.' ),
			'default'      => true,
		)
	);

	register_setting(
		'writing',
		'default_category',
		array(
			'show_in_rest' => true,
			'type'         => 'integer',
			'description'  => __( 'Default post category.' ),
		)
	);

	register_setting(
		'writing',
		'default_post_format',
		array(
			'show_in_rest' => true,
			'type'         => 'string',
			'description'  => __( 'Default post format.' ),
		)
	);

	register_setting(
		'reading',
		'posts_per_page',
		array(
			'show_in_rest' => true,
			'type'         => 'integer',
			'description'  => __( 'Blog pages show at most.' ),
			'default'      => 10,
		)
	);

	register_setting(
		'discussion',
		'default_ping_status',
		array(
			'show_in_rest' => array(
				'schema' => array(
					'enum' => array( 'open', 'closed' ),
				),
			),
			'type'         => 'string',
			'description'  => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ),
		)
	);

	register_setting(
		'discussion',
		'default_comment_status',
		array(
			'show_in_rest' => array(
				'schema' => array(
					'enum' => array( 'open', 'closed' ),
				),
			),
			'type'         => 'string',
			'description'  => __( 'Allow people to submit comments on new posts.' ),
		)
	);
}

/**
 * Registers a setting and its data.

Advertisement

Changelog Changelog

Changelog
Version Description
4.7.0 $args can be passed to set flags on the setting, similar to register_meta().
2.7.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.