Recommended method to add and store custom field that would better integrate with Messages

Dear HivePress Support,

I am reaching out because I have added a new field (phone number) to the message submission form using the following code:

add_filter( 'hivepress/v1/models/message', 'custom_add_message_fields', 1000 );
add_filter( 'hivepress/v1/forms/message_send', 'custom_add_message_fields', 1000);

function custom_add_message_fields($form){
    $form['fields']['custom_text_field'] = [
        'label'     => 'Custom field',
        'type'      => 'text',
        '_external' => true,
        '_order'    => 10,
    ];

    return $form;
}
add_filter(
    'hivepress/v1/models/message/attributes',
    function($attributes){
        $attributes['custom_text_field'] = [
            'editable' => true,
            'edit_field' => [
                'label'     => 'Custom field',
                'type'      => 'text',
                '_order'    => 10,
            ]
        ];
        
        return $attributes;
    },
    1000
);

Everything seems to be working correctly, but I am unsure where the value entered in this new field is actually stored. Specifically, I would like to know:

  1. In which database table/column is the phone number stored (or the value entered in the custom_text_field), and how can I view or manage it within HivePress?

  2. If there is a more efficient or recommended method to add and store custom fields, such as a phone number, that would better integrate with HivePress’s message structure.

Thank you in advance for your support. I look forward to your response.

Best regards,

Alessio

Hi,

Yes, this is the correct way to add a new field and store it for messages. The second snippet for hivepress/v1/models/message/attributes is not needed, though. This new field is stored in wp_commentmeta database table (because message is a hidden comment type), with “hp_custom_text_field” meta key.

Another approach is adding a user attribute Phone and make it required, then it will be mandatory on registration. Since messages require registration anyway, you can collect the phone number once and then use it (for example) in the New Message email using %sender.phone% token.

Hope this helps

Hello, I have modified the snippet to look like this.

add_filter( ‘hivepress/v1/models/message’, ‘custom_add_message_fields’, 1000 );
add_filter( ‘hivepress/v1/forms/message_send’, ‘custom_add_message_fields’, 1000);

function custom_add_message_fields($form){
	$form[‘fields’][‘custom_tel_field’] = [
		‘label’ => ‘custom field’,
		‘type’ => ‘text’,
		‘_external’ => true,
		‘_order’ => 10,
	];

	return $form;
}

As we understand it, the value to be entered will then be saved within the dedicated database. Using wordpress and siteground, the database can be accessed from phpmyadmin. I cannot find the table mentioned and the metakey. Could you please provide support regarding the navigation and display of the table?

Please check if there’s a table with “commentmeta” in its name. This is the default WordPress database table so it’s there for sure, but the default prefix “wp_” can differ. If you want to display the phone number somewhere in the message layout I can provide general guidance on how to do this, let me know.

Grazie mille