Membership Plugin, Database Interaction and Admin Panel Permissions

Hi,

If you've been following my escapades so far, I have been directly interacting with the database to modify rules, levels and subscription types. For more information, you can view the topics:

https://premium.wpmudev.org/forums/topic/membership-functionality-ii-ipn-filters-and-drip-feeds
https://premium.wpmudev.org/forums/topic/membership-functionality-iii-paypal-integration-and-ipn#post-83062

If anything in this topic doesn't make sense, please ask me for clarification. I would appreciate help on this!

So far, everything is working really well! I have a few problems though, which seem to deal with permission issues and the Membership plugin admin panel. First and foremost, if I create subscriptions using the admin panel, I have absolutely no trouble modifying them, deleting them, or batch-processing them. The problem arises when I try to modify subscriptions which are being generated by my scripts.

I first noticed this when I was cleaning out old test accounts. I would delete the account using Wordpress, and notice that all of the subscriptions, rules and levels tied to that account remained. So, I went through the admin panel, and batch-selected every subscription I wanted to delete (all of which were created outside of the admin panel.) When I went to click "delete," I was sent to the "You do not have access page." which is a selectable Membership plugin option. I thought that was strange, so I tried to delete subscriptions manually, and I received an error similar to:

Subscription not deleted.

I thought that it was strange that all of these subscriptions, rules and levels remained after I deleted a user, but I let it slide and deleted all of that data through phpMyAdmin. Just recently, while trying to activate a subscription via the hook 'membership_payment_processed' (unfortunately, the gateway isn't activating subscriptions that have received payment, I had to write code to do it instead) I found that I could not activate or deactivate any subscription I had created outside of the admin panel. I received the error:

Subscription activation not toggled.

It appears that my administrator account doesn't have permission to do this kind of stuff. Weird, huh?

I understand that you would rather I not modify the subscriptions outside of the administrative panel, but the scope of this project demands that I do. What do I need to do to enable subscription modification for the administrator when creating subscriptions outside of the admin panel?

Thank you for your help.

  • Philip John

    Hi Dseason!

    Okay, I think first what you need to do is run a few tests.

    Manually run all the tasks you want to automate and log everything that happens in the database.

    Then, run them using your automated scripts and compare the changes in the database to the ones made by the manual tasks.

    It sounds like a simple case of not all the required changes getting through your automation process.

    Phil

  • Barry

    Hi
    One of the things to check on the admin area is if there are any users assigned to subscriptions / levels. The admin interface won't let you delete or deactivate (toggle) subscriptions or levels that have users on them for the obivous reason that you have subscribers on those levels and really should move them to something else before removing their permissions from under them.

    Obviously, in the db you can remove these without this check (the big table to check in this case is the membership_relationships table).

  • Barry

    I first noticed this when I was cleaning out old test accounts. I would delete the account using Wordpress

    Yeah - i need to sort that out - good find, for some reason hooking into the delete user functionality didn't make my implementation list. But the table i mentioned above is the key to clearing out - do a:

    DELETE FROM wp_m_membership_relationships WHERE user_id NOT IN (
    SELECT ID FROM wp_users);
  • dseason

    Phil - So far I believe everything is being populated correctly (only because I haven't noticed anything out of the ordinary.)

    Barry - I see. This is how I had it setup in my head:

    Assign each user their own private subscription, to give them unique posts/page access. They would never be moved away from their subscription. When the subscription is activated, they have access to all of their posts. When the subscription is deactivated, it's essentially suspended.

    I may need to implement an alternative, like user meta data that says whether or not they're subscribed and include a small admin panel where the administrator can suspend a subscription by setting that meta data to 0.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.