>> grant users specific amount of posts they can publish

How can I do to grant users specific amount of posts they can publish ?

  • Ash
    • WordPress Hacker

    Hello there

    You can try the following code:

    function limit_user_by_post_count(){
    $user = get_current_user_id();
    if (!current_user_can( 'manage_options')) {
    //not an admin - so impose the limit
    $user_post_count = count_user_posts($user);
    header("Location: /wp-admin/edit.php");

    Here I set the limit to 10, you can change it. If the user is admin, there is no limit according to the above code.

    You can use this code in your theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!



  • James Morris
    • WordPress Enthusiast

    Hello Laurent_C,

    How to limit posts per user depends on the type of site you are running. If you are running a multisite network where you are giving your users their own blog, the best approach would be to use the Pro Sites plugin. There are a few modules available in that plugin that will enable you to limit publishing to a specific level and even limit the number of posts they can publish.

    If you have a standalone site, this can also be accomplished by using the Membership 2 plugin. You can enable the Member Capabilities add-on in the plugin and associate it with a specific membership level. This add-on will grant specific capabilities, such as publishing posts, to a membership level, which you can charge for. Then, using the mu-plugin Ash provided, they will be limited to a specific number of posts/pages.

    I hope this clarifies a bit.

    Best regards,

    James Morris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.