I created a new entry in the registration form with this code
add_filter(
'hivepress/v1/forms/user_register',
function ( $form ) {
$form['fields'] = array_merge(
$form['fields'],
[
'phone_number' => [
'type' => 'text',
'placeholder' => 'Digite seu Telefone',
'label' => 'Número de telefone',
'required' => true,
'_order' => 2,
],
],
);
return $form;
},
100
);
add_action(
'hivepress/v1/models/user/register',
function( $user_id, $values ) {
if ( isset( $values['phone_number'] ) ) {
update_user_meta( $user_id, 'phone_number', $values['phone_number'] );
}
},
10,
2
);
Now I need to display the phone field in the user configuration panel, how do I do this?
andrii
March 6, 2024, 2:16pm
4
Hi,
We recommend using these hooks:
hivepress/v1/models/user
hivepress/v1/forms/user_update
If you add new fields to the model and to the form, you will be able to manage and save them automatically.
I hope this is helpful to you.
1 Like
add_filter(
'hivepress/v1/forms/user_update',
function ( $form ) {
$form['fields'] = array_merge(
$form['fields'],
[
'phone_number' => [
'type' => 'text',
'placeholder' => 'Digite seu Telefone',
],
],
);
return $form;
},
100
);
add_filter(
'hivepress/v1/models/user',
function( $model ) {
$model['fields']['phone_number'];
return $model;
},
1000
);
It is true? If not, would there be an example of applying the code?
andrii
March 7, 2024, 2:08pm
8
Hi,
Yes, snippets are almost correct, but you need to declare the field additionally in the first hook using this parameter: ‘_external’ => true
. Also, it is better to use the phone field type.
1 Like
system
Closed
April 6, 2024, 2:08pm
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.