I am currently updating the WordPress plugin, which has been released a long time ago, and part of the “future verification” of the plugin is to get rid of some crappy naming schemes that were implemented in the initial stages of the plugin.
I decided that I would just add an activation hook that would check if any of these names exist, and if so, just delete the plugin parameters array and show a notification allowing the user to know that they need to update their parameters again, because we should have cleared the data for future verification. Sounds easy enough, huh? Apparently not.
I tried all the possible methods that I can think of, and no matter what I do, I CANNOT get the delete_option (), update_option (), add_option () and get_option () functions to work inside the activation hook.
The following is an example of how my activation hook is configured:
function my_activation_hook() {
global $opts_array;
$needs_update = false;
foreach($opts_array['bookmark'] as $bkmrk) {
if(strpos($bkmrk, 'badname-') !== false) {
$needs_update = true;
}
}
if($needs_update === true) {
unset($opts_array);
delete_option('MyPluginOpts');
$opts_array = array(
'position' => 'below',
'reloption' => 'nofollow',
'targetopt' => '_blank',
'bgimg-yes' => 'yes',
'mobile-hide' => '',
'bgimg' => 'shr',
'shorty' => 'b2l',
'pageorpost' => '',
'bookmark' => array_keys($bookmarks_opts_data),
'feed' => '1',
'expand' => '1',
'autocenter' => '1',
'ybuzzcat' => 'science',
'ybuzzmed' => 'text',
'twittcat' => '',
'tweetconfig' => '${title} - ${short_link}',
'defaulttags' => 'blog',
'warn-choice' => '',
'doNotIncludeJQuery' => '',
'custom-mods' => '',
'scriptInFooter' => '1',
'vernum' => 'old',
);
add_option('MyPluginOpts', $opts_array);
$opts_array = get_option('MyPluginOpts');
}
}
register_activation_hook(__FILE__, 'my_activation_hook' );