PHP Compatibility Error with Two-Factor Plugin
Closed this issue · 4 comments
Describe the bug
Hi everyone,
I'm facing an issue with the Two-Factor plugin in WordPress. When trying to execute the code, I get the following error:
Uncaught Error: Call to undefined function str_contains() in /var/www/html/wp-content/plugins/two-factor/class-two-factor-core.php:727
This error occurs in the maybe_show_reset_password_notice function at line 727. The problem seems to be the use of the str_contains function, which is not available in PHP versions lower than 8, although the plugin claims to be compatible with these versions.
The problematic code is:
if ( ! $attempted_user && str_contains( $user_name, '@' ) ) {
$attempted_user = get_user_by( 'email', $user_name );
}
To resolve this issue, it would be necessary to replace str_contains with a function compatible with earlier versions.
I hope this helps! Let me know if you need anything else.
Steps to Reproduce
Trigger the Error: Perform an action that triggers the maybe_show_reset_password_notice function. This typically involves attempting to log in with a username that includes an '@' symbol.
2.
Observe the Error: You should see the following error message:
Uncaught Error: Call to undefined function str_contains() in /var/www/html/wp-content/plugins/two-factor/class-two-factor-core.php:727
Screenshots, screen recording, code snippet
No response
Environment information
No response
Please confirm that you have searched existing issues in this repository.
Yes
Please confirm that you have tested with all plugins deactivated except Two-Factor.
Yes
Thanks for reporting the issue @a-casado!
WordPress core has a polyfill for this method since version 5.9:
so it should work unless the code path is triggered before the compatibility layers is loaded.
Which version of WP core are you using?
Hi @kasparsd ,
I'm currently using WordPress version 5.2. Given that the str_contains polyfill is available from version 5.9, would it be advisable to update WordPress to at least version 5.9 to ensure it works correctly?
Thanks!
Since the plugin header mentions the correct version, I’m closing this.