Skip to content

How to Add 2FA to a Custom Login Form

The plugin adds its step to WordPress’s own password check, which every proper login form goes through. Most custom forms need nothing.

A form that posts to WordPress and reloads gets the code screen after a correct password, on the My Account page for WooCommerce forms and on wp-login.php for the rest.

A popup cannot show a second screen, so it shows the message the plugin returns: “This account uses two-factor authentication. Continue to enter your code.” The link opens the code screen for that sign in.

Forms that post the code with the password

Section titled “Forms that post the code with the password”

A one-step form can collect the code itself and send it in a field named _ddwcga_authentication_code, together with the username and password.

<input type="text" name="_ddwcga_authentication_code" inputmode="numeric" autocomplete="one-time-code" />

A right code signs in at once. A wrong one is refused with “The two-factor authentication code is wrong.” and counts towards the lockout. On the demo, both cases behaved this way. Trusted devices skip the field.

  • ddwcga_activity fires after every two-factor event, with the event, user ID, method and where it happened.
  • ddwcga_trust_proxy_headers returns true behind a trusted proxy, so the log records the visitor’s address.
  • ddwcga_display_myaccounts_menu hides the My Account menu item.
  • ddwcga_modify_admin_menu_capability changes who sees the admin screens, manage_woocommerce by default.
  • ddwcga_configuration filters every setting.