Writing a Basic Plugin
April 12, 2019
Latest Security Audit
April 25, 2019

Plugin Hooks


When you create a plugin for UserSpice, you can use our plugin hooks to allow you to inject code on common pages without modifying the page itself. Basically when you do your install.php file for your plugin, put

$hooks['account.php']['bottom'] = 'hooks/accountbottom.php';
So list the page, the position and the link to the file that is the "include" on that page. Note that you can use the same include on multiple pages. There's nothing wrong with also doing…
$hooks['join.php']['bottom'] = 'hooks/accountbottom.php';
if your include code is the same. Be sure to test your hooks because you can seriously break projects. Plugin hooks are automatically uninstalled when a plugin is uninstalled.

If you want to know exactly where a plugin hook will be in the code, visit the page referenced and look for the includeHook function like includeHook($hooks,'post');

The new 'pre' hook is usually included right below the getMyHooks() function.


Page pre post body form bottom Description
account.php Body is below gravitar. Bottom is bottom right.
admin.php?view=general Do form and post in one div or use the built in settings table AJAX
admin_settings.php (v5.1.5) Pre is before the if statements. Bottom is before json encode. DO NOT echo text inside this hook.
admin.php?view=social(v4.4) Do form and post in one div or use the built in settings table AJAX
admin.php?view=user (v5.0.5+) Body is above the form.
admin.php?view=users (v5.0.5+) Pre is above the table. Body is the table header. Bottom is the table. Form is the new user modal.
join.php Form is inside /views/_join.php
login.php Post is just before validation passed so you can boot them.

As of version 5.1.4, we also have "event hooks".  These can be triggered when a certain event happens on your site.  They're included very similarly to other hooks with the exception that they don't use the php page name. Instead they all use the body position and the event hook name.
$hooks['loginFail']['body'] = 'hooks/accountbody.php';

Current event names are:

noAccess (Did not have permission to visit a page)
joinFail (For join success, use the standard join.php "post" position instead)