Home Forums Plugin Support WP User Frontend Pro Allow user to create only one post in a custom post type

This topic is: resolved

This topic contains 8 replies, has 3 voices, and was last updated by  Denis 4 years, 7 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2679

    noomia
    Participant
    Post count: 115

    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 !

    #2685

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #2690

    noomia
    Participant
    Post count: 115

    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 ?

    #2692

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #2694

    noomia
    Participant
    Post count: 115

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

    Thanks Tareq !

    #2771

    noomia
    Participant
    Post count: 115

    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

    #2811

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #2830

    noomia
    Participant
    Post count: 115

    Thanks !

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

    #23886

    Denis
    Participant
    Post count: 165

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

    was this line updated in an update?

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Allow user to create only one post in a custom post type’ is closed to new replies.