Creating a plugin to Increase members' storage space over time

I run a small membership site, and I currently allocate members a certain amount of storage space when they sign up.

I want to implement a system, however, whereby a member's storage space increases over time. It would increase by a set amount each month depending on that person's membership level.

Eg. Level 1 gains 200MB per month. So they start on 100MB in month 1, then they have 200MB storage in total in month 2, and then 300MB storage in total in month 3, and so on. Level 2 might add 200MB to their storage total each month.

I can't find a plugin on here, or anywhere else, that does this so I'm guessing I need to build one myself!

I feel like this wouldn't be complicated to implement, but would appreciate some help in getting started. I've messed around with creating plugins before, but I'm still an amateur.

If you could point me in the right direct of the Wordpress code to edit this type of stuff I'd really appreciate it.

Thanks,
Colin

  • Alexander
    • DEV MAN’s Mascot

    Hey @Colin,

    Nice chatting with you in live support this morning. Got a few more questions, and some info for you.

    Are you using Multisite? Or are you already using something to manage the upload space? By default, WordPress single site doesn't impose anything. On Multisite, an upload quota can be set, but it works on a per site basis - not per user.

    Curious to see if you have anything so far. If not, could you give a bit more context on how it will be used?

    Membership specific functions for access and subscription info can be found in membershipincludes/includes/functions.php

    As for working with the multisite upload quota, take a look at how Pro Sites does it in the upload quota module: https://premium.wpmudev.org/project/pro-sites/

    Best regards,

  • Colin
    • Site Builder, Child of Zeus

    Good question! Sorry, that was a pretty obvious thing to tell you.

    Yes, I'm using Multisite, and I'm not running any particular membership plugin - I actually manage the memberships manually (it's very small, quite niche, quite tailored, and just works fine that way). But, the one thing I would like to automate is the increasing storage space. And, yes, it would be "per site" rather than "per user" as I mentioned - my mistake.

    I know pro-sites can set a storage quota for a site based on the amount paid, but as far as I know it can't increase it regularly - is that right?

    Thanks for your help!
    Colin

  • Alexander
    • DEV MAN’s Mascot

    Hi @Colin,

    I'm sorry for the delay here. Yes, then it sounds like Pro Sites is the way to go. As for custom coding something to increase it over time, I would recommend working from the existing upload quota module for Pro Sites.

    Then you could use wp_schedule_event to setup a scheduled job. In the hook, you would need to write a function that retrieves the currency quota, increments it, then saves it again.

    Best regards,

  • Alexander
    • DEV MAN’s Mascot

    Hi @Colin,

    Sure, you can check Membership level using the functions found in membershipincludes/includes/functions.php There are a few simple functions for checking if a user is on a level or subscription, like these:

    current_user_on_level
    current_user_on_subscription

    Another function that might help you is: get_active_blog_for_user

    This Wordpress function will take a user ID, and give you that user's primary blog, which would be the one they are an admin of. Then you'll have the blog ID to work with the upload quota amount.

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.