It turns out getting the URL on activation is not likely through the standard $_GET
so WP has hooks for that.
Plugin Activation
I need to check for back up files stored in wp-content
root, if they were created previously during de-activation or update, and copy to the plugin’s folder.
register_activation_hook(__FILE__, function()
{
add_option('move_blocks_activated','move-blocks');
if( file_exists(WP_CONTENT_DIR.'/moveblocktmp/override.ini') ) {
copy(WP_CONTENT_DIR.'/moveblocktmp/override.ini', MYPLGPATH.'/msg/override.ini');
}
}
Plugin De-Activation
Action when the plugin Deactivate
link is processed. This works during plugin update to store user created files while the plugin is deleted and replaced.
register_deactivation_hook(__FILE__, function()
{
add_option('move_blocks_deactivated','move-blocks');
// create backup directory
if( !file_exists(WP_CONTENT_DIR.'/moveblocktmp') ) {
mkdir(WP_CONTENT_DIR.'/moveblocktmp',0755);
}
// copy files for backup
if( file_exists(MYPLGPATH.'/msg/override.ini') ) {
copy(MYPLGPATH.'/msg/override.ini', WP_CONTENT_DIR.'/moveblocktmp/override.ini');
}
}
Action After Previous Processes
add_action('admin_init', function()
{
// delete the previously created DB option row
if( !is_null(get_option('move_blocks_activated')) ) {
delete_option('move_blocks_activated');
}
if( !is_null(get_option('move_blocks_deactivated')) ) {
delete_option('move_blocks_deactivated');
}
});
On Plugin Delete
Using the uninstall.php
method in the plugin’s root.
<?php
if( !defined('WP_UNINSTALL_PLUGIN') ) {
die;
}
// delete the backup directory
if( file_exists(WP_CONTENT_DIR.'/moveblocktmp') )
rmdir(WP_CONTENT_DIR.'/moveblocktmp');
// rmdir() will not delete a directory with files. I use a recursive function.