I need to add an usermeta field for users when they decide to modify some account informations on a custom form. At the moment I'm calling the wp_update_user()
but since I want that the modifications are approved first, I want to add a field into user meta that will replace the actual usermeta informations if the modification is approved. I've looked at codex and I've discovered there is also the update_user_meta()
function, it's not clear for me at the moment what can be the best choice to achive my scope. This is the code I have at the moment
$user_id = $request->get_param('user_id');
//TOFIX: mappatura meta input utente
$customer = wp_update_user(
$user_id,
array(
'user_email' => $request->get_param('email'),
'first_name' => $request->get_param('nome'),
'last_name' => $request->get_param('cognome'),
'user_login' => $request['user_login'],
//'display_name' => $request['nome'] .' '. $request['cognome'],
'rich_editing' => false,
'show_admin_bar_front' => false,
'role' => 'customer',
'meta_input' => array(
'indirizzo' => $request['indirizzo'],
'comune' => $request['comune'],
'provincia' => $request['provincia'],
'cap' => $request['cap'],
'nazione' => $request['nazione'],
'telefono_fisso' => $request['telefono_fisso'],
'telefono_cellulare' => $request['telefono_cellulare'],
'cod_fiscale_piva' => $request['cod_fiscale_piva'],
'codSDI' => $request['codSDI'],
'pec' => $request['pec'],
'num_tessera' => $request['num_tessera'],
'stato_account' => 'pending',
)
)
);
what I want to do is to add new temporary usermeta for the fields that users can modify so for example I want to have this kind of code
$user_id = $request->get_param('user_id');
//TOFIX: mappatura meta input utente
$customer = wp_update_user(
$user_id,
array(
'user_email' => $request->get_param('email'),
'first_name' => $request->get_param('nome'),
'last_name' => $request->get_param('cognome'),
'user_login' => $request['user_login'],
//'display_name' => $request['nome'] .' '. $request['cognome'],
'rich_editing' => false,
'show_admin_bar_front' => false,
'role' => 'customer',
'meta_input' => array(
'new_telefono_fisso' => $request['telefono_fisso'],
'new_telefono_cellulare' => $request['telefono_cellulare']
)
)
);
Basically the idea is to add the fields with the new_
prefix, so I can load them using the rest api and give a feedback on my vue front-end when the change occur and need to be approved. Any suggestion on what function or action I can use?