1

I'm currently working on a WordPress child theme and I needed a way to delete all the data on uninstall, so I found this in the WordPress documentation.

I tested uninstall.php or the register_uninstall_hook but it doesn't work when the theme is uninstalled.

Here's my uninstall code:

function uninstallMe() {
    if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
        die('Heey dude, wanna coffee?');
    }
    global $wpdb;

    $sql = "DROP TABLE IF EXISTS {$wpdb->prefix}coffee_tags";
    $wpdb->query($sql);

    exec("crontab -l | grep -v 'mycustomcron0047.php' | crontab -");

    $sysPath = dirname($_SERVER['DOCUMENT_ROOT']) ;
    unlink($sysPath.DIRECTORY_SEPARATOR.'config.php');
    unlink($sysPath.DIRECTORY_SEPARATOR.'mycustomcron0047.php');
}
register_uninstall_hook( __FILE__, 'uninstallMe' );

Is there an alternative way to remove data on child theme uninstall? Or a way to make default ways work?

0

0