This topic contains 8 reply and 3 voices, and was last updated by Denis 5 years, 3 months ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
April 22, 2013 at 11:37 am 2679
Denis Hi everybody ! I would like to know if it's possible with WP User Frontend to limit the number of post a user can create for a particular custom post type ? I want to allow my users to only create one company (custom post type "companies"), not more. Thanks in advance !
April 22, 2013 at 11:52 am 2685
Tareq Hasan Tareq Hasan

Yes it’s possible. When a new post has been made, update the user meta with the post count. Then you need to use the `wpuf_can_post` filter and check if the users post count == 1, if it’s true, return “no” from that filter and the user will not be able to submit more posts.

April 22, 2013 at 12:08 pm 2690
noomia noomia

update the user meta with the post count

You mean that I have to create a specific meta for users which will handle this value ?

April 22, 2013 at 12:11 pm 2692
Tareq Hasan Tareq Hasan

Yeah, a user meta, e.g: `company_post_count`, which will count the number of posts the user created. So now you can track which users have how many post and limit them.

April 22, 2013 at 12:21 pm 2694
noomia noomia

Nice one 🙂 ! I’ll try and let you know if I need more help 🙂 !

Thanks Tareq !

April 23, 2013 at 12:07 pm 2771
noomia noomia

Then you need to use the wpuf_can_post filter and check if the users post count == 1, if it’s true, return “no” from that filter and the user will not be able to submit more posts.

I don’t see how to deal with that :s…

Also, I have other custom post types in my website. So I want user to only post 1 company. Then, if he has posted 1 company, he is allowed to post other custom post type (like news, jobs, projects, …). If he hasn’t post 1 company, he is not allowed to post other custom post type.

So how can I restrict the acces to a page (which contain a post form) to only the users that have posted 1 company ?

Thanks

April 24, 2013 at 9:54 am 2811
Tareq Hasan Tareq Hasan

You need to add filter like this:
[php]
function wpufe_restrict_post( $permission, $form_id, $form_settings ) {
if ( ‘company’ == $form_settings[‘post_type’] ) {
$post_count = get_user_meta( get_current_user_id(), ‘company_post_count’, true );

if ( $post_count == ‘1’ ) {
return ‘no’;
}
}

return $permission;
}

add_filter( ‘wpuf_can_post’, ‘wpufe_restrict_post’, 10, 3 );
[/php]

But I suppose you need to change a bit of code `/class/frontend-form-post.php`. Currently the version you are using provides only one parameter to that filter. Changing the line 33 to this will allow you to access the form settings like the code above.
[php]$user_can_post = apply_filters( ‘wpuf_can_post’, ‘yes’, $id, $form_settings );[/php]

April 24, 2013 at 11:42 am 2830
noomia noomia

Thanks !

Could you please add this (modification on line 33) in the nextupdate ?

July 21, 2014 at 8:38 pm 23886
Denis Denis

$user_can_post = apply_filters( 'wpuf_can_post', 'yes', $id, $form_settings );

was this line updated in an update?

Viewing 8 Posts - 1 through 8 (of 8 total)