Hook: admin_usergroup_save
avatar
Señor FAQ

¡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.


Hook: admin_usergroup_save

The admin_usergroup_save hook allows plugins to handle custom data processing after a user group is saved in the admin interface.

Usage


DynamicHooks::executeHook('admin_usergroup_save', false, $jkp["ugid"], $jkp);

// Example Implementation
DynamicHooks::addHook('admin_usergroup_save', function ($userGroupId, $data) use ($jakdb) {
    $pluginId = $jakdb->get('plugins', 'id', ['name' => 'Your_Plugin_Name']);

    $comment_access = isset($data["comment_access"]) && $data["comment_access"] == 1 ? 1 : 0;

    if (is_numeric($userGroupId)) {
        $existing = $jakdb->get('plugin_data', 'id', [
            'plugin_item_id' => $userGroupId,
            'plugin_id' => $pluginId,
            'meta_key' => 'comment_access',
        ]);

        if ($existing) {
            $jakdb->update('plugin_data', [
                'meta_value' => $comment_access,
            ], [
                'id' => $existing,
            ]);
        } else {
            $jakdb->insert('plugin_data', [
                'plugin_id' => $pluginId,
                'plugin_item_id' => $userGroupId,
                'meta_key' => 'comment_access',
                'meta_value' => $comment_access,
            ]);
        }
    }
}, 'your_plugin');
    

Best Practices

  • Ensure data integrity when saving custom fields to the database.
  • Use unique metadata keys to avoid overwriting existing data.
  • Test data handling logic to ensure proper updates and inserts.

Troubleshooting

  • Verify the hook is registered correctly under the intended namespace.
  • Check for missing or invalid metadata during data processing.
  • Inspect logs for errors during database updates or inserts.
Was this article helpful?
0 out of 0 found this helpful