Hi @andrewsupport,
thanks for your reply. The error is still present in the latest version of the plugin. You can easily reproduce the error by setting up WordPress and setting WordPress filesystem method. Please do not define any credentials for FTP (by default they should be empty). I am running WordPress in a multi-site environment, where none of the individual site owner has direct access to the WordPress filesystem by intention – all updates and plugins are managed by service provider instead. The default filesystem method for all site owner is defined as follows:
if (!defined('FS_METHOD'))
define( 'FS_METHOD', 'ftpext' );
The error occurs when the google-captcha plugin has been configured by one site owner to protect the wp-admin login prompt. In particular, it will fail to test for the existence of CSS files, because it will trigger WordPress filesystem access via FTP, which would ask for credentials. Therefore, people will be unable to access to login screen, instead they will see the WordPress error page: “There has been a critical error on this website…”.
The php error logged is as follows:
[11-Dec-2022 14:15:36 UTC] PHP Fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given in /usr/share/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php:4
20
Stack trace:
#0 /usr/share/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php(420): ftp_nlist()
#1 /var/lib/wordpress/wp-content/plugins/google-captcha/bws_menu/bws_functions.php(748): WP_Filesystem_FTPext->exists()
#2 /usr/share/wordpress/wp-includes/class-wp-hook.php(308): bws_admin_enqueue_scripts()
#3 /usr/share/wordpress/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#4 /usr/share/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /usr/share/wordpress/wp-admin/admin-header.php(118): do_action()
#6 /usr/share/wordpress/wp-admin/index.php(137): require_once('...')
#7 {main}
thrown in /usr/share/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420
As I do not expect the touch the WordPress filesystem access layer, I would recommend to replace the use of WordPress’ filesystem wp_filesystem
to php’s file_exists
, because the php code is running where the CSS file should be located as well; thus having direct filesystem access to it as well.
Hope the description helps to understand my proposed change.
Thanks!