# register_theme_feature()

URL: https://chugunov.pro/api-wordpress/functions/register_theme_feature/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.5.0.

## Сигнатура

```php
register_theme_feature( string $feature, array $args = array() ): true|WP_Error
```

## Описание

Это не означает, что активная тема поддерживает данную возможность, — здесь лишь описываются поддерживаемые ею параметры.
См. alsoadd_theme_support()

## Параметры

- `$feature` `string` — обязательный. Имя, однозначно идентифицирующее возможность. Список возможных значений см. в add_theme_support() .
- `$args` `array` — необязательный, по умолчанию `array()`. Data used to describe the theme.
  
  - `type` string The type of data associated with this feature.
  
  Valid values are `'string'`, `'boolean'`, `'integer'`, `'number'`, `'array'`, and `'object'`. Defaults to `'boolean'`.
  
  - `variadic` bool Does this feature utilize the variadic support of [add_theme_support()](https://developer.wordpress.org/reference/functions/add_theme_support/) , or are all arguments specified as the second parameter. Must be used with the "array" type.
  
  - `description` string A short description of the feature. Included in the Themes REST API schema. Intended for developers.
  
  - `show_in_rest` bool|array Whether this feature should be included in the Themes REST API endpoint.
  
  Defaults to not being included. When registering an ‘array’ or ‘object’ type, this argument must be an array with the ‘schema’ key.
  
  - `schema` array Specifies the JSON Schema definition describing the feature. If any objects in the schema do not include the `'additionalProperties'` keyword, it is set to false.
  
  - `name` string An alternate name to be used as the property name in the REST API.
  
  - `prepare_callback` callable A function used to format the theme support in the REST API.
  
  Receives the raw theme support value.
  
  More Arguments from add_theme_support( … $args )Optional extra arguments to pass along with certain features. Default:`array()`
  [Return](#return) true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) True if the theme feature was successfully registered, a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) object if not.
  
  [Source](#source)
  
  ```
  function register_theme_feature( $feature, $args = array() ) {
  global $_wp_registered_theme_features;
  
  if ( ! is_array( $_wp_registered_theme_features ) ) {
  $_wp_registered_theme_features = array();
  }
  
  $defaults = array(
  'type' => 'boolean',
  'variadic' => false,
  'description' => '',
  'show_in_rest' => false,
  );
  
  $args = wp_parse_args( $args, $defaults );
  
  if ( true === $args['show_in_rest'] ) {
  $args['show_in_rest'] = array();
  }
  
  if ( is_array( $args['show_in_rest'] ) ) {
  $args['show_in_rest'] = wp_parse_args(
  $args['show_in_rest'],
  array(
  'schema' => array(),
  'name' => $feature,
  'prepare_callback' => null,
  )
  );
  }
  
  if ( ! in_array( $args['type'], array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
  return new WP_Error(
  'invalid_type',
  __( 'The feature "type" is not valid JSON Schema type.' )
  );
  }
  
  if ( true === $args['variadic'] && 'array' !== $args['type'] ) {
  return new WP_Error(
  'variadic_must_be_array',
  __( 'When registering a "variadic" theme feature, the "type" must be an "array".' )
  );
  }
  
  if ( false !== $args['show_in_rest'] && in_array( $args['type'], array( 'array', 'object' ), true ) ) {
  if ( ! is_array( $args['show_in_rest'] ) || empty( $args['show_in_rest']['schema'] ) ) {
  return new WP_Error(
  'missing_schema',
  __( 'When registering an "array" or "object" feature to show in the REST API, the feature\'s schema must also be defined.' )
  );
  }
  
  if ( 'array' === $args['type'] && ! isset( $args['show_in_rest']['schema']['items'] ) ) {
  return new WP_Error(
  'missing_schema_items',
  __( 'When registering an "array" feature, the feature\'s schema must include the "items" keyword.' )
  );
  }
  
  if ( 'object' === $args['type'] && ! isset( $args['show_in_rest']['schema']['properties'] ) ) {
  return new WP_Error(
  'missing_schema_properties',
  __( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' )
  );
  }
  }
  
  if ( is_array( $args['show_in_rest'] ) ) {
  if ( isset( $args['show_in_rest']['prepare_callback'] )
  && ! is_callable( $args['show_in_rest']['prepare_callback'] )
  ) {
  return new WP_Error(
  'invalid_rest_prepare_callback',
  sprintf(
  /* translators: %s: prepare_callback */
  __( 'The "%s" must be a callable function.' ),
  'prepare_callback'
  )
  );
  }
  
  $args['show_in_rest']['schema'] = wp_parse_args(
  $args['show_in_rest']['schema'],
  array(
  'description' => $args['description'],
  'type' => $args['type'],
  'default' => false,
  )
  );
  
  if ( is_bool( $args['show_in_rest']['schema']['default'] )
  && ! in_array( 'boolean', (array) $args['show_in_rest']['schema']['type'], true )
  ) {
  // Automatically include the "boolean" type when the default value is a boolean.
  $args['show_in_rest']['schema']['type'] = (array) $args['show_in_rest']['schema']['type'];
  array_unshift( $args['show_in_rest']['schema']['type'], 'boolean' );
  }
  
  $args['show_in_rest']['schema'] = rest_default_additional_properties_to_false( $args['show_in_rest']['schema'] );
  }
  
  $_wp_registered_theme_features[ $feature ] = $args;
  
  return true;
  }
  ```
  
  [View all references](https://developer.wordpress.org/reference/files/wp-includes/theme.php/) [View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/theme.php#L3280) [View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/theme.php#L3280-L3385)
  
  [Related](#related) Uses | Description |
  [rest_default_additional_properties_to_false()](https://developer.wordpress.org/reference/functions/rest_default_additional_properties_to_false/)`wp-includes/rest-api.php` | Sets the “additionalProperties” to false by default for all object definitions in the schema.
  |
  [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` | Retrieves the translation of $text.
  |
  [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` | Merges user defined arguments into defaults array.
  |
  [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` | Initializes the error.
  |
  [Show 2 more](#)[Show less](#) Used by | Description |
  [create_initial_theme_features()](https://developer.wordpress.org/reference/functions/create_initial_theme_features/)`wp-includes/theme.php` | Creates the initial theme features when the ‘setup_theme’ action is fired.
  |
  
  [Changelog](#changelog) Version | Description |
  [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |

## Возвращаемое значение

`true|WP_Error` — WP_Error

## Исходный код

Файл: `wp-includes/theme.php:3280`

```php
function register_theme_feature( $feature, $args = array() ) {
	global $_wp_registered_theme_features;

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

	$defaults = array(
		'type'         => 'boolean',
		'variadic'     => false,
		'description'  => '',
		'show_in_rest' => false,
	);

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

	if ( true === $args['show_in_rest'] ) {
		$args['show_in_rest'] = array();
	}

	if ( is_array( $args['show_in_rest'] ) ) {
		$args['show_in_rest'] = wp_parse_args(
			$args['show_in_rest'],
			array(
				'schema'           => array(),
				'name'             => $feature,
				'prepare_callback' => null,
			)
		);
	}

	if ( ! in_array( $args['type'], array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
		return new WP_Error(
			'invalid_type',
			__( 'The feature "type" is not valid JSON Schema type.' )
		);
	}

	if ( true === $args['variadic'] && 'array' !== $args['type'] ) {
		return new WP_Error(
			'variadic_must_be_array',
			__( 'When registering a "variadic" theme feature, the "type" must be an "array".' )
		);
	}

	if ( false !== $args['show_in_rest'] && in_array( $args['type'], array( 'array', 'object' ), true ) ) {
		if ( ! is_array( $args['show_in_rest'] ) || empty( $args['show_in_rest']['schema'] ) ) {
			return new WP_Error(
				'missing_schema',
				__( 'When registering an "array" or "object" feature to show in the REST API, the feature\'s schema must also be defined.' )
			);
		}

		if ( 'array' === $args['type'] && ! isset( $args['show_in_rest']['schema']['items'] ) ) {
			return new WP_Error(
				'missing_schema_items',
				__( 'When registering an "array" feature, the feature\'s schema must include the "items" keyword.' )
			);
		}

		if ( 'object' === $args['type'] && ! isset( $args['show_in_rest']['schema']['properties'] ) ) {
			return new WP_Error(
				'missing_schema_properties',
				__( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' )
			);
		}
	}

	if ( is_array( $args['show_in_rest'] ) ) {
		if ( isset( $args['show_in_rest']['prepare_callback'] )
			&& ! is_callable( $args['show_in_rest']['prepare_callback'] )
		) {
			return new WP_Error(
				'invalid_rest_prepare_callback',
				sprintf(
					/* translators: %s: prepare_callback */
					__( 'The "%s" must be a callable function.' ),
					'prepare_callback'
				)
			);
		}

		$args['show_in_rest']['schema'] = wp_parse_args(
			$args['show_in_rest']['schema'],
			array(
				'description' => $args['description'],
				'type'        => $args['type'],
				'default'     => false,
			)
		);

		if ( is_bool( $args['show_in_rest']['schema']['default'] )
			&& ! in_array( 'boolean', (array) $args['show_in_rest']['schema']['type'], true )
		) {
			// Automatically include the "boolean" type when the default value is a boolean.
			$args['show_in_rest']['schema']['type'] = (array) $args['show_in_rest']['schema']['type'];
			array_unshift( $args['show_in_rest']['schema']['type'], 'boolean' );
		}

		$args['show_in_rest']['schema'] = rest_default_additional_properties_to_false( $args['show_in_rest']['schema'] );
	}

	$_wp_registered_theme_features[ $feature ] = $args;

	return true;
}
```

## История изменений

- 5.5.0 — Introduced.

## Связанные

Использует: [`rest_default_additional_properties_to_false`](https://chugunov.pro/api-wordpress/functions/rest_default_additional_properties_to_false/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/), `WP_Error::__construct`.
Используется в: [`create_initial_theme_features`](https://chugunov.pro/api-wordpress/functions/create_initial_theme_features/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/register_theme_feature/
