Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@banago

banago May 27, 2014

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

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