# apply_filters()

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

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

## Сигнатура

```php
apply_filters( string $hook_name, mixed $value, mixed $args ): mixed
```

## Описание

Эта функция вызывает все функции, привязанные к хуку-фильтру $hook_name.
Можно создавать новые хуки-фильтры, просто вызвав эту функцию и указав имя нового хука в параметре $hook_name.
Функция также позволяет передавать хукам несколько дополнительных аргументов.
Пример использования:
// Функция обратного вызова фильтра.
function example_callback( $string, $arg1, $arg2 ) {
// (возможно) изменить $string.
return $string;
}
add_filter( 'example_filter', 'example_callback', 10, 3 );

/*
* Применить фильтры, вызвав функцию 'example_callback()',
* которая привязана к `example_filter` выше.
*
* - 'example_filter' — это хук-фильтр.
* - 'filter me' — фильтруемое значение.
* - $arg1 и $arg2 — дополнительные аргументы, передаваемые в функцию обратного вызова.
$value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );

## Параметры

- `$hook_name` `string` — обязательный. Имя хука-фильтра.
- `$value` `mixed` — обязательный. Значение для фильтрации.
- `$args` `mixed` — необязательный. Дополнительные параметры для передачи функциям обратного вызова.

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

`mixed`

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

Файл: `wp-includes/plugin.php:173`

```php
function apply_filters( $hook_name, $value, ...$args ) {
	global $wp_filter, $wp_filters, $wp_current_filter;

	if ( ! isset( $wp_filters[ $hook_name ] ) ) {
		$wp_filters[ $hook_name ] = 1;
	} else {
		++$wp_filters[ $hook_name ];
	}

	// Do 'all' actions first.
	if ( isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;

		$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
		_wp_call_all_hook( $all_args );
	}

	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
		if ( isset( $wp_filter['all'] ) ) {
			array_pop( $wp_current_filter );
		}

		return $value;
	}

	if ( ! isset( $wp_filter['all'] ) ) {
		$wp_current_filter[] = $hook_name;
	}

	// Pass the value to WP_Hook.
	array_unshift( $args, $value );

	$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );

	array_pop( $wp_current_filter );

	return $filtered;
}
```

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

- 6.0.0 — Formalized the existing and already documented ...$args parameter by adding it to the function signature.
- 0.71 — Introduced.

## Связанные

Использует: [`_wp_call_all_hook`](https://chugunov.pro/api-wordpress/functions/_wp_call_all_hook/).
Используется в: [`_load_script_textdomain_from_src`](https://chugunov.pro/api-wordpress/functions/_load_script_textdomain_from_src/), `WP_AI_Client_Prompt_Builder::__construct`, `WP_AI_Client_Prompt_Builder::__call`, [`wp_supports_ai`](https://chugunov.pro/api-wordpress/functions/wp_supports_ai/), [`wp_print_auto_sizes_contain_css_fix`](https://chugunov.pro/api-wordpress/functions/wp_print_auto_sizes_contain_css_fix/), [`wp_get_image_editor_output_format`](https://chugunov.pro/api-wordpress/functions/wp_get_image_editor_output_format/), [`wp_img_tag_add_auto_sizes`](https://chugunov.pro/api-wordpress/functions/wp_img_tag_add_auto_sizes/), [`wp_enqueue_img_auto_sizes_contain_css_fix`](https://chugunov.pro/api-wordpress/functions/wp_enqueue_img_auto_sizes_contain_css_fix/), [`wp_finalize_template_enhancement_output_buffer`](https://chugunov.pro/api-wordpress/functions/wp_finalize_template_enhancement_output_buffer/), [`wp_should_output_buffer_template_for_enhancement`](https://chugunov.pro/api-wordpress/functions/wp_should_output_buffer_template_for_enhancement/), `WP_Debug_Data::get_wp_active_theme`, `WP_Debug_Data::get_wp_parent_theme`, `WP_Debug_Data::get_wp_themes_inactive`, `WP_Debug_Data::get_wp_plugins_raw_data`, [`wp_get_speculation_rules_configuration`](https://chugunov.pro/api-wordpress/functions/wp_get_speculation_rules_configuration/), [`wp_get_speculation_rules`](https://chugunov.pro/api-wordpress/functions/wp_get_speculation_rules/), [`get_block_bindings_supported_attributes`](https://chugunov.pro/api-wordpress/functions/get_block_bindings_supported_attributes/), `WP_Abilities_Registry::register`, `WP_Ability_Categories_Registry::register`, [`wp_password_needs_rehash`](https://chugunov.pro/api-wordpress/functions/wp_password_needs_rehash/), [`is_post_embeddable`](https://chugunov.pro/api-wordpress/functions/is_post_embeddable/), [`wp_should_load_block_assets_on_demand`](https://chugunov.pro/api-wordpress/functions/wp_should_load_block_assets_on_demand/), `WP_REST_Menu_Locations_Controller::check_has_read_only_access`, [`wp_check_comment_data`](https://chugunov.pro/api-wordpress/functions/wp_check_comment_data/), `WP_Script_Modules::print_script_module_data`, `WP_Block_Metadata_Registry::register_collection`, [`wp_autoload_values_to_autoload`](https://chugunov.pro/api-wordpress/functions/wp_autoload_values_to_autoload/), [`wp_filter_default_autoload_value_via_option_size`](https://chugunov.pro/api-wordpress/functions/wp_filter_default_autoload_value_via_option_size/), [`wp_determine_option_autoload_value`](https://chugunov.pro/api-wordpress/functions/wp_determine_option_autoload_value/), [`insert_hooked_blocks_into_rest_response`](https://chugunov.pro/api-wordpress/functions/insert_hooked_blocks_into_rest_response/), `WP_Site_Health::get_test_autoloaded_options`, `WP_Automatic_Updater::has_fatal_error`, [`_wp_filter_font_directory`](https://chugunov.pro/api-wordpress/functions/_wp_filter_font_directory/), [`‘upload_dir’`](https://chugunov.pro/api-wordpress/filters/upload_dir/), `WP_Block_Type::get_variations`, `WP_Block_Type::get_uses_context`, `WP_Plugin_Dependencies::sanitize_dependency_slugs`, [`wp_is_rest_endpoint`](https://chugunov.pro/api-wordpress/functions/wp_is_rest_endpoint/), `WP_Block_Bindings_Source::get_value`, `WP_Script_Modules::get_src`.

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