How do I set the the media quota and products quota to numbers for different levels?

When using the quota system (screen shot):

I would like to be able to set the media quota and the product quota to individual numbers for each level.

However instead they are stuck at the setting: same as posts, and same as pages.

What am I doing wrong that does not allow me to set these settings to a number? Thanks!

  • Aaron
    • CTO

    It's not technically possible because they share the same capability in Wordpress. Example "publish_posts". As the module works by removing the capability for all blog users, if two post types share the same capability the limits will be shared.

    It is possible to change capabilities for a given post type but that requires custom coding generally.

  • Ben
    • The Reaper

    I don't understand your response....

    Wouldn't it be simple enough to have the module, when in the user's admin mode, count the number of items that are products or separately count the number of items that are media, then compare that number to a set quota, and if that count is lower than the quota set in this area, allow the user user to add a product or media item, and if it is equal or above the quota, disable the ability to add a new product or media item.

    It seems this is the intuitive way to have it set up, no? If that is not how the limit is set up, then +1 for doing it this way.

  • Ben
    • The Reaper

    Perhaps in the admin an sql statement could be run to get the product count to run a comparison against a quota for number of products allowed:

    SELECT * FROM {THE USER BLOG TABLE} where post_type = 'product' and status = 'published'

    Perhaps in the admin an sql statement could be run to get the media count to run a comparison against a quota for number of media items:

    SELECT * FROM {THE USER BLOG TABLE} where post_type = 'attachment' and status = 'inherit'`

    I am new to word press (but not new to PHP), I think this shouldn't be too hard to do for the plugin developer...or am I missing something?

  • Alexander
    • DEV MAN’s Mascot


    Wordpress provides APIs for dealing with the database to developers don't have to often. It's easy enough to find the number of posts with wp_count_posts function - which is how the plugin checks this.

    It doesn't really matter how you count them, I think what you're missing here is the limitation when it comes the logic that handles preventing new posts. Aaron explained this above.

    When the quota is reached, this module removes the "publish_posts" capability from the users. Here are the capabilities we have to work with in Wordpress:

    This module doesn't support custom post types as it is, but if you really need it here's a suggestion. If you open posting-quota.php, take a look at the write_filter function starting on line 19 With a bit of custom coding, this can easily be modified to suite your needs with custom post types.

    Best regards,

  • Ben
    • The Reaper

    >> they need to have custom
    >> capabilities for the limit 

    Hey aaron, thanks for the reply. When you say custom capabilities do you mean a settibg or field needs to be creates? If you could, please clarify what custom capabilites means. Thanks!

    And alex, thanjs for the info on counting posts.

  • Ben
    • The Reaper

    I'm still confused and want to make sure I am on the same page and we are talking about the same thing. Are you refering to how to save a variable for creating a new post of a different type? Or Are you suggesting that giving the user a quota for attachment media or products should be done in a new post capability type?

    Is the capability_type in the wordpress the same as the post_type in the actual database?

    For counting the number of products the user has or the number of attachment media in use the post_type in the database has already been set so it should be easy to tally up the ussage...right?

  • Alexander
    • DEV MAN’s Mascot

    @Aaron, thanks for the clarification! I see what you mean about the custom post types. Sorry for missing that they are supported here, and for any confusion caused.

    @Ben When a plugin declares a custom post type, it will by default piggyback along with the posts capability.

    To see this in action, try network activating our Classifieds plugin. In Pro Sites, you'll see that you can change the number accordingly.

    The shared capabilities is quite convenient because it means the post type will just follow along with the rules for normal posts. This also means that editors, and other built in roles will be able to work with the type without any extra setup. So it's quite beneficial in that regard.

    The downside is, if any plugin, where to remove that capability from a user (like the upload quota) you lose the privileges for all custom post types that are using it.

    This is why you can't alter the number. If you had Products to 5 and posts to 10, as soon as someone posted the 5th product, the user would lose the ability to publish posts. Going back to the counting, all the counting is done for you, but the limiting as we can see has a wider range of effect.

    The solution is custom coding to add new capabilities when plugins register a post type. See Aaron's link to the codex article for register_post_type above.

    Is the capability_type in the wordpress the same as the post_type in the actual database?

    No, they are two separate entities. Custom Post Types are assigned a capability when they are registered. Capabilities are added to users by plugins, or when they are assigned a new WP Role. When certain actions need to be performed, Wordpress checks to see if the user has the appropriate capability for the post type in context.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.