Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jason Coleman

    (@strangerstudios)

    Take a look at this plugin:
    https://www.ads-software.com/extend/plugins/delete-me/

    It adds a delete button to a user’s profile that deletes their entire account. PMPro will cancel their subscription when they are deleted.

    You can use that plugin and point user’s to the delete button to close their membership.

    Alternatively, you can use the wp_delete_user and/or wpmu_delete_user function to delete a user:
    https://codex.www.ads-software.com/Function_Reference/wp_delete_user
    https://codex.www.ads-software.com/Function_Reference/wpmu_delete_user

    You can hook into PMPro using the “pmpro_after_change_membership_level” hook. (It passes $pmpro_level->id and $user_id as parameters.)

    If you did that, I would make sure to make this clear to users by adding text to the cancel page, etc.

    Thread Starter lweilenman

    (@lweilenman)

    Thanks for the quick response, I saw a previous thread about the “pmpro_after_change_membership_level” hook with wp_delete_user, but when I tried that, I started getting “Failed to cancel subscription” notification emails sent to the Admin, which made me think maybe that hook was deleting the user, before the plugin was done doing all of it’s “close account” procedures. Would that cause that particular error? I don’t get the error if I am not also trying to delete the user using that hook.

    Plugin Author Jason Coleman

    (@strangerstudios)

    That’s possible. Let me test something and get back to you.

    Plugin Author Jason Coleman

    (@strangerstudios)

    So this got tricky.

    There were a couple notices in pmpro_changeMembershipLevel, which I’ve cleaned up for PMPro version 1.4.

    I also had to tweak the pmpro_changeMembershipLevel function a bit to avoid an infinite redirect loop when deleting users who cancelled (PMPro would then try to cancel their membership, which would trigger the hook to delete them again… etc etc).

    So you will need an updated copy of /paid-memberships-pro/includes/functions.php. v1.4 is not scheduled to go out yet, but you can grab just the functions.php to replace yours here:
    https://github.com/strangerstudios/paid-memberships-pro/blob/master/includes/functions.php

    Then try code like this to delete members who cancel:
    https://gist.github.com/2185226

    Let me know if that new functions.php and the gist works for you or if you run into any issues.

    Plugin Author Jason Coleman

    (@strangerstudios)

    Fooey. Forgot, you’ll also have to update paid-memberships-pro.php to avoid the “error cancelling subscription” email.

    https://github.com/strangerstudios/paid-memberships-pro/blob/master/paid-memberships-pro.php

    If you cut and paste that over your v1.3.19 copy, you’ll want to update the version number at the top of the file so WP knows to let you upgrade when v1.4 comes out. Alternatively you can replace the pmpro_delete_user function with this code:

    //deleting a user? remove their account info.
    function pmpro_delete_user($user_id = NULL)
    {
    	global $wpdb;
    
    	//changing their membership level to 0 will cancel any subscription and remove their membership level entry
    	//we don't remove the orders because it would affect reporting
    	if(pmpro_changeMembershipLevel(0, $user_id))
    	{
    		//okay
    	}
    	else
    	{
    		//couldn't delete the subscription
    		//we should probably notify the admin
    		global $pmpro_error;
    		if(!empty($pmpro_error))
    		{
    			$pmproemail = new PMProEmail();
    			$pmproemail->data = array("body"=>"<p>There was an error canceling the subscription for user with ID=" . $user_id . ". You will want to check your payment gateway to see if their subscription is still active.</p><p>Error: " . $pmpro_error . "</p>");
    			$last_order = $wpdb->get_row("SELECT * FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $user_id . "' ORDER BY timestamp DESC LIMIT 1");
    			if(!empty($last_order))
    				$pmproemail->data["body"] .= "<p>Last Invoice:<br />" . nl2br(var_export($last_order, true)) . "</p>";
    			$pmproemail->sendEmail(get_bloginfo("admin_email"));
    		}
    	}
    }
    add_action('delete_user', 'pmpro_delete_user');
    add_action('wpmu_delete_user', 'pmpro_delete_user');

    Sorry for the complicated answer here. But thanks for bringing this up. It think this is something that a lot of people will want to do. It’s good that v1.4 will support this through hooks and it may get baked into future versions.

    Thread Starter lweilenman

    (@lweilenman)

    Dang, man that works like a charm! Thanks so much for your help this is a great plugin. Keep up the good work!

    Plugin Author Jason Coleman

    (@strangerstudios)

    Thanks

    Thread Starter lweilenman

    (@lweilenman)

    strangerstudios,

    After using this fix for about a week now (works great, btw). I have noticed a new bug, where when an administrator changes a user’s level through their profile (From membership level A to membership level B), that user’s membership becomes non-recurring, and free. An email is even sent to the user letting them know that their membership level was changed, and the new level is free. Is it possible, that some of the changes to one of these PMP files has caused this, or should I open up a new thread for a separate issue?

    Plugin Author Jason Coleman

    (@strangerstudios)

    This is working as intended. Did you notice the popup that says “Warning: The existing membership will be canceled, and the new membership will be free.” when you try to change a user’s level through the admin?

    We did this because we can’t know the admin’s intent when they are changing a level. Do they want to make it free? Do they want to change the level without changing the payments? Do they want the user to pay a new subscription fee?

    Do anything but making the level free here would require some work on our part. Feel free to post your thoughts on how you think this could work and we’ll consider it.

    If you need to, you can change someone’s level through the DB or program your own way to change the level without cancelling the subscription. We can help you at https://www.paidmembershipspro.com

    Thread Starter lweilenman

    (@lweilenman)

    Wow….sorry to waste your time, I skimmed completely over the last half of that popup box, all I remembered was it would delete the current membership.

    I agree this issue is a bit tricky and I think you have handled it as it probably should be as an out-of-the-box solution. I was thinking (trying to figure out why I was having this problem and how to fix it) and I ran into all sorts of potential problems about having to notify the user to re-authorize a new amount on their Credit Card, etc.

    One thing that I thought of would be to (in the event and admin changes a user’s membership level) Notify the user with a confirmation link that says “Your level has been changed, you need to go to this link and re-authorize your payment information for the new amount, or go to this link to decline and remain at your current level. Until the user approves the change and any new charges, they would remain at their previous level, and the change would only take effect once they approved (Ex: User is Level A, but admin moves them to level B. This could be marked as Level B(pending), but user would still have permissions and charges of Level A until they approved to be moved to Level B, in which case the “pending” tag would be removed and they would now be official Level B members).

    Those are just my thoughts on how this could be handled if you ever decided to include this in the plugin by default. If we need to address this ourselves, I will definitely head over to your paid support area and chat with you guys there about it.

    Thanks again.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Paid Memberships Pro] Remove User/Posts when cancelling PMP subscription’ is closed to new replies.