0
0
Wordpressframework~20 mins

Uninstall and cleanup hooks in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Uninstall Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
ANo cleanup code runs automatically; plugin data remains in the database.
BWordPress will run the uninstall hook registered in the main plugin file instead.
CWordPress throws an error and prevents uninstallation.
DWordPress deletes all plugin data automatically without any code.
Attempts:
2 left
💡 Hint
Think about what WordPress does by default without explicit uninstall instructions.
📝 Syntax
intermediate
2: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?
Aregister_hook('uninstall_plugin', 'my_plugin_cleanup');
Badd_action('uninstall', 'my_plugin_cleanup');
Cadd_uninstall_hook('my_plugin_cleanup');
Dregister_uninstall_hook(__FILE__, 'my_plugin_cleanup');
Attempts:
2 left
💡 Hint
Look for the exact WordPress function name and parameters.
🔧 Debug
advanced
2:00remaining
Why does the uninstall hook not run when uninstalling the plugin?
Consider this uninstall.php file content:
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');
AThe delete_option function is misspelled, causing a fatal error.
BThe constant WP_UNINSTALL_PLUGIN is not defined during uninstall, so the script exits early.
CThe uninstall.php file is not in the plugin root folder, so WordPress does not find it.
DThe uninstall hook requires a function wrapper around delete_option to run.
Attempts:
2 left
💡 Hint
Check the file location and how WordPress detects uninstall.php.
state_output
advanced
2:00remaining
What is the state of options after uninstall hook runs?
A plugin registers this uninstall hook:
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');
ABoth options remain because delete_option only works during plugin activation.
BBoth 'plugin_setting' and 'plugin_cache' options are removed from the database.
COnly 'plugin_setting' is removed; 'plugin_cache' remains.
DNeither option is removed because uninstall hooks do not delete options.
Attempts:
2 left
💡 Hint
Think about what delete_option does and when uninstall hooks run.
🧠 Conceptual
expert
2: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?
Auninstall.php runs even if the plugin is deleted without deactivation, ensuring cleanup always happens.
Bregister_uninstall_hook runs faster and is preferred for performance reasons.
Cuninstall.php allows cleanup code to run during plugin activation as well.
Dregister_uninstall_hook requires the plugin to be active, so uninstall.php is used for inactive plugins.
Attempts:
2 left
💡 Hint
Consider when uninstall.php is triggered compared to uninstall hooks.