Docs

Actions and filters

6 min readUpdated November 19, 2026

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

HookArgsWhen
nahnls_before_custom_checkarray $contextBefore the JavaScript marker and CAPTCHA are checked
nahnls_after_custom_checktrue|WP_Error $result, array $contextAfter the check, whether it passed or failed
nahnls_custom_check_blockedWP_Error $error, array $contextOnly when a submission is blocked
nahnls_custom_check_passedarray $contextOnly 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

HookArgsPurpose
nahnls_check_submission_enabledbool $enabled, array $contextReturn false to skip the check for a particular form
nahnls_form_nonce_lifeint $secondsHow 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#

HookTypeArgsPurpose
nahnls_widget_html_argsfilterarray $argsChange the arguments before the widget HTML is built
nahnls_widget_html_outputfilterstring $html, array $argsChange the final widget HTML
nahnls_captcha_provider_srcfilterstring $src, string $providerChange 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 );

Actions

HookArgsWhen
nahnls_passkey_registeredint $user_id, array $credential_publicA passkey was saved. $credential_public has id, name, aaguid, transports, created, last_used (never the key)
nahnls_passkey_removedint $user_id, string $credential_idA passkey was deleted
nahnls_passkey_loginWP_User $user, array $credential_publicAfter the login cookie is set and wp_login has fired, before the response is sent
nahnls_passkey_login_failedstring $reason_code, ?int $user_id, string $ipA 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_requestedWP_User $user, string $ipA link was queued or sent. The token is never passed
nahnls_magic_link_loginWP_User $user, string $ipA link was used and the cookie set, before wp_login and the redirect
nahnls_magic_link_failedstring $reason_code, string $ipA link request or use failed. Reasons: expired, invalid, disabled, rate_limited, opted_out

Filters

HookArgsPurpose
nahnls_passkey_user_allowedbool $allowed, WP_User $userAllow or deny passkeys for a user (registration and sign-in)
nahnls_magic_link_user_allowedbool $allowed, WP_User $userAllow or deny magic links for a user (after the role and opt-out checks)
nahnls_passkey_login_redirectstring $url, WP_User $userWhere to send the user after a passkey sign-in (validated with wp_validate_redirect)
nahnls_magic_link_redirectstring $url, WP_User $userThe same, for magic-link sign-ins
nahnls_passkey_rememberbool $remember, WP_User $userForce or forbid a persistent session
nahnls_magic_link_ttlint $seconds, WP_User $userHow long a link is valid (minimum 60 seconds)
nahnls_magic_link_urlstring $url, WP_User $userThe link placed in the email. The nahnls_mt and _wpnonce query arguments must stay
nahnls_magic_link_emailarray $email, WP_User $user, string $url[ 'to', 'subject', 'message', 'headers' ] just before wp_mail()
nahnls_magic_link_rate_limitsarray $limits[ 'per_ip' => 3, 'per_account' => 3, 'window' => 900 ]
nahnls_login_button_htmlstring $html, string $kindThe passkey or magic-link markup printed into login forms. $kind is passkey or magic. Return '' to hide it
nahnls_passkey_rp_idstring $rp_idThe WebAuthn relying-party ID (a bare host name). Changing it makes existing passkeys stop working
nahnls_passkey_originstring $originThe origin that assertions must carry, for example when the login page is on another subdomain
nahnls_passkey_creation_optionsarray $options, WP_User $userRegistration options before they are sent. Don’t change challenge, rp.id or user.id
nahnls_passkey_request_optionsarray $optionsSign-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#

HookTypeArgsWhen or purpose
nahnls_2fa_verifiedactionWP_User $user, string $methodThe second factor passed. $method is totp, email, passkey or backup_code

REST API#

HookTypeArgsPurpose
nahnls_rest_allowed_originsfilterarray $hostsBrowser 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#

HookTypeArgsPurpose
nahnls_email_argsfilterarray $args, string $typeChange 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_htmlfilterstring $html, string $typeChange the final HTML document
nahnls_magic_link_emailfilterarray $email, WP_User $user, string $urlSee 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#

HookTypeArgsPurpose
nahnls_front_css_enabledfilterbool $enabled, string $handleReturn 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_localefilterstring $localeChange 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#

HookTypeArgsPurpose
nahnls_signup_verify_skipfilterbool $skip, int $user_idReturn 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#

HookTypeArgsPurpose
nahnls_enforce_ip_bindingfilterbool $enforceReturn 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#

HookTypeArgsPurpose
nahnls_sureforms_form_enabledfilterbool $enabled, int $form_idThis 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#

HookTypeArgsWhen
nahnls_lockout_removedactionstring $ipA 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?

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only