[Resolved] how to allow the site member to make only 1 post using post form ?
This support ticket is created 5 years, 9 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
help me .. how to allow site members to make only 1 post using post form ?
OR
how to hide the form from users who already published a post on my website ?
ok .. i use the form for creating pages ( .. please tell me what changes to make to the filter and how to hide the validation field with css code
i changed the form id & the field slug is ok .. i tried to change the filter as follows but not working : -
--------------------
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($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']==20111)
{
$user = get_current_user_id();
$user_post_count = count_user_posts( $user , 'page' );
$user_data = get_userdata($user);
$user_role = $user_data->roles;
if ( $user_role[0] == 'page' && $user_post_count > 0)
{
//set error message for my_field
$errors['wpcf-user-validation']='Only 1 post per user is allowed';
}
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($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']==20111)
{
$user = get_current_user_id();
$user_post_count = count_user_posts( $user , 'page' );
$user_data = get_userdata($user);
$user_role = $user_data->roles;
if ( $user_role[0] == 'author' && $user_post_count > 0)
{
//set error message for my_field
$errors['wpcf-user-validation']='Only 1 post per user is allowed';
}
//check if featured image exists
}
//return result
return array($fields,$errors);
}
You had $user_role[0] == 'page' when it should be $user_role[0] == 'author'