register_deactivation_hook() - WordPress 函数参考中文文档

返回介绍

register_deactivation_hook()

发布于 2017-09-11 字数2498 浏览 1120 评论 0

register_deactivation_hook( string $file,  callable $function )

Set the deactivation hook for a plugin.


描述

When a plugin is deactivated, the action ‘deactivate_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 ‘deactivate_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 ‘deactivate_sample.php’.


参数

$file

(string)
(Required)
The filename of the plugin including the path.

$function

(callable)
(Required)
The function hooked to the ‘deactivate_PLUGIN’ action.


源代码

File: wp-includes/plugin.php

function register_deactivation_hook($file, $function) {
	$file = plugin_basename($file);
	add_action('deactivate_' . $file, $function);
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/plugin.php:
    plugin_basename()
  • wp-includes/plugin.php:
    add_action()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Examples
    If you have a function called myplugin_deactivate() in the main plugin file at either

    wp-content/plugins/myplugin.php or
    wp-content/plugins/myplugin/myplugin.php
    use this code:

    
    register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
    

    This will call the myplugin_deactivate() function on deactivation of the plugin.

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!