0
0
Wordpressframework~10 mins

Uninstall and cleanup hooks in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register an uninstall hook for a WordPress plugin.

Wordpress
register_uninstall_hook(__FILE__, '[1]');
Drag options to blanks, or click blank then click option'
Amy_plugin_uninstall
Binit
Cdeactivate_plugin
Dactivate_plugin
Attempts:
3 left
💡 Hint
Common Mistakes
Using activation or deactivation hooks instead of uninstall hook.
Passing a hook name instead of a function name.
2fill in blank
medium

Complete the uninstall function to delete a custom option from the database.

Wordpress
function my_plugin_uninstall() {
    [1]('my_plugin_option');
}
Drag options to blanks, or click blank then click option'
Adelete_option
Bupdate_option
Cadd_option
Dget_option
Attempts:
3 left
💡 Hint
Common Mistakes
Using update_option instead of delete_option.
Trying to get_option instead of deleting.
3fill in blank
hard

Fix the error in the uninstall function to remove a custom database table.

Wordpress
function my_plugin_uninstall() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'my_plugin_data';
    $wpdb->query("[1]");
}
Drag options to blanks, or click blank then click option'
ADELETE TABLE $table_name
BDROP TABLE $table_name
CDROP TABLE IF EXISTS $table_name
DREMOVE TABLE $table_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using DELETE TABLE which is invalid SQL.
Not checking if the table exists before dropping.
4fill in blank
hard

Fill both blanks to remove a custom post type and its metadata during uninstall.

Wordpress
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);
    }
}
Drag options to blanks, or click blank then click option'
Amy_custom_type
Bmy_custom_meta
Cpost_meta_key
Dcustom_post
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong post type name.
Deleting wrong meta key.
5fill in blank
hard

Fill all three blanks to unregister a shortcode and remove its option during uninstall.

Wordpress
function my_plugin_uninstall() {
    [1]('[2]');
    [3]('my_plugin_shortcode_option');
}
Drag options to blanks, or click blank then click option'
Aremove_shortcode
Bdelete_option
Cmy_plugin_shortcode
Dunregister_shortcode
Attempts:
3 left
💡 Hint
Common Mistakes
Using unregister_shortcode which does not exist.
Not deleting the option after removing shortcode.