Skip to main content

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:

ParameterTypeDescription
$priorityintPriority 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:

ParameterTypeDescription
$documentsarrayArray 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:

ParameterTypeDescription
$membersarrayArray 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

HookPriorityPurpose
init8 (filterable)i18n, plugin init, sync key generation
wp_enqueue_scriptsdefaultEnqueue frontend JS and CSS
admin_enqueue_scriptsdefaultEnqueue admin JS and CSS
admin_menudefaultRegister Settings → Association App page
rest_api_initdefaultRegister custom REST routes
user_new_formdefaultAdd custom fields to the "Add New User" form
show_user_profiledefaultDisplay custom fields on user profile
edit_user_profiledefaultDisplay custom fields when editing another user's profile
personal_options_updatedefaultSave custom fields from own profile
edit_user_profile_updatedefaultSave custom fields from another user's profile
profile_updatedefaultSend email notifications on profile changes
user_registerdefaultHandle post-registration tasks (invitation email, role)
delete_userdefaultUnsubscribe device from Firebase FCM on account deletion

Filters

HookPurpose
mce_cssInject plugin styles into the TinyMCE visual editor
script_loader_tagAdd async/defer attributes to plugin scripts
rest_url_prefixReplace /wp-json with /api
rest_endpointsDisable default WordPress REST endpoints
rest_pre_dispatchPre-process JWT auth on every REST request
determine_current_userIdentify the current user from JWT token
jwt_auth_algorithmSet the JWT signing algorithm
jwt_auth_expireSet JWT token expiry duration
jwt_auth_token_before_signModify JWT payload before signing
jwt_auth_token_before_dispatchAttach refresh token to login response
allowed_block_types_allRestrict available Gutenberg blocks per custom post type
the_contentApply content filters when building sync response
get_the_excerptApply excerpt filters when building sync response
send_email_change_emailSuppress WordPress's default email-change notification
wp_authenticate_userBlock 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.