Actions and filters
Every hook that Nahnu Login Shield offers to other code. Use actions to react to something that happened, and filters to change a value before the plugin uses it. For the functions, see Functions reference.
How to read the tables#
- Args are the arguments your callback receives, in order. For a filter, return the first argument (changed or not). For a filter with more than one argument, pass the argument count as the fourth parameter of
add_filter(). - Hook names are stable parts of the API. Anything not listed here is internal and may change.
add_filter( 'nahnls_check_submission_enabled', function ( bool $enabled, array $context ): bool {
// two arguments, so the 4th parameter of add_filter() is 2
return $enabled;
}, 10, 2 ); Form checks#
These hooks run inside nahnls_check_submission(), so they fire for forms you protect yourself with the API. They do not fire for the built-in integrations (WooCommerce, comments, Bricks, SureForms) or the login page.
Actions
| Hook | Args | When |
|---|---|---|
nahnls_before_custom_check | array $context | Before the JavaScript marker and CAPTCHA are checked |
nahnls_after_custom_check | true|WP_Error $result, array $context | After the check, whether it passed or failed |
nahnls_custom_check_blocked | WP_Error $error, array $context | Only when a submission is blocked |
nahnls_custom_check_passed | array $context | Only when a submission passes |
The $context array is the same for all four:
[
'form_id' => 'my_form', // the $form_id you passed
'post_url' => '/my-page/', // current request URI
'provider' => 'oopspam', // active CAPTCHA provider slug
] Filters
| Hook | Args | Purpose |
|---|---|---|
nahnls_check_submission_enabled | bool $enabled, array $context | Return false to skip the check for a particular form |
nahnls_form_nonce_life | int $seconds | How long the hidden form nonce stays valid. Default: one day |
When you skip a check with nahnls_check_submission_enabled, nahnls_check_submission() returns true straight away, and the other form-check actions do not fire.
Example: skip the check for editors
add_filter( 'nahnls_check_submission_enabled', function ( bool $enabled, array $context ): bool {
if ( current_user_can( 'edit_posts' ) ) {
return false;
}
return $enabled;
}, 10, 2 ); Example: log blocked submissions
add_action( 'nahnls_custom_check_blocked', function ( WP_Error $error, array $context ) {
nahnls_log_event( 'captcha_fail', $context['form_id'] . ' -- ' . $error->get_error_code() );
}, 10, 2 ); Example: lengthen the nonce for cached pages
add_filter( 'nahnls_form_nonce_life', fn() => 2 * DAY_IN_SECONDS ); The CAPTCHA widget#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_widget_html_args | filter | array $args | Change the arguments before the widget HTML is built |
nahnls_widget_html_output | filter | string $html, array $args | Change the final widget HTML |
nahnls_captcha_provider_src | filter | string $src, string $provider | Change the provider script URL that widget.js loads for widgets built by JavaScript (ajax context) |
Example: add a wrapper around the widget
add_filter( 'nahnls_widget_html_output', function ( string $html, array $args ): string {
return '<div class="my-captcha-row">' . $html . '</div>';
}, 10, 2 ); Passkeys and magic links#
Actions
| Hook | Args | When |
|---|---|---|
nahnls_passkey_registered | int $user_id, array $credential_public | A passkey was saved. $credential_public has id, name, aaguid, transports, created, last_used (never the key) |
nahnls_passkey_removed | int $user_id, string $credential_id | A passkey was deleted |
nahnls_passkey_login | WP_User $user, array $credential_public | After the login cookie is set and wp_login has fired, before the response is sent |
nahnls_passkey_login_failed | string $reason_code, ?int $user_id, string $ip | A passkey sign-in failed. Reasons include unknown_credential, user_handle_mismatch, role_not_allowed, ip_mismatch, or the verifier’s own code (bad signature, counter, origin) |
nahnls_magic_link_requested | WP_User $user, string $ip | A link was queued or sent. The token is never passed |
nahnls_magic_link_login | WP_User $user, string $ip | A link was used and the cookie set, before wp_login and the redirect |
nahnls_magic_link_failed | string $reason_code, string $ip | A link request or use failed. Reasons: expired, invalid, disabled, rate_limited, opted_out |
Filters
| Hook | Args | Purpose |
|---|---|---|
nahnls_passkey_user_allowed | bool $allowed, WP_User $user | Allow or deny passkeys for a user (registration and sign-in) |
nahnls_magic_link_user_allowed | bool $allowed, WP_User $user | Allow or deny magic links for a user (after the role and opt-out checks) |
nahnls_passkey_login_redirect | string $url, WP_User $user | Where to send the user after a passkey sign-in (validated with wp_validate_redirect) |
nahnls_magic_link_redirect | string $url, WP_User $user | The same, for magic-link sign-ins |
nahnls_passkey_remember | bool $remember, WP_User $user | Force or forbid a persistent session |
nahnls_magic_link_ttl | int $seconds, WP_User $user | How long a link is valid (minimum 60 seconds) |
nahnls_magic_link_url | string $url, WP_User $user | The link placed in the email. The nahnls_mt and _wpnonce query arguments must stay |
nahnls_magic_link_email | array $email, WP_User $user, string $url | [ 'to', 'subject', 'message', 'headers' ] just before wp_mail() |
nahnls_magic_link_rate_limits | array $limits | [ 'per_ip' => 3, 'per_account' => 3, 'window' => 900 ] |
nahnls_login_button_html | string $html, string $kind | The passkey or magic-link markup printed into login forms. $kind is passkey or magic. Return '' to hide it |
nahnls_passkey_rp_id | string $rp_id | The WebAuthn relying-party ID (a bare host name). Changing it makes existing passkeys stop working |
nahnls_passkey_origin | string $origin | The origin that assertions must carry, for example when the login page is on another subdomain |
nahnls_passkey_creation_options | array $options, WP_User $user | Registration options before they are sent. Don’t change challenge, rp.id or user.id |
nahnls_passkey_request_options | array $options | Sign-in options before they are sent. Don’t change challenge or rpId |
Example: only allow passkeys for customers who are members
add_filter( 'nahnls_passkey_user_allowed', function ( bool $allowed, WP_User $user ): bool {
return $allowed && user_can( $user, 'read_private_posts' );
}, 10, 2 ); Example: shorter magic-link lifetime for administrators
add_filter( 'nahnls_magic_link_ttl', function ( int $seconds, WP_User $user ): int {
return user_can( $user, 'manage_options' ) ? 5 * MINUTE_IN_SECONDS : $seconds;
}, 10, 2 ); Example: send an event to your analytics
add_action( 'nahnls_passkey_login', function ( WP_User $user, array $credential ) {
do_action( 'my_analytics_event', 'login', [ 'method' => 'passkey', 'user' => $user->ID ] );
}, 10, 2 ); Two-factor authentication#
| Hook | Type | Args | When or purpose |
|---|---|---|---|
nahnls_2fa_verified | action | WP_User $user, string $method | The second factor passed. $method is totp, email, passkey or backup_code |
REST API#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_rest_allowed_origins | filter | array $hosts | Browser origins that may call the public nahnls/v1 routes. Defaults to your own site’s hosts. Needed for headless front ends on another host |
add_filter( 'nahnls_rest_allowed_origins', fn( array $hosts ) => [ ...$hosts, 'app.example.com' ] ); Emails#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_email_args | filter | array $args, string $type | Change the arguments of the branded 2FA, magic-link and signup emails before they are built. $type is 2fa, magic or signup. Plain text only |
nahnls_email_html | filter | string $html, string $type | Change the final HTML document |
nahnls_magic_link_email | filter | array $email, WP_User $user, string $url | See the passkeys and magic links table above |
add_filter( 'nahnls_email_args', function ( array $args, string $type ): array {
$args['intro'] .= "\n\nNeed help? support@example.com";
return $args;
}, 10, 2 ); Front-end styling#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_front_css_enabled | filter | bool $enabled, string $handle | Return false to stop the plugin from loading the stylesheet nahnls-account-panel or nahnls-2fa-front. Markup and class names stay the same |
nahnls_frontend_locale | filter | string $locale | Change the language used for the plugin’s front-end text. Gets the WPML or Polylang locale, or '' to use the site’s locale |
add_filter( 'nahnls_front_css_enabled', function ( $enabled, $handle ) {
return in_array( $handle, [ 'nahnls-account-panel', 'nahnls-2fa-front' ], true ) ? false : $enabled;
}, 10, 2 ); See Front-end theming.
Signup verification#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_signup_verify_skip | filter | bool $skip, int $user_id | Return true to skip email verification for a new account, for example when your code creates users from an address you already trust |
add_filter( 'nahnls_signup_verify_skip', function ( bool $skip, int $user_id ): bool {
return $skip || user_can( $user_id, 'manage_options' );
}, 10, 2 ); Verification tokens#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_enforce_ip_binding | filter | bool $enforce | Return false to stop checking that a verification token is used from the same network it was issued to. Only turn this off if visitors’ networks change between the page load and the submit (some mobile and proxy setups) |
SureForms#
| Hook | Type | Args | Purpose |
|---|---|---|---|
nahnls_sureforms_form_enabled | filter | bool $enabled, int $form_id | This filter only runs when the Integrations tab is set to protect selected forms. $enabled is true when the form is ticked. Return false to leave a ticked form unprotected, true to protect a form that is not ticked. With “all forms” chosen, every form is protected and the filter is not called |
add_filter( 'nahnls_sureforms_form_enabled', function ( bool $enabled, int $form_id ): bool {
return 42 === $form_id ? false : $enabled;
}, 10, 2 ); Lockouts#
| Hook | Type | Args | When |
|---|---|---|---|
nahnls_lockout_removed | action | string $ip | A lockout was removed. $ip is the unlocked address, or * when all lockouts were cleared |
What is not here#
There is no hook for a lockout starting, an IP being blocked, or a login being counted as a failure. A lockout being removed does have a hook: nahnls_lockout_removed. To react to those, use WordPress’s own wp_login_failed and wp_login actions, or read the event log. If you need a hook for something else, ask for it through the Support page. See Protect any other form.
Was this helpful?
Thanks for your feedback!
✓ Feedback received. Thank you!