Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markjaquith/857430 to your computer and use it in GitHub Desktop.
Save markjaquith/857430 to your computer and use it in GitHub Desktop.
Example code for doing activate/deactivate/uninstall hooks in a WordPress plugin
<?php
// Change /*CUSTOMIZE_THIS*/ to a unique name (two places). Go ahead, make it long.
// Like, your initials, and your full plugin name.
// e.g. MTJ_Some_Awesome_Plugin_Controller
/*CUSTOMIZE_THIS*/_Controller::init();
class /*CUSTOMIZE_THIS*/_Controller {
function init() {
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
register_deactivation_hook( __FILE__, array( __CLASS__, 'deactivate' ) );
}
function activate() {
// Add options, initiate cron jobs here
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
}
function deactivate() {
// Remove cron jobs here
}
function uninstall() {
// Delete options here
}
}
@banago
Copy link

banago commented May 27, 2014

When is the uninstall hook fired? I seem not to be able to fire it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment