Skip Navigation

[Resolved] how to allow the site member to make only 1 post using post form ?

This support ticket is created 5 years, 11 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Shane 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1207500

hi team ..

i have a no programming experience ..

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 ?

please guide me how to do it

thank you

#1207681

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for getting in touch.

I've worked on a ticket previously with this issue.

Take a look at the link below.
https://toolset.com/forums/topic/limiting-cred-form-submission-to-one-post/

This should be able to guide you through the getting this to work.

Thanks,
Shane

#1210740

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';
}

//check if featured image exists

}

//return result
return array($fields,$errors);
}

#1211404

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

I see some inconsistencies here.

Could you let me know the role of the user that you want this to apply for ?

Thanks,
Shane

#1211405

user role : authors

#1211551

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

So your code should be.

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'

Please try this and let me know the results.

Thanks,
Shane