Page 1 of 2 12 LastLast
Results 1 to 10 of 18
Like Tree1Likes

Thread: Found solution!!! Limit the number of ads by user

  1. #1
    Thread Starter
    Member nathanmuniz's Avatar
    Join Date
    Jan 2012
    Posts
    81
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Found solution!!! Limit the number of ads by user

    Hello all!

    I found how to limit the number of ADS that a user can post. Take a look:

    I put the code on theme-functions, and create the folder css... put the ad_listing on the codes but it is not working... can someone help?

    This code will limit the number of posts a user can make.

    At first, I was trying to limit each user to one post and I had that working. Then I realized that I needed to have different numbers of posts for different users, so I created an option in a user’s profile that only people with the right capability (manage_options) can edit. I’ll be changing this in the future for that number to be automatically changed depending on a user’s subscription type, but I needed this for testing purposes.

    The option in the profile shows up under the contact info section, which I know is an odd place, but it was the easiest place to put it.

    Put the following into your functions.php file:
    PHP Code:
    // limit number of posts per user
    // provided by cleverness.org
    if ( !current_user_can('manage_options') ) {
        
    $default 1// default number of posts
        
    $count_posts 0;
        global 
    $wpdb;
        
    $poststable $wpdb->prefix.'posts';
        
    $postlimit get_user_meta($current_user->id'postlimit'true);
        if ( 
    $postlimit == '' $postlimit $default;
        
    $query "SELECT COUNT(*) FROM $poststable WHERE post_author = '$current_user->id' AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";
        
    $count_posts $wpdb->get_var($query);
        if (
    $count_posts >= $postlimit) {
            if ( 
    $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' )
                
    Header("Location: index.php");//redirects to dashboard
            
    if ( is_admin() ){
                
    $stylesheet =  get_stylesheet_directory_uri() . '/css/limitposts.css';
                
    wp_register_style('limitpost_admin_css'$stylesheetfalse'1''screen');
                
    wp_enqueue_style('limitpost_admin_css');
                }
        }
    }
     
    // add post limit option to profile
    add_filter('user_contactmethods','hide_profile_fields',10,1);
     
    function 
    hide_profile_fields$contactmethods ) {
        if( 
    current_user_can'manage_options' ) )
            
    $contactmethods['postlimit'] = 'Post Limit';
        return 
    $contactmethods;

    Create a file called limitposts.css, put the following into it, and save it in a directory called css in your theme folder (you can change where you save it, but be sure to change the location in functions.php).

    PHP Code:
    #menu-posts .wp-first-item + li {
        
    displaynone;

    If you want to use this for custom post types, change:
    PHP Code:
    if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' 
    to:
    PHP Code:
    if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php?post_type=customposttype' 
    and change the id name in your CSS:

    PHP Code:
    #menu-posts-customposttype .wp-first-item + li {
        
    displaynone;

    Be sure to replace customposttype with the name of your custom post type.
    FOUND AT: http://cleverness.org/2010/08/13/lim...-in-wordpress/

  2. #2
    rubencio's Avatar
    Join Date
    May 2010
    Location
    Spain
    Posts
    3,804
    Thanks
    268
    Thanked 316 Times in 278 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    aj270303 likes this.

    r u b e n c i o . c o m


    Since 2010 providing AppThemes solutions,
    Plugins and the best childthemes...



  3. #3
    Junior Member mayed's Avatar
    Join Date
    Jan 2012
    Location
    United Arab Emirates
    Posts
    28
    Thanks
    11
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  4. #4
    Thread Starter
    Member nathanmuniz's Avatar
    Join Date
    Jan 2012
    Posts
    81
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  5. #5
    targoviste's Avatar
    Join Date
    Jul 2010
    Location
    Romania
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  6. The Following User Says Thank You to targoviste For This Useful Post:

    marinel (April 13th, 2012)

  7. #6
    rubencio's Avatar
    Join Date
    May 2010
    Location
    Spain
    Posts
    3,804
    Thanks
    268
    Thanked 316 Times in 278 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

    r u b e n c i o . c o m


    Since 2010 providing AppThemes solutions,
    Plugins and the best childthemes...



  8. #7
    Thread Starter
    Member nathanmuniz's Avatar
    Join Date
    Jan 2012
    Posts
    81
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  9. #8
    laura's Avatar
    Join Date
    Apr 2010
    Location
    Michigan
    Posts
    2,594
    Thanks
    60
    Thanked 279 Times in 254 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  10. #9
    Thread Starter
    Member nathanmuniz's Avatar
    Join Date
    Jan 2012
    Posts
    81
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  11. The Following User Says Thank You to nathanmuniz For This Useful Post:

    buddhan (February 20th, 2012)

  12. #10
    Junior Member alabasta79's Avatar
    Join Date
    Nov 2011
    Posts
    22
    Thanks
    7
    Thanked 1 Time in 1 Post
    You must be an AppThemes customer and logged in to view this response. Join today!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can CP limit the number of listings a user posts within a timeframeq
    By m4rty5miff in forum ClassiPress General Discussion
    Replies: 4
    Last Post: August 17th, 2010, 08:36 AM
  2. Limit the number of free ads a single user can publish
    By karlo in forum ClassiPress General Discussion
    Replies: 1
    Last Post: May 16th, 2010, 06:17 AM
  3. limit to the number of free ads that a user can publish
    By karlo in forum Help Using ClassiPress
    Replies: 3
    Last Post: December 31st, 1969, 07:00 PM