Title: Unsubscribe user using php script
Last modified: August 21, 2016

---

# Unsubscribe user using php script

 *  Resolved [wahyu_anggg](https://wordpress.org/support/users/wahyu_anggg/)
 * (@wahyu_anggg)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/unsubscribe-user-using-php-script/)
 * Hay, is it possible if I want to unsubscribe user using php code or function?
 * my idea is to automatically unsubscribe user from their last subscription when
   they move to another subscription.
 * Thanks for help 🙂
 * [https://wordpress.org/plugins/membership/](https://wordpress.org/plugins/membership/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/unsubscribe-user-using-php-script/#post-4817961)
 * Hi [@wahyu_anggg](https://wordpress.org/support/users/wahyu_anggg/),
 * Thanks for your question and yes that’s possible!
 * For reference, you’ll find lots of helpful class methods in the following folder:
 *     ```
       \membership\membershipincludes\classes\class.membership.php
       ```
   
 * In there, you’ll see methods like the following:
 *     ```
       function current_subscription()
       function has_subscription()
       function move_to($sub_id, $thislevel_id, $thislevel_order, $nextlevel)
       ```
   
 * And specifically, I believe you’ll want this one:
 *     ```
       function drop_subscription($fromsub_id)
       ```
   
 * Given that, you could use a function like this to unsubscribe:
 *     ```
       function remove_subscription_from_member ( $user_id, $sub_id ) {
       	if ( class_exists( 'M_Membership' ) ) {
       		$member = new M_Membership($user_id);
       		$member->drop_subscription($sub_id);
       	}
       }
       ```
   
 * You then call the function with the user id for the member, and the id of the
   subscription.
 * How’s that work for you? 🙂
 * Cheers,
    David
 *  Thread Starter [wahyu_anggg](https://wordpress.org/support/users/wahyu_anggg/)
 * (@wahyu_anggg)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/unsubscribe-user-using-php-script/#post-4818089)
 * Hi [@david](https://wordpress.org/support/users/david/)
 * thanks for your help..
    it works very well 🙂
 * before you give this code, I used javascript, and it was not work very well.
 * thanks David 🙂
 * Cheers,
    Wahyu
 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/unsubscribe-user-using-php-script/#post-4818099)
 * Hi Wayhu,
 * You’re most welcome, glad that helps. 🙂
 * Any further questions, please feel free to ask. We’re happy to assist!
 * Cheers,
    David

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Unsubscribe user using php script’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/membership_b8cdaa.svg)
 * [Membership 2](https://wordpress.org/plugins/membership/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/membership/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/membership/)
 * [Active Topics](https://wordpress.org/support/plugin/membership/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/membership/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/membership/reviews/)

## Tags

 * [unsubscribe](https://wordpress.org/support/topic-tag/unsubscribe/)

 * 3 replies
 * 2 participants
 * Last reply from: [David](https://wordpress.org/support/users/ugotsta/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/unsubscribe-user-using-php-script/#post-4818099)
 * Status: resolved