Support

Account

Home Forums ACF PRO Admin Aproval

Solved

Admin Aproval

    • Manu

    • May 30, 2016 at 4:24 pm

    Hello,
    i want to approve all acf_forms with the rule
    User form >> is equal to >> add / edit

    My question is. What do I do best?

    My idea is
    1) create new table wp_usermeta_wating_approval
    2) save new update first into the wp_usermeta_wating_approval
    3) Create GUI for the Admin

    Approve:
    -> move all (from user XXX)
    from wp_usermeta_wating_approval into wp_usermeta

    Is this possible? Do you know a better way?
    I appreciate any help.

    • James

    • May 30, 2016 at 4:56 pm

    Hi @manu

    I believe it will be simpler if you use the True/False field type.

    With that field type, you can create a field type that will tell you that an account is approved or not. It will be easier to update too. Don’t forget to check this field when you need to query the accounts.

    I hope this makes sense 🙂

    • Manu

    • May 31, 2016 at 11:04 am

    Hi James,
    Thanks for the fast reply but your solution does not work.
    I think you don’t get it (i know, bad english, sry :/ ).

    # An user update fields (for example: City, Name, Age, About me Text)

    # Only the User see the changes, all other user (including the admin) see the “old” values.

    # The admin must confirm (on a custom Page in the ACP) the changes
    Age -> ok -> Update user Profile
    Name -> ok -> Update user Profile
    About me Text -> not ok -> sent email and delete entry

    I know that is a lot of work, but i need this feature.
    Thanks in advance!

    • James

    • May 31, 2016 at 12:37 pm

    Hi @manu

    In my opinion, creating a custom table for this case would be too complicated and it’s not related to ACF anymore. Instead, I think you can create a group field where users can save the temporary data and you can create a front end from for that field group.

    You can also create a true/false field for each field for the admin to approve the data. Then you can use the acf/save_post hook to check if the admin approved the data or not. If he did, then the code will automatically update the real data by using the update_user_meta() function.

    I hope this makes sense 🙂

    • Manu

    • May 31, 2016 at 3:39 pm

    Sorry i dont get it 🙁

    I add (for example) the true/false field to the user “about me” field.
    On the frontend i check if the field “about me” is true (approved) or false (disapproved)

    If true, i show the normal “about me” field.
    If false, … where do i get the old value?

    • James

    • May 31, 2016 at 4:57 pm

    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 🙂

    • Manu

    • June 21, 2016 at 3:13 pm

    21 days later and i think the solution with the true/false field will not work for me. I have over 200 fields and i don’t want to add for every field an extra true/false field.

    What i have:

    JS

    // ##### TEXT #####
    $("input[type='text'],textarea").change(function ()
    {
        // mark input field with red Border
        $(this).addClass('editNow');
    
        // STOP FLOODING
        if(typeof editNow_select_TM != 'undefined') { clearTimeout(editNow_select_TM) }
        editNow_select_TM = setTimeout(function() 
        { 
            var newDataObj = [];  
    
            // get all changed input fields            
            $('#setCardManager_allForms :input.editNow').each(function(e)
            {
                newDataObj.push({   setCardId: $('#setCardManager').data('setcardid'), 
                                    type : 'input',
                                    fieldId : this.id, 
                                    fieldValue : $(this).val() });                                
            }); 
    
            // save to DB
            updateSetCard('select',newDataObj);
    
            // clear Timeout
            delete editNow_select_TM;     
        },1500);
    });
    
    // ##### DROPDOWN #####
    $('#setCardManager_allForms select').change(function ()
    {
        // save to DB
        updateSetCard('select',({   setCardId: $('#setCardManager').data('setcardid'), 
                                    type : 'select',
                                    fieldId : this.id, 
                                    fieldValue : $(this).val() }));
    });    
    
    // ##### CheckBox #####
    $(':checkbox').change(function() 
    {
        // save to DB
        updateSetCard('select',({   setCardId: $('#setCardManager').data('setcardid'), 
                                    type : 'checkbox',
                                    fieldId : this.id, 
                                    fieldValue :this.checked }));
    }); 
    
    // ##### REPEATER FIELDS #####
    $(':checkbox').change(function() 
    {
       // hmmm, not so easy
    }); 

    PHP
    I created a copy from wp_postmeta with the name wp_postmeta_draft.

    The function updateSetCard() store the new values in this table.
    update_post_meta_draft(setCardOpt['setCardId'], setCardOpt['fieldId'], setCardOpt['fieldValue']);

    If the admin confirm

    update_field($selector, $value, $post_id);
    delete row from wp_postmeta_draft

    ACF is new for me so i’m not sure:
    – will this solution work with any problems?
    – did i forget something?

    Thanks in advance and sorry for the late reply.

    • James

    • June 21, 2016 at 3:38 pm

    Hi @manu

    In that case, I think your solution would be the best for you. I’m not sure if the new table will create an issue in the future or not. For further support regarding the new table, I suggest you consult to WordPress Support forum instead.

    Thanks 🙂

  • The built-in administrator account logs on in Admin Approval Mode so that any operation that requires elevation of privilege displays a prompt that provides the administrator the option to permit or deny the elevation of privilege.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.