# shortcode_parse_atts()

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

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

## Сигнатура

```php
shortcode_parse_atts( string $text ): array
```

## Описание

В списке атрибутов имя атрибута является ключом, а значение атрибута — значением в паре ключ/значение. Это упрощает получение атрибутов, поскольку все атрибуты должны быть известны.

## Параметры

- `$text` `string` — обязательный. Список аргументов шорткода.

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

`array`

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

Файл: `wp-includes/shortcodes.php:613`

```php
function shortcode_parse_atts( $text ) {
	$atts    = array();
	$pattern = get_shortcode_atts_regex();
	$text    = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text );
	if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) {
		foreach ( $match as $m ) {
			if ( ! empty( $m[1] ) ) {
				$atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] );
			} elseif ( ! empty( $m[3] ) ) {
				$atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] );
			} elseif ( ! empty( $m[5] ) ) {
				$atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] );
			} elseif ( isset( $m[7] ) && strlen( $m[7] ) ) {
				$atts[] = stripcslashes( $m[7] );
			} elseif ( isset( $m[8] ) && strlen( $m[8] ) ) {
				$atts[] = stripcslashes( $m[8] );
			} elseif ( isset( $m[9] ) ) {
				$atts[] = stripcslashes( $m[9] );
			}
		}

		// Reject any unclosed HTML elements.
		foreach ( $atts as &$value ) {
			if ( str_contains( $value, '<' ) ) {
				if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) {
					$value = '';
				}
			}
		}
	}

	return $atts;
}
```

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

- 6.5.0 — The function now always returns an array, even if the original arguments string cannot be parsed or is empty.
- 2.5.0 — Introduced.

## Связанные

Использует: [`get_shortcode_atts_regex`](https://chugunov.pro/api-wordpress/functions/get_shortcode_atts_regex/).
Используется в: [`wp_ajax_parse_embed`](https://chugunov.pro/api-wordpress/functions/wp_ajax_parse_embed/), [`do_shortcode_tag`](https://chugunov.pro/api-wordpress/functions/do_shortcode_tag/), [`do_shortcode`](https://chugunov.pro/api-wordpress/functions/do_shortcode/), `WP_oEmbed::discover`, [`get_post_galleries`](https://chugunov.pro/api-wordpress/functions/get_post_galleries/).

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