register_deactivation_hook

函式
register_deactivation_hook ( $file, $callback )
引數
  • (string) $file The filename of the plugin including the path.
    Required:
  • (callable) $callback The function hooked to the 'deactivate_PLUGIN' action.
    Required:
定義位置
相關方法
register_activation_hookregister_taxonomyunregister_taxonomyregister_metaunregister_meta_key
引入
2.0.0
棄用
-

register_deactivation_hook: 這個函式用來為一個外掛註冊一個停用鉤子。它需要兩個引數:$file和$callback。$file是外掛檔案的路徑,$callback是外掛停用時將被呼叫的函式。

設定一個外掛的停用鉤子。

當一個外掛被停用時,動作’deactivate_PLUGINNAME’被呼叫。在這個鉤子的名稱中,PLUGINNAME被替換成外掛的名稱,包括可選的子目錄。例如,當外掛位於wp-content/plugins/sampleplugin/sample.php,那麼這個鉤子的名字將變成’deactivate_sampleplugin/sample.php’。

當外掛只有一個檔案,並且(預設情況下)位於wp-content/plugins/sample.php中時,這個鉤子的名稱將是’deactivate_sample.php’。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function register_deactivation_hook( $file, $callback ) {
$file = plugin_basename( $file );
add_action( 'deactivate_' . $file, $callback );
}
function register_deactivation_hook( $file, $callback ) { $file = plugin_basename( $file ); add_action( 'deactivate_' . $file, $callback ); }
function register_deactivation_hook( $file, $callback ) {
	$file = plugin_basename( $file );
	add_action( 'deactivate_' . $file, $callback );
}

常見問題

FAQs
檢視更多 >