Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Yes, there are multiple ways to achieve it.

    1. Hide the form on the template page

    You could get the posts of the currently logged user, and if there is more than one post, do not call the acfe_form() functions. Usage example:

    // get current user posts
    $get_user_posts = get_posts(array(
        'post_type'      => 'post',
        'posts_per_page' => -1,
        'author'         => get_current_user_id()
    ));
    
    // if user have less than one post, show the form
    if(count($get_user_posts) < 1){
        acfe_form();
    }

    2. Hide the form using a hook

    You could use the same method, but within the acfe/form/load hook. Useful if you’re using the shortcode. See documentation.

    3. Use a form validation error

    An another solution could be to check the user posts count inside a form validation hook, and throw an error if he already has a posted something. You can do that using the acfe/form/validation action. See documentation. Usage example:

    add_action('acfe/form/validation/form=my-form', 'my_form_validation', 10, 2);
    function my_form_validation($form, $post_id){
        
        // get current user posts
        $get_user_posts = get_posts(array(
            'post_type'      => 'post',
            'posts_per_page' => -1,
            'author'         => get_current_user_id()
        ));
        
        // count user posts
        if(count($get_user_posts) >= 1){
            
            // add validation error
            acfe_add_validation_error('', 'You are not allowed to post more than one time');
            
        }
        
    }

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Limit user to 1 post’ is closed to new replies.