钩子文档

deactivate_{$plugin}

💡 云策文档标注

概述

deactivate_{$plugin} 是一个 WordPress 钩子,在特定插件被停用时触发。它由 register_deactivation_hook() 内部使用,用于处理插件停用逻辑。

关键要点

  • 这是一个动态钩子,$plugin 部分指代插件的基本名称(basename)。
  • 如果插件被静默停用(例如在更新过程中),此钩子不会触发。
  • 参数 $network_deactivating 是一个布尔值,仅在多站点环境中有效,表示插件是否在整个网络中停用(默认为 false)。
  • 钩子通过 do_action() 调用,开发者可以添加自定义函数来响应插件停用事件。

注意事项

  • 此钩子主要用于插件开发,允许在停用时执行清理或通知操作。
  • 在多站点设置中,需注意 $network_deactivating 参数以区分停用范围。

📄 原文内容

Fires as a specific plugin is being deactivated.

Description

This hook is the “deactivation” hook used internally by register_deactivation_hook() .
The dynamic portion of the hook name, $plugin, refers to the plugin basename.

If a plugin is silently deactivated (such as during an update), this hook does not fire.

Parameters

$network_deactivatingbool
Whether the plugin is deactivated for all sites in the network or just the current site. Multisite only. Default false.

Source

do_action( "deactivate_{$plugin}", $network_deactivating );

Changelog

Version Description
2.0.0 Introduced.