Skip Navigation

[Resolved] Submitting one post per user allowed

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 3 voices.

Last updated by Jeffrey 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#630257

I have to re-open this ticket because it was still not working so far, https://toolset.com/forums/topic/limiting-one-post-per-user-not-working/, Could you please assign Luo to work with me if possible, because I have consulted many times on this issue, I guess he will know the issue I mentioned, also please send me the private link, so that I can describe some private information. Thank you so much again for you great help!

#630260

Assigned to Luo.
He will be back only next week.

Private reply also active.

#630456

Dear Jeffrey,

Please provide a database dump file of your website in below private detail box(ZIP file), I need to test and debug the PHP codes in my localhost, thanks

#630470

I have done below modifications in your website:
1) Edit the post group "Required information of host":
hidden link
add a custom field "User validation"

2) Edit the CRED form:
hidden link
Put above field into the CRED form, and hide it:

<div style="display:none;">
[cred_field field='user-validation' post='guest' value='' urlparam='' class='form-control' output='bootstrap']
 </div>

3) Modify your PHP codes to:

add_filter('cred_form_validate','my_validation_2',10,2);
function my_validation_2($field_data, $form_data)
{
    //field data are field values and errors
    list($fields,$errors)=$field_data;
    
    //uncomment this if you want to print the field values
    //print_r($fields);
    
    //validate if specific form
    if ($form_data['id']==105)
    {       
            $user = get_current_user_id();
            $user_post_count = count_user_posts( $user , 'guest' );
            $user_data = get_userdata($user);
            $user_role = $user_data->roles;
	  
        if ( $user_role[0] == 'guests' && $user_post_count > 0)
        {
            //set error message for my_field
            $errors['user-validation']='Only 1 post per user is allowed';
        }
    
      
    }
    
    //return result
    return array($fields,$errors);
}

Please test again, check if it is fixed.

#630473
$errors['user-validation']='Only 1 post per user is allowed';

Is it used to display a modal box if a user submits the second post? How can I translate that to Chinese in string translate of WPML?
Thank you so much for the help again, I have not tested yet, but I will do tomorrow.

#630503

You can wrap the text with wordress gettext function, for example:

$errors['user-validation']=__('Only 1 post per user is allowed', 'my-code');

Then translate it by following WPML document:
https://wpml.org/documentation/getting-started-guide/string-translation/

#862921

Trying to re-open the ticket