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!
Assigned to Luo.
He will be back only next week.
Private reply also active.
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
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.
$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.
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/
Trying to re-open the ticket