Support

Account

Home Forums ACF PRO Admin Aproval Reply To: Admin Aproval

  • Hi @manu

    I’ve attached an image of a field group as an example. With that field group, I created a front end form like this:

    acf_form(array(
        'post_id' => 'user_99',
        'fields' => array('field_574d2ee6b5a16'),
    ));

    Where “99” is the ID of a user you want to update (you can dynamically generate it, of course). After that, I use this function in my functions.php to check if an admin approved the submitted data or not:

    add_action('acf/save_post', 'example_save_temporary_user_data', 20);
    function example_save_temporary_user_data( $post_id )
    {
        // The approval should be on the back end only;
        if( !is_admin() )
            return;
        
        // Check if an admin approve it or not
        if( get_field('approve_example_text', $post_id) ){
            
            //get the temporary data
            $temporary_data = get_field('example_text', $post_id);
            
            // $post_id contains "user_99" so $user_id should "99"
            $user_id = str_replace('user_', '', $post_id);
            
            // update the user data (in this case the first name)
            update_user_meta( $user_id, 'first_name', $temporary_data );
        }
    }

    You can also use the acf/load_value field to always make the true/false field unchecked.

    I hope this makes sense 🙂