1

My goal is to get a signed-in user to select a color( via front end form and saved in ACF user meta field group) that will be applied to another user meta field inside a repeater. The field must be the same for each row inside the repeater ( for front-end design reasons ). I am using ACF pro, and a plugin called ACF Front end admin (let's call it FEA from now on) for the front-end form. I'm pretty new to PHP and have referenced ACF & FEA's s documentation, which can be found below, spin up a custom function. I am currently running this through the code snippets plugin if this helps. I've run an error log and nothing related to this shows. Tried running this through wp-config and it crashes my site.

Edit, Additional information: ACF Field composition of 'button color' (color of the buttons that user wants displayed in front end, and saved as user meta):

acf_add_local_field_group(array(
    'key' => 'group_60000aaa00000',
    'title' => 'Color Selector',
    'fields' => array(
        array(
            'key' => 'field_60000aaa00000',
            'label' => 'Button color',
            'name' => 'button_color',
            'type' => 'color_picker',

Button color in repeater field that needs to updated based on the above mentioned 'button_color' meta value:

acf_add_local_field_group(array(
    'key' => 'group_70000bbb00000',
    'title' => 'front end user profile',
    'fields' => array(
        array(
            'key' => 'field_70000bbb00000',
            'label' => 'Quick Link selector',
            'name' => 'quick_link_selector',
            'type' => 'repeater',
            ),
                array(
                    'key' => 'field_70000ccc00000',
                    'label' => 'repeater button color',
                    'name' => 'repeater_button_color',
                    'type' => 'text',

The title of the forum is: "QL color selector form" (created through the FEA plugin) and has a short code of [frontend_admin form="3030"] if this helps.

I'm running the following code with no luck and would really appreciate any help!

 
/// Hooks into any(?) form and does something
add_action('acf_frontend/save_user', 'retrieve_colors_2_update', 10, 2);
function retrieve_colors_2_update( $form, $user_id ) {
    $user = get_user_by('ID',$user_id);
    //get important fields
    $btn_color = get_field('button_color', 'user_' .$user_id);
    //// update a repeater loop (ACF)
    if( have_rows('quick_link_selector', 'user_'.$user_id) ) {
        $i = 0;
        while( have_rows('quick_link_selector') ) {
            the_row();
            $i++;
            update_sub_field('repeater_button_color', $btn_color );
    }
}
}
Luca
  • 11
  • 3
  • There's a lot of wrong code here. But fine, let's begin with question at a time. Where is the another user id you want to save the color for? – Vinay Jain Aug 24 '22 at 03:36
  • Also, update your question with the form being submitted via frontend and it's ACF field IDs in backend. – Vinay Jain Aug 24 '22 at 03:37
  • Hi @VinayJain, thanks for your help. To answer your question, the user ID im using should reference from wp_user, ( I think? ) and I'm not sure where ACF stores its user fields ( maybe wp_usermeta from what I could find ) but I was able to pull some info for my fields I think may be relevant : 'location' => array(...'param' => 'user_form', - This location parameter is pretty much how I've set all my ACF fields to customize the WordPress user. Appreciate the suggestion, will update my question as suggested! – Luca Aug 26 '22 at 03:47
  • @Luca message me over skype at priyankit57 and i will personally checkout and do your functionality – Priyank Sep 02 '22 at 05:25

0 Answers0