How to remove / uninstall B2BKing completely & remove all plugin data

By default, B2BKing does not remove all its data when it is uninstalled. This is a safety precaution to prevent accidental losses of important data.

To completely remove B2BKing and all its data from the database, you can do the following prior to uninstalling the plugin:

Add this PHP code snippet to your site:

update_option('b2bking_keepdata_setting', 0);

If you have already removed the plugin before reading this article, you can instead run the following code snippet:

// clear options
global $wpdb;
$plugin_options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%b2bking%'" );
foreach( $plugin_options as $option ) {
    delete_option( $option->option_name );

// clear all custom posts
$post_types = array('b2bking_custom_role', 'b2bking_custom_field', 'b2bking_group', 'b2bking_rule', 'b2bking_offer', 'b2bking_conversation');
foreach ($post_types as $type){
	$allposts= get_posts( array('post_type'=> $type,'numberposts'=>-1) );
	foreach ($allposts as $eachpost) {
		wp_delete_post( $eachpost->ID, true );

// clear user metadata
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '%b2bking%'");

// clear product metadata
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '%b2bking%'");

This snippet can be added to a code snippets plugin and run once, or it can be added to functions.php and removed after it runs.

Powered by BetterDocs