Name an add-on’s data for Benecaster’s uninstall
Benecaster’s Delete all data on uninstall switch doesn’t work from a list — it discovers benecaster_-namespaced data by prefix and removes it. That means an add-on’s tables, options, meta, cron hooks, post types and taxonomies are removed along with Benecaster’s own, even while the add-on plugin is still installed and active. This is deliberate: an add-on can’t run without Benecaster, so its data is unreachable once Benecaster is gone.
Naming rules, so your add-on’s data is found:
- Tables:
{$wpdb->prefix}benecaster_{addon}_…. Found withSHOW TABLES LIKE, so
there’s no list to register with. - Options:
benecaster_{addon}_…. Background-job options may use
_benecaster_{addon}_…. Transients:benecaster_{addon}_…. - Post meta / user meta:
_benecaster_{addon}_…orbenecaster_{addon}_…. Keys stored
withupdate_user_option()get the site’s table prefix in front (wp_benecaster_…), which no prefix matches — useupdate_user_meta()instead. - Cron hooks, post types, taxonomies: start with
benecaster_. ⚠ WordPress caps a post
type key at 20 characters, andbenecaster_uses 11 of them. - What is never removed: anything outside the namespace.
myaddon_settingssurvives a
core uninstall, and so do WordPress users, media library attachments, and roles or capabilities added to WordPress roles.
Your add-on’s own uninstall.php must not depend on Benecaster. If the podcaster deletes Benecaster first, its autoloader is gone and \Benecaster\… classes fatal. If they delete the add-on first, Benecaster may be active and loaded, or deactivated and not loaded, and you can’t tell which in advance — so use $wpdb directly, and don’t assume the tables still exist.
Don’t delete another add-on’s data or Benecaster’s own from your uninstall.php, and don’t read Benecaster’s benecaster_delete_data_on_uninstall switch — it governs Benecaster’s own uninstall, not yours. Whether your own uninstall keeps data by default is your add-on’s own choice.
Code
<?php
// wp-content/plugins/benecaster-addon-guests/uninstall.php
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// Safe if core's uninstall already dropped it.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}benecaster_guests_appearances" );
// esc_like(): `_` is a LIKE wildcard.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( 'benecaster_guests_' ) . '%'
)
);
wp_clear_scheduled_hook( 'benecaster_guests_daily_sync' );
Need this built rather than just documented? See our services →