Challenge - 5 Problems
Uninstall Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when the uninstall.php file is missing in a plugin?
In WordPress, a plugin uses an uninstall.php file to clean up data when uninstalled. What happens if this file is missing and the plugin is uninstalled?
Attempts:
2 left
💡 Hint
Think about what WordPress does by default without explicit uninstall instructions.
✗ Incorrect
If the uninstall.php file is missing and no uninstall hook is registered, WordPress does not run any cleanup code automatically. Plugin data remains in the database until manually removed.
📝 Syntax
intermediate2:00remaining
Which uninstall hook registration is correct?
You want to register an uninstall hook in your main plugin file to clean up options. Which code snippet correctly registers the uninstall hook?
Attempts:
2 left
💡 Hint
Look for the exact WordPress function name and parameters.
✗ Incorrect
The correct function to register an uninstall hook is register_uninstall_hook with the plugin file path and callback function.
🔧 Debug
advanced2:00remaining
Why does the uninstall hook not run when uninstalling the plugin?
Consider this uninstall.php file content:
Why might the uninstall hook not run when uninstalling the plugin?
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit();
}
delete_option('my_plugin_option');Why might the uninstall hook not run when uninstalling the plugin?
Wordpress
if (!defined('WP_UNINSTALL_PLUGIN')) { exit(); } delete_option('my_plugin_option');
Attempts:
2 left
💡 Hint
Check the file location and how WordPress detects uninstall.php.
✗ Incorrect
WordPress only runs uninstall.php if it is located in the root folder of the plugin. If placed elsewhere, it won't run and no cleanup happens.
❓ state_output
advanced2:00remaining
What is the state of options after uninstall hook runs?
A plugin registers this uninstall hook:
After uninstalling the plugin, what happens to these options?
function cleanup() {
delete_option('plugin_setting');
delete_option('plugin_cache');
}
register_uninstall_hook(__FILE__, 'cleanup');After uninstalling the plugin, what happens to these options?
Wordpress
function cleanup() {
delete_option('plugin_setting');
delete_option('plugin_cache');
}
register_uninstall_hook(__FILE__, 'cleanup');Attempts:
2 left
💡 Hint
Think about what delete_option does and when uninstall hooks run.
✗ Incorrect
The uninstall hook runs the cleanup function which calls delete_option on both options, removing them from the database.
🧠 Conceptual
expert2:00remaining
Why use uninstall.php instead of register_uninstall_hook?
Which reason best explains why a plugin developer might prefer using an uninstall.php file over register_uninstall_hook for cleanup?
Attempts:
2 left
💡 Hint
Consider when uninstall.php is triggered compared to uninstall hooks.
✗ Incorrect
uninstall.php is executed when the plugin is deleted directly, even if not deactivated first, ensuring cleanup always runs.