¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
on_user_save
The on_user_save
hook is triggered when user data is being saved.
It allows plugins to capture and store additional user-specific information dynamically.
DynamicHooks::executeHook('on_user_save', false, $page2, $jkp);
This hook is executed using the DynamicHooks::executeHook()
method with the following parameters:
$page2
- The ID of the user being saved.$jkp
- The data being submitted, typically from a form.
DynamicHooks::addHook('on_user_save', function ($userId, $data) use ($jakdb) {
if (isset($data['company_name'])) {
// Get the plugin ID for the "Marketplace" plugin
$pluginId = $jakdb->get('plugins', 'id', ['name' => 'Your_Plugin_Name']);
if ($pluginId) {
// Prepare the data
$metaValue = json_encode([
'company_name' => $data['company_name'] ?? '',
'address' => $data['address'] ?? '',
'country' => $data['country'] ?? '',
'tax_id' => $data['tax_id'] ?? '',
'additional_info' => $data['additional_info'] ?? ''
]);
// Check if the record already exists
$exists = $jakdb->has('plugin_data', [
'plugin_id' => $pluginId,
'plugin_item_id' => $userId,
'meta_key' => 'user_data'
]);
if ($exists) {
// Update existing record
$jakdb->update('plugin_data', [
'meta_value' => $metaValue
], [
'plugin_id' => $pluginId,
'plugin_item_id' => $userId,
'meta_key' => 'user_data'
]);
} else {
// Insert new record
$jakdb->insert('plugin_data', [
'plugin_id' => $pluginId,
'plugin_item_id' => $userId,
'meta_key' => 'user_data',
'meta_value' => $metaValue
]);
}
}
}
}, 'your_plugin');
company_name
) are present in the post data.