Confirm plugin uninstallation
Many plugin developers tend to run their uninstallation routines without questioning. It may not big issue after all, I mean, the user is logged in so no security check are really necessary. But, how many of you (developers) tend to mistakenly uninstall a plugin? Probably not many, but I have come across that.. Now make the same question about regular administrators.
It is actually not hard to add a confirmation page at all, just around 20 lines of code right before our original code. A example is found below.
There it is, rather simple isn't? Removing the comments there is really few code being added to the plugin file.
Also note that this is part of the update to the Hello! plugin being added to the upcoming versions of MyBB.
I hope it is of some use for you.
It is actually not hard to add a confirmation page at all, just around 20 lines of code right before our original code. A example is found below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// _uninstall() routine for our plugins | |
function foo_uninstall() | |
{ | |
global $mybb; | |
// Only run if a post request | |
if($mybb->request_method != 'post') | |
{ | |
global $page; | |
$message = $title = ''; | |
// You can ignore the following if you don't want to bother to load language files | |
//$message = 'Are you sure you wish to uninstall the Foo plugin?'; | |
//$title = 'Uninstall Foo Plugin'; | |
$page->output_confirm_action('index.php?module=config-plugins&action=deactivate&uninstall=1&plugin=foo', $message, $title); | |
} | |
// Verify post requests for XSS attempts | |
if(!verify_post_check($mybb->get_input('my_post_key'))) | |
{ | |
global $lang; | |
flash_message($lang->invalid_post_verify_key2, 'error'); | |
admin_redirect('index.php?module=config-plugins'); | |
} | |
// So administrator is not sure.. | |
if(isset($mybb->input['no'])) | |
{ | |
admin_redirect('index.php?module=config-plugins'); | |
} | |
// drop tables | |
// remove our templates | |
// delete settings and/or setting groups | |
// rebuild_settings | |
// etcetera | |
} |
There it is, rather simple isn't? Removing the comments there is really few code being added to the plugin file.
Also note that this is part of the update to the Hello! plugin being added to the upcoming versions of MyBB.
I hope it is of some use for you.