register_activation_hook()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
register_activation_hook( string $file, callable $callback )
Описание
При активации плагина вызывается хук-действие «activate_PLUGINNAME». В имени этого хука PLUGINNAME заменяется именем плагина, включая необязательный подкаталог. Например, если плагин находится в wp-content/plugins/sampleplugin/sample.php, имя этого хука станет «activate_sampleplugin/sample.php».
Если плагин состоит только из одного файла и (как по умолчанию) расположен в wp-content/plugins/sample.php, имя этого хука будет «activate_sample.php».
Оригинал (английский)
When a plugin is activated, the action ‘activate_PLUGINNAME’ hook is called. In the name of this hook, PLUGINNAME is replaced with the name of the plugin, including the optional subdirectory. For example, when the plugin is located in wp-content/plugins/sampleplugin/sample.php, then the name of this hook will become ‘activate_sampleplugin/sample.php’.
When the plugin consists of only one file and is (as by default) located at wp-content/plugins/sample.php the name of this hook will be ‘activate_sample.php’.
Параметры
$file
string
обязательный
$callback
callable
обязательный
Исходный код
wp-includes/plugin.php:879
function register_activation_hook( $file, $callback ) {
$file = plugin_basename( $file );
add_action( 'activate_' . $file, $callback );
}
История изменений
| Версия | Описание |
|---|---|
| 2.0.0 | Introduced. |

