Complete the code to register an uninstall hook for a WordPress plugin.
register_uninstall_hook(__FILE__, '[1]');
The register_uninstall_hook function requires the name of the uninstall callback function as the second argument.
Complete the uninstall function to delete a custom option from the database.
function my_plugin_uninstall() {
[1]('my_plugin_option');
}The delete_option function removes an option from the WordPress database.
Fix the error in the uninstall function to remove a custom database table.
function my_plugin_uninstall() {
global $wpdb;
$table_name = $wpdb->prefix . 'my_plugin_data';
$wpdb->query("[1]");
}Using DROP TABLE IF EXISTS safely removes the table if it exists, avoiding errors.
Fill both blanks to remove a custom post type and its metadata during uninstall.
function my_plugin_uninstall() {
$posts = get_posts(array('post_type' => '[1]', 'numberposts' => -1));
foreach ($posts as $post) {
delete_post_meta($post->ID, '[2]');
wp_delete_post($post->ID, true);
}
}The first blank is the custom post type name. The second blank is the meta key to delete.
Fill all three blanks to unregister a shortcode and remove its option during uninstall.
function my_plugin_uninstall() {
[1]('[2]');
[3]('my_plugin_shortcode_option');
}remove_shortcode unregisters the shortcode by name, and delete_option removes the stored option.