How can we help?

Search for answers or browse our knowledge base.

Table of Contents

List of hooks in WP 2FA

WP 2FA has a number of settings that allow website administrators to configure the plugin as they wish. However, in some cases, administrators and developers might want to change some of the plugin’s behavior that cannot be changed via a setting. While this does not happen often, due to the nature of how WordPress websites are used, there might be edge cases in which this is needed.

In such cases one can use hooks in the WP 2FA plugin to hook into the plugin’s functionality and modify its behavior. Below is a list of hooks and parameters found in the WP 2FA plugin.

Note: if you would like us to add a hook send us an email at support@melapress.com with all the details and requirements.

Important: use this hook only if the user(s) do not have access to the WordPress dashboard. If the users have access to the WordPress dashboard use the hook wp_2fa_setup_page_link.

Function

Use this hook to specify the page where a user should be redirected to when required to setup 2FA based on your own logic, for example if a user belongs to a certain group of roles etc. By default the plugin does a great job of handling where to take users when setting up 2FA, however, this might be required in certain custom setups.

Parameters

  • $url – the URL where the user should be redirected to
  • $user – the user object of the user that needs to be redirected

Example code

add_filter( 'wp_2fa_custom_setup_page_link', 'my_custom_setup_page_link', 10, 2 );

function my_custom_setup_page_link( $url, $user ) {
    if ( in_array( 'author', (array) $user->roles ) ) {
         // The user has the "author" role.
        $url = ‘my-custom-slug’;
    }
    return $url;
}

wp_2fa_mail_default_settings

Function

The filter provides just a single argument, $default_settings, which contains the default list of strings used within the plugin which can be read, altered, and returned back to our plugin prior to display.

Parameters

  • $default_settings – Array of default strings used throughout emails.

Example code

add_filter( 'wp_2fa_mail_default_settings', 'my_custom_email_strings' );

function my_custom_email_strings( $default_settings ) {
    $default_settings['login_code_setup_email_body'] = '<p>Hello world</p>';
    return $default_settings;
}

wp_2fa_replacement_email_strings

Function

In the plugin’s emails you can use tags such as {user_login_name} and {grace_period} which are replaced with applicable strings when an email is generated and sent to a user. This filter allows you to set your own replacements or add your own tags.

Parameters

  •  $replacements – Array of default strings used throughout emails.

Example code

add_filter( 'wp_2fa_mail_default_settings', 'my_custom_replacement_reconfigure_strings' );

function my_custom_replacement_reconfigure_strings( $replacements ) {
    $replacements['grace_period'] = '<p>Hello world</p>';
    return $replacements;
}

wp_2fa_replacement_reconfigure_strings

Function

In the plugin’s reconfiguration email’s you can use tags such as {reconfigure_or_configure} and {reconfigure_or_configure_capitalized} which are replaced with applicable strings when an email is generated and sent to a user. This filter allows you to set your own replacements or add your own tags.

Parameters

  •  $replacements – Array of default strings used throughout emails.

Example code

add_filter( 'wp_2fa_mail_default_settings', 'my_custom_replacement_reconfigure_strings' );

function my_custom_replacement_reconfigure_strings( $replacements ) {
    $replacements['reconfigure_or_configure'] = '<p>Hello world</p>';
    return $replacements;
}

Important: use this hook only if the user has access to the WordPress dashboard. If you are using a custom front-end 2FA page use the hook wp_2fa_custom_setup_page_link.

Function

Use this hook to specify the page where a user should be redirected to when required to setup 2FA based on your own logic, for example if a user belongs to a certain group of roles etc. By default the plugin does a great job of handling where to take users when setting up 2FA, however, this might be required in certain custom setups.

Parameters

  • $url – the URL where the user should be redirected to

Example code

add_filter( 'wp_2fa_setup_page_link', 'my_custom_setup_page_link', 10, 1 );

function my_custom_setup_page_link( $url ) {
    $user = wp_get_current_user();
    if ( in_array( 'author', (array) $user->roles ) ) {
         // The user has the "author" role.
        $url = ‘my-custom-slug’;
    }
    return $url;
}

wp_2fa_user_is_unlocked

Function

This action is fired after a user has been unlocked. It provides the $user object which you can use to implement custom logic as you wish.

Parameters

  • $user – the user object of the user that needs to be redirected

Example code

add_action( 'wp_2fa_user_is_unlocked', 'my_custom_user_is_unlocked' );

function my_custom_user_is_unlocked( $user ) {
    $updated = update_user_meta( $user->ID, 'my-custom-key', ‘my-custom-value’ );
}

The survey results are in: Find out what your WordPress security gameplan might be missing

Uploading Melapress Login Security as a zip file in WordPress
Melapress Login Security in the WordPress plugin repository
Close

Installing Melapress Login Security Free

Congratulations on taking control of your WordPress website's security by implementing robust login and password policies with Melapress Login Security. You can change your login page URL, limit failed login attempts, and reset passwords.

 

Below are two ways to install Melapress Login Security on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for Melapress Login Security.

Download the Melapress Login Security plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading CAPTCHA 4WP as a zip file in WordPress
CAPTCHA 4WP in the WordPress plugin repository
Close

Installing CAPTCHA 4WP Free

Well done you. You're one step closer to safeguarding your WordPress website from spam and automated attacks with CAPTCHA 4WP. You'll be able to effortlessly integrate CAPTCHA into your forms and enjoy a website with enhanced security.

 

Below are two ways to install CAPTCHA 4WP on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for CAPTCHA 4WP.

Download the CAPTCHA 4WP plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP Activity Log as a zip file in WordPress
WP Activity Log in the WordPress plugin repository
Close

Installing WP Activity Log Free on your website

You deserve a pat on the back for choosing to record user actions and changes on your website. That is the first step towards better user accountability, easier troubleshooting of website security, and many other benefits of issues.

 

Below are the two ways to install WP Activity Log on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for WP Activity Log.

Download the WP Activity Log plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP 2FA as a zip file in WordPress
WP 2FA in the WordPress plugin repository
Close

Installing WP 2FA Free

Congratulations on taking the first step towards enhancing your WordPress site's security with WP 2FA Free! You're now on your way to protecting your valuable data and ensuring peace of mind. No coding or technical knowledge is required.

 

Below are two ways to install WP 2FA on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for WP 2FA.

Download the WP 2FA plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2