Support » Plugin: WPAdverts - Classifieds Plugin » Limit ads?

  • Resolved bdd

    (@bws-online)


    Is there any way to limit the number of ads a particular user can post at one time?

    Even better, any way to limit the number of ads a particular user can post in each category at one time?

    Thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    by default, there is no such feature in WPAdverts but you can add it using Limit User Active Listings snippet https://github.com/simpliko/wpadverts-snippets/blob/master/limit-user-active-listings/limit-user-active-listings.php

    By default the limit is set to 5, you can change it to a different number on line 40.

    Please note that that this will work only on logged in users, for the anonymous users it is impossible to check how many Ads they have already posted.

    How to install the snippet you can read here https://github.com/simpliko/wpadverts-snippets/ at the bottom of the page.

    bdd

    (@bws-online)

    Thank you Greg.

    No problem on this only working for logged in users, as only logged in users are allowed to see the ads anyway.

    I’ll have to do a little more testing here, but something’s a bit off/I have a question about something else.

    First the question — is there any way to let them know they’ve reached their limit BEFORE they fill out the whole ad and go to publish it?

    And for the part that’s a bit off — I also have it so that ads need to be approved before they’re published (per the moderate parameter being set to 1 as described here: https://wpadverts.com/documentation/allow-users-to-post-ads-adverts_add/). Right now it seems to be approving every other ad/putting every other one into moderation. I’ll have to turn off the Limit User Active Listings snippet to see if that was part of the problem. (I’ll let you know on that — if it’s not related to this snippet I’ll start a new topic.)

    Thanks again.

    bdd

    (@bws-online)

    I’m back. Noticed that the Limit User Active Listings message is actually triggering on other ad pages (not just the Add page). I’m going to start fresh and see what I see. So for the moment, please ignore my question above about letting them know they’ve reached their limit BEFORE they fill out the whole ad and go to publish it. Thanks.

    bdd

    (@bws-online)

    More problems now so I can’t test this out yet.

    When I attempt to edit the Add page, it’s saying “This page isn’t working” (that the URL is “currently unable to handle this request”) and giving me an HTTP ERROR 500. Is this a known issue?

    bdd

    (@bws-online)

    Okay. Looks like Limit User Active Listings was what was busting the Add page. Thoughts?

    Plugin Author Greg Winiarski

    (@gwin)

    The Internal Server Error is just a general error message, to find out an actual error message you would need to open file wp-config.php add there a line define( "WP_DEBUG", true ); and refresh the page it should show an error message which you can copy and paste here i should be then able to help.

    bdd

    (@bws-online)

    It’s showing a browser 500 error, not a WordPress error, so WP_DEBUG doesn’t provide any information.

    See: https://ibb.co/vk6HkhF

    Plugin Author Greg Winiarski

    (@gwin)

    Have you tried using the WP_DEBUG? With most servers using WP_DEBUG would show the actual error instead of 500 error, as most likely this is still a PHP error only covered with a 500 header so there are no debug information freely available to anyone.

    One other way to get the actual error message, is to open the error_log file and look for the error message there, it should be at the end of the file. If you are not sure where to get the error_log from you would need to ask the hosting tech support about it as the location of the file varies from server to server.

    bdd

    (@bws-online)

    Yes, I tried using WP_DEBUG — as I said, WP_DEBUG didn’t provide any information.

    I checked both the hosting Error Log (via cPanel) and the php_errorlog file directly — nothing is triggering from this error.

    I also confirmed that if I attempt to edit the page that contains the shortcode while the Limit Active Listings snippet/plugin is active I get the 500 error — turn it off, I can edit the page.

    Any other suggestions/advice? Thanks.

    Plugin Author Greg Winiarski

    (@gwin)

    Hmm without the additional debug information it is hard to suggest anything.

    I understand the problem occurs in wp-admin panel only when editing the page from wp-admin panel, there are two thing you can try:

    1. after line $max = 5; add line include_once ADVERTS_PATH . '/includes/shortcodes.php';.

    2. replace the line `
    add_action( “init”, “limit_user_active_listings_init”, 20 );`

    with

    
    if( ! is_admin() ) {
        add_action( "init", "limit_user_active_listings_init", 20 );
    }
    
    bdd

    (@bws-online)

    Thank you very much Greg.

    I tried both options individually, and they each eliminated the problem.

    I tried both at the same time, and it worked, too.

    Do you recommend one or the other options — or both?

    Plugin Author Greg Winiarski

    (@gwin)

    Ok great i am glad you have it resolved.

    When updating the code snippet i think i will go with the solution #1, but in the end i think it will not make much (if any difference) so you can select the solution you like or both of them.

    bdd

    (@bws-online)

    When using Limit User Active Listings with moderation, is there a way to limit it BEFORE the ads are moderated? In testing, just had a user submit 4 ads for moderation.

    Plugin Author Greg Winiarski

    (@gwin)

    You should be able to do that by changing in limit-user-active-listings.php file the line

    
    'post_status' => 'publish',
    

    to

    
    'post_status' => array( 'publish', 'pending' ),
    
    bdd

    (@bws-online)

    Looks good — thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.