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'