Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 51
Plugin Deactivation Function
ОглавлениеLike the activation function, WordPress also allows you to execute code from a registered deactivation callback via the register_deactivation_hook()
function. The following example includes the src/Deactivation.php
class and executes its deactivate()
method:
<?php namespace PDEV; register_deactivation_hook( __FILE__, function() { require_once plugin_dir_path( __FILE__ ) . 'src/Deactivation.php'; Deactivation::deactivate(); } );
Once you've registered your deactivation callback, you need to run some code on deactivation. The following is an example of how to set up your Deactivation
class:
<?php namespace PDEV; class Deactivation { public static function deactivate() { // Run your deactivation code here. } }
Like with the activation hook, you have the freedom to run any code that you need when a user decides to deactivate your plugin.