WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Uninstall on Multisite (7 posts)

  1. jkbb
    Member
    Posted 1 year ago #

    Hi!

    We hade no use for this plugin anymore so I deactivated and removed it. I read that there is an uninstall script that's supposed to run when doing this. But doesn't seem to work since I still have a lot of subscribe2 related stuff in my db. For example I still got the subscribe2 table for each blog.

    How can i do a proper uninstallation of this script on my big mu installation?

    http://wordpress.org/extend/plugins/subscribe2/

  2. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @jkbb,

    Thanks for raising this, I've looked at the uninstall code and it clearly isn't robust enough to uninstall settings on Multisite installs as it doesn't switch between database tables.

    Basically, the code need to cycle through all the sub-blog tables removing the settings. I haven't tested this uninstall.php code but it's worth a try:

    <?php
    if ( !defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') ) {
    	// Make sure not to call this file directly
    	exit();
    } else {
    	// Is this WordPressMU or not?
    	if ( isset($wpmu_version) || strpos($wp_version, 'wordpress-mu') ) {
    		$s2_mu = true;
    	}
    	if ( function_exists('is_multisite') && is_multisite() ) {
    		$s2_mu = true;
    	}
    
    	if ( $s2_mu ) {
    		global $wpdb;
    		$blogs = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
    		foreach ( $blogs as $blog ) {
    			switch_to_blog($blog);
    			s2_uninstall();
    			restore_current_blog();
    		}
    	} else {
    		s2_uninstall();
    	}
    
    	function s2_uninstall() {
    		global $wpdb, $table_prefix;
    		// get name of subscribe2 table
    		$public = $table_prefix . "subscribe2";
    		// delete entry from wp_options table
    		delete_option('subscribe2_options');
    		// delete legacy entry from wp-options table
    		delete_option('s2_future_posts');
    		// remove and scheduled events
    		wp_clear_scheduled_hook('s2_digest_cron');
    		// delete usermeta data for registered users
    		// use LIKE and % wildcard as meta_key names are prepended on WPMU
    		// and s2_cat is appended with category ID integer
    		$wpdb->query("DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_cat%'");
    		$wpdb->query("DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_subscribed'");
    		$wpdb->query("DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_format'");
    		$wpdb->query("DELETE from $wpdb->usermeta WHERE meta_key LIKE '%s2_autosub'");
    		// delete any postmeta data that supressed notifications
    		$wpdb->query("DELETE from $wpdb->postmeta WHERE meta_key = 's2mail'");
    
    		// drop the subscribe2 table
    		$sql = "DROP TABLE IF EXISTS <code>&quot; . $public . &quot;</code>";
    		$wpdb->query($sql);
    	} // end s2_uninstall()
    }
    ?>
  3. jkbb
    Member
    Posted 1 year ago #

    Thank you for the quick answer.

    So how do I use this, do I have to install, activate and deactivate the plugin again?

  4. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @jkbb,

    You could install the plugin as normal, copy the code above over the existing uninstall.php file and then uninstall it (don't even need to activate it).

    Or, if you can handle code okay you could simply run this code by adding it into an existing plugin or the functions.php file of your theme.

  5. jkbb
    Member
    Posted 1 year ago #

    Seemed to work great, except a reference to subscribe2/subscribe2.php in each blogs wp_options, _transient_plugin_slugs.

    Thanks!

  6. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @jkbb,

    Thanks for the feedback, I'll update the uninstall.php file in the next version.

    The _transient keys are coming from the WordPress core files, there seems to be a way to stop the expired keys building up:

    http://www.staze.org/wordpress-_transient-buildup/

  7. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @jkbb,

    In fact, after a little more digging, this seems to be a core bug in WordPress:
    http://core.trac.wordpress.org/ticket/20316

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.