# wp_specialchars_decode()

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

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

## Сигнатура

```php
wp_specialchars_decode( string $text, string|int $quote_style = ENT_NOQUOTES ): string
```

## Описание

В частности обрабатывает: &, , " и '.
$quote_style может быть равен ENT_COMPAT, чтобы декодировать сущности ", или ENT_QUOTES, чтобы декодировать и ", и '. Значение по умолчанию — ENT_NOQUOTES, при котором кавычки не декодируются.

## Параметры

- `$text` `string` — обязательный. Текст, который нужно декодировать.
- `$quote_style` `string|int` — необязательный, по умолчанию `ENT_NOQUOTES`. Преобразует двойные кавычки при значении ENT_COMPAT, одинарные и двойные — при ENT_QUOTES или ни одни — при ENT_NOQUOTES.
  
  Также совместимо со старыми значениями _wp_specialchars(); преобразует одинарные кавычки при значении 'single', двойные — при 'double' или оба вида при любом другом значении.
  
  Значение по умолчанию — ENT_NOQUOTES.

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

`string`

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

Файл: `wp-includes/formatting.php:1015`

```php
function wp_specialchars_decode( $text, $quote_style = ENT_NOQUOTES ) {
	$text = (string) $text;

	if ( 0 === strlen( $text ) ) {
		return '';
	}

	// Don't bother if there are no entities - saves a lot of processing.
	if ( ! str_contains( $text, '&' ) ) {
		return $text;
	}

	// Match the previous behavior of _wp_specialchars() when the $quote_style is not an accepted value.
	if ( empty( $quote_style ) ) {
		$quote_style = ENT_NOQUOTES;
	} elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
		$quote_style = ENT_QUOTES;
	}

	// More complete than get_html_translation_table( HTML_SPECIALCHARS ).
	$single      = array(
		'&#039;' => '\'',
		'&#x27;' => '\'',
	);
	$single_preg = array(
		'/&#0*39;/'   => '&#039;',
		'/&#x0*27;/i' => '&#x27;',
	);
	$double      = array(
		'&quot;' => '"',
		'&#034;' => '"',
		'&#x22;' => '"',
	);
	$double_preg = array(
		'/&#0*34;/'   => '&#034;',
		'/&#x0*22;/i' => '&#x22;',
	);
	$others      = array(
		'&lt;'   => '<',
		'&#060;' => '<',
		'&gt;'   => '>',
		'&#062;' => '>',
		'&amp;'  => '&',
		'&#038;' => '&',
		'&#x26;' => '&',
	);
	$others_preg = array(
		'/&#0*60;/'   => '&#060;',
		'/&#0*62;/'   => '&#062;',
		'/&#0*38;/'   => '&#038;',
		'/&#x0*26;/i' => '&#x26;',
	);

	if ( ENT_QUOTES === $quote_style ) {
		$translation      = array_merge( $single, $double, $others );
		$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
	} elseif ( ENT_COMPAT === $quote_style || 'double' === $quote_style ) {
		$translation      = array_merge( $double, $others );
		$translation_preg = array_merge( $double_preg, $others_preg );
	} elseif ( 'single' === $quote_style ) {
		$translation      = array_merge( $single, $others );
		$translation_preg = array_merge( $single_preg, $others_preg );
	} elseif ( ENT_NOQUOTES === $quote_style ) {
		$translation      = $others;
		$translation_preg = $others_preg;
	}

	// Remove zero padding on numeric entities.
	$text = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $text );

	// Replace characters according to translation table.
	return strtr( $text, $translation );
}
```

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

- 2.8.0 — Introduced.

## Связанные

Используется в: [`wpmu_new_site_admin_notification`](https://chugunov.pro/api-wordpress/functions/wpmu_new_site_admin_notification/), `WP_Automatic_Updater::send_plugin_theme_email`, `WP_Recovery_Mode_Email_Service::send_recovery_mode_email`, [`_wp_privacy_send_request_confirmation_notification`](https://chugunov.pro/api-wordpress/functions/_wp_privacy_send_request_confirmation_notification/), [`_wp_privacy_send_erasure_fulfillment_notification`](https://chugunov.pro/api-wordpress/functions/_wp_privacy_send_erasure_fulfillment_notification/), [`wp_send_user_request`](https://chugunov.pro/api-wordpress/functions/wp_send_user_request/), [`wp_privacy_send_personal_data_export_email`](https://chugunov.pro/api-wordpress/functions/wp_privacy_send_personal_data_export_email/), [`wp_site_admin_email_change_notification`](https://chugunov.pro/api-wordpress/functions/wp_site_admin_email_change_notification/), [`update_network_option_new_admin_email`](https://chugunov.pro/api-wordpress/functions/update_network_option_new_admin_email/), [`wp_network_admin_email_change_notification`](https://chugunov.pro/api-wordpress/functions/wp_network_admin_email_change_notification/), [`retrieve_password`](https://chugunov.pro/api-wordpress/functions/retrieve_password/), `WP_Automatic_Updater::send_email`, `WP_Automatic_Updater::send_debug_email`, [`update_option_new_admin_email`](https://chugunov.pro/api-wordpress/functions/update_option_new_admin_email/), [`send_confirmation_on_profile_email`](https://chugunov.pro/api-wordpress/functions/send_confirmation_on_profile_email/), [`admin_created_user_email`](https://chugunov.pro/api-wordpress/functions/admin_created_user_email/), [`wp_password_change_notification`](https://chugunov.pro/api-wordpress/functions/wp_password_change_notification/), [`wp_new_user_notification`](https://chugunov.pro/api-wordpress/functions/wp_new_user_notification/), [`wp_notify_postauthor`](https://chugunov.pro/api-wordpress/functions/wp_notify_postauthor/), [`wp_notify_moderator`](https://chugunov.pro/api-wordpress/functions/wp_notify_moderator/), [`wp_update_user`](https://chugunov.pro/api-wordpress/functions/wp_update_user/), [`wpmu_welcome_user_notification`](https://chugunov.pro/api-wordpress/functions/wpmu_welcome_user_notification/), [`wpmu_welcome_notification`](https://chugunov.pro/api-wordpress/functions/wpmu_welcome_notification/), [`wpmu_signup_blog_notification`](https://chugunov.pro/api-wordpress/functions/wpmu_signup_blog_notification/), [`wpmu_signup_user_notification`](https://chugunov.pro/api-wordpress/functions/wpmu_signup_user_notification/).

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