Membership Pro 2: Automatically delete expired members

I need to auto-delete expired members from Membership Pro 2, otherwise, they are unable to re-register again later.

  • Huberson

    Hi Jonathan,
    The expired members can actually renew their subscription or sign up for a different one with their current profile/account without a new registration.
    If what you need is to remove them entirely so they can register/subscribe again with a new account you can use that filter

    <?php
    add_filter( 'ms_model_relationship_set_status',
    	function( $status, $subscription ){
    
        if ( MS_Model_Relationship::STATUS_EXPIRED == $subscription->status || strtotime( $subscription->expire_date ) < strtotime( 'now' ) ) {
            wp_delete_user( $subscription->user_id );
        }
        return $status;
    
    }, 10, 2 );

    It can be added within a file under 'wp-content/mu-plugins' directory or inside functions.php file.

    Note that the code will delete the user from the site entirely as soon as her subscription expired.

    Regards,
    Huberson

  • Jonathan

    Hi,

    Thanks for your wonderful reply.
    It gives me some lights.

    1) From your scripts,
    wp_delete_user( $subscription->user_id );
    May I know whether deleting a Wordpress User will also CLEANLY delete all that User's data from Membership Pro 2?

    2) May I know how does the expired members can actually renew their subscription or sign up for a different one with their current profile/account without a new registration? Which page or what shortcode I can use?

    Please advise. Thank you.

  • Kasia Swiderska

    Hello Jonathan,

    May I know whether deleting a Wordpress User will also CLEANLY delete all that User's data from Membership Pro 2?

    All usermeta will be deleted for that user - and info about user subscription is kept in user meta. So yes, it will be removed.

    2) May I know how does the expired members can actually renew their subscription or sign up for a different one with their current profile/account without a new registration? Which page or what shortcode I can use?

    They can do that from membership list page or from account page (and then click link "Change membership" that links to membership list page).
    Membership list page uses

    [ms-membership-signup]

    Other shortcodes with description you can find on this page in your WordPress

    /wp-admin/admin.php?page=membership2-help&tab=shortcodes

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.