• Resolved dionix

    (@dionix)


    Can this be done with ACF EXTENDED?

    Limit the publication of forms from the frontend to a specific amount according to the user role.

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

    (@hwk-fr)

    Hello,

    This is more a page display restriction problem than form restriction. Because one ACF Extended Form can do 50 differents actions with one single submission (add posts, update an another etc…). I could add some restrictions conditions in the form setting, but it could quickly become very complex:

    Hide form if user role X has more than 5 posts in the post type Y within the last 24 hour. etc…

    Also, if I add UI for restrictions, maybe it should be added to form actions (micro management) instead of global form setting (macro management). Maybe some users would like to restrict actions instead of whole form display. It’s complicated to find the perfect solution. It should be very flexible to fulfil everyone’s needs.

    The best way to achieve it, is by writing your own PHP condition on the page that call the form. You have to count the current user posts and check if it’s higher than your limit.

    Here is a code example:

    
    $user = wp_get_current_user();
    
    // Check if current user has role 'author'
    if(in_array('author', (array) $user->roles)){
        
        // Get posts of the current user (by post_author)
        $check_posts = get_posts(array(
            'post_type'         => 'my_post_type',
            'post_author'       => get_current_user_id(),
            'posts_per_page'    => -1,
            'fields'            => 'ids'
        ));
    
        // Display form if the current has less than 5 posts
        if(count($check_posts) < 5){
            
            // Call my form
            acfe_form('my-form');
            
        }else{
            
            ?>
            <h3>You already posted more than 5 posts.</h3>
            <?php
            
        }
    
    }
    

    I haven’t tested the code, but it should work.

    Hope it helps!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Limit Forms Post’ is closed to new replies.