Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to know is there any way/Plugin to limit the user published post (in a given time span) by his role?

Like this:

  • Role A -> 1 post per day and 30 post total.
  • Role B -> 10 post per day and 100 post total.
  • Role C -> unlimited.

I know there are some plugin out there that have these features but they only able to control either limit post per day or limit number of posts on role basic, and they are not mutually inclusive on each other.

Note: This is to prevent the real estate platform from being spamed. (Editors note)

Any ideas?

share|improve this question
    
1  
Well, what I am doing is a real estate site, which different from the content website. The limitation is intended to avoid spam and in the meantime to monetize from it. –  dev-jim Apr 24 '12 at 15:11
    
Ah, ok. Well explained. –  kaiser Apr 24 '12 at 15:12
    
    
Oh, thank you for the suggestion...will take a look at it.. –  dev-jim Apr 24 '12 at 15:18
add comment

2 Answers 2

up vote 1 down vote accepted

You can use my plugin Posts Creation Limits which has a per user, per role, per post type, per post status limiting system and combined with its post_creation_limits_custom_checks action hook and check if the user has created a post that day already - if so: show the the "limit reached message". For example:

add_action( 'post_creation_limits_custom_checks', 'post_per_day_limit' );

function post_per_day_limit( $type, $user_id ) {
    global $bapl,$wpdb;

    // safe check: Plugin installed?
    ! isset( $bapl ) AND _doing_it_wrong( __FUNCTION__, sprintf( 'You need to %sinstall the needed Plugin%s', '<a href="http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/">', '</a>' ), 0 );

    $time_in_days = 1; // 1 means in last day
    $count = $wpdb->get_var(
        $wpdb->prepare("
            SELECT COUNT(*) 
            FROM $wpdb->posts 
            WHERE post_status = 'publish' 
            AND post_type = %s 
            AND post_author = %s
            AND post_date >= DATE_SUB(CURDATE(),INTERVAL %s DAY)",
            $type,
            $user_id,
            $time_in_days
        )
    );
    if ( 0 < $count ) 
        $count = number_format( $count );

    // here you can check since we have the $count ex: 
    // limit for 2 posts a day
    if ( 1 < $count ) {
        // return limit reached message using the plugin class
        exit( $bapl->bapl_not_allowed( 'you can not posts more them two posts a day' ) );
    }
    // else do nothing
}
share|improve this answer
    
If I not mistaken, your codes is limit the post on all user, not particular on user's role, right? –  dev-jim Apr 24 '12 at 12:37
1  
Take a look at the $user_id inside the query. –  kaiser Apr 24 '12 at 14:51
    
Kaiser that's correct! –  Bainternet Apr 24 '12 at 15:10
    
When I paste this code to functions.php, the site get fatal error, any idea why? –  dev-jim Apr 24 '12 at 15:13
1  
I figure it out the what causing the error, the $bapl=> should be $bapl->. –  dev-jim Apr 25 '12 at 14:47
show 3 more comments

You dont need to rely on

//Limit posts per month
    $time_in_days = 1; // 1 means in last day
    $count = $wpdb->get_var(
        $wpdb->prepare("
            SELECT COUNT(*) 
            FROM $wpdb->posts 
            WHERE post_status = 'publish' 
            AND post_type = %s 
            AND post_author = %s
            AND post_date >= DATE_SUB(CURDATE(),INTERVAL %s DAY)",
            'post',
            get_current_user_id(),
            $time_in_days
        )
    );
    if ( 0 < $count ) 
    $count = number_format( $count );

    // here you can check since we have the $count ex: 
    // limit for 2 posts a day
    if ( 1 < $count ) {
        // return limit reached message using the plugin class
         $errors[] = 'You have reached your monthly post limit';
    }

Where I have $errors is where you can echo a message, in my case I' plugging into the WP user frontend.

If you wanted to do it by role than you can simply add another if statement checking if that user has the correct role inside the if ( 1 < $count ) {}, it does then echo your code or run a redirect to an error page.

share|improve this answer
    
Rely on what? You should optimize your explanation further - thanks! –  ialocin Jan 31 at 12:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.