Developer Hooks & Filters
The plugin exposes action hooks and filters that allow you to extend or modify its behaviour without editing plugin files.
All custom hooks use the _2dc_assoc_app_ or _2dcassocapp_ prefix.
Action Hooks
_2dc_assoc_app_before_init
Fires before the plugin runs its initialisation routine. Use this to register anything that must exist before the plugin bootstraps its classes.
add_action('_2dc_assoc_app_before_init', function() {
// runs before plugin class loading
});
_2dc_assoc_app_init
Fires after Composer dependencies and all plugin classes have been loaded, but before custom post types, REST routes, and hooks are registered.
add_action('_2dc_assoc_app_init', function() {
// safe to interact with plugin classes here
});
_2dc_assoc_app_loaded
Fires after the plugin has fully bootstrapped — post types are registered, REST routes are registered, and all hooks are in place.
add_action('_2dc_assoc_app_loaded', function() {
// plugin is fully loaded
});
Filter Hooks
_2dc_assoc_app_init_priority
Controls the priority at which the plugin attaches its setup to the WordPress init action. Default is 8.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$priority | int | Priority passed to add_action('init', ...) |
Returns: int
// Load plugin setup later than default (e.g. after a theme's init)
add_filter('_2dc_assoc_app_init_priority', function(int $priority): int {
return 15;
});
_2dcassocapp_document_recently_viewed
Filters the list of recently viewed documents before it is returned to the mobile app.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$documents | array | Array of document post objects/arrays |
Returns: array
add_filter('_2dcassocapp_document_recently_viewed', function(array $documents): array {
// remove documents the current user should not see
return array_filter($documents, fn($doc) => !get_post_meta($doc['id'], '_restricted', true));
});
_2dcassocapp_user_members
Filters the member list before it is returned by the members endpoint or sync endpoint.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$members | array | Array of member data arrays |
Returns: array
add_filter('_2dcassocapp_user_members', function(array $members): array {
// exclude members with the is_exclude_listing flag
return array_filter($members, function($member) {
return empty(get_user_meta($member['id'], 'is_exclude_listing', true));
});
});
WordPress Hooks Used by the Plugin
The table below lists all WordPress core hooks the plugin hooks into. This is useful for understanding execution order and for diagnosing conflicts with other plugins or themes.
Actions
| Hook | Priority | Purpose |
|---|---|---|
init | 8 (filterable) | i18n, plugin init, sync key generation |
wp_enqueue_scripts | default | Enqueue frontend JS and CSS |
admin_enqueue_scripts | default | Enqueue admin JS and CSS |
admin_menu | default | Register Settings → Association App page |
rest_api_init | default | Register custom REST routes |
user_new_form | default | Add custom fields to the "Add New User" form |
show_user_profile | default | Display custom fields on user profile |
edit_user_profile | default | Display custom fields when editing another user's profile |
personal_options_update | default | Save custom fields from own profile |
edit_user_profile_update | default | Save custom fields from another user's profile |
profile_update | default | Send email notifications on profile changes |
user_register | default | Handle post-registration tasks (invitation email, role) |
delete_user | default | Unsubscribe device from Firebase FCM on account deletion |
Filters
| Hook | Purpose |
|---|---|
mce_css | Inject plugin styles into the TinyMCE visual editor |
script_loader_tag | Add async/defer attributes to plugin scripts |
rest_url_prefix | Replace /wp-json with /api |
rest_endpoints | Disable default WordPress REST endpoints |
rest_pre_dispatch | Pre-process JWT auth on every REST request |
determine_current_user | Identify the current user from JWT token |
jwt_auth_algorithm | Set the JWT signing algorithm |
jwt_auth_expire | Set JWT token expiry duration |
jwt_auth_token_before_sign | Modify JWT payload before signing |
jwt_auth_token_before_dispatch | Attach refresh token to login response |
allowed_block_types_all | Restrict available Gutenberg blocks per custom post type |
the_content | Apply content filters when building sync response |
get_the_excerpt | Apply excerpt filters when building sync response |
send_email_change_email | Suppress WordPress's default email-change notification |
wp_authenticate_user | Block login for users with pending-review role |
JWT Extension Filters
The plugin extends the JWT Authentication for WP REST API plugin using its own filter hooks. You can further customise JWT behaviour:
jwt_auth_expire
Control how long access tokens are valid. Default is DAY_IN_SECONDS (86400 seconds).
add_filter('jwt_auth_expire', function(int $expire): int {
return HOUR_IN_SECONDS * 2; // 2-hour tokens
});
jwt_auth_token_before_sign
Modify the JWT payload before it is signed. Useful for adding custom claims.
add_filter('jwt_auth_token_before_sign', function(array $token, \WP_User $user): array {
$token['data']['user']['membership_type'] = get_user_meta($user->ID, '_2dc_assoc_member_type', true);
return $token;
}, 10, 2);
jwt_auth_token_before_dispatch
Modify the full login response object (token + metadata) before it is sent to the client.
add_filter('jwt_auth_token_before_dispatch', function(array $data, \WP_User $user): array {
$data['organisation_name'] = get_option('association_name');
return $data;
}, 10, 2);
Example: Adding a Custom Member Field to the Sync Response
add_filter('_2dcassocapp_user_members', function(array $members): array {
return array_map(function($member) {
$member['membership_expiry'] = get_user_meta($member['id'], 'renewal_date', true);
return $member;
}, $members);
});
Place this code in your theme's functions.php or a site-specific plugin.