WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 5 months ago

#48689 new defect (bug)

PHP warnings after updating to WP 5.3: ftp_nlist() and ftp_pwd() expect missing parameters

Reported by: Hinjiriyo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.3
Component: Filesystem API Keywords: needs-patch
Focuses: Cc:

Description

I updated several websites to WP 5.3 without any problems. But on one wesite I got these PHP warnings both in the backend and in the website:

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 402
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_nlist() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 402
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 681
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226
Warning: ftp_pwd() expects parameter 1 to be resource, null given in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 226

Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/class-wp-filesystem-ftpext.php:402) in /wp-includes/functions.php on line 5946
Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/class-wp-filesystem-ftpext.php:402) in /wp-admin/includes/misc.php on line 1252
Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/class-wp-filesystem-ftpext.php:402) in /wp-admin/admin-header.php on line 9

I suppressed the ouput by "muting" the function calls with '@' in the file 'class-wp-filesystem-ftpext.php', i.e. changed ftp_nlist() to @ftp_nlist() etc..

I will be glad if any reason can be found and fixed until the next WP upgrade.

Change History (13)

#1 follow-up: @SergeyBiryukov
8 months ago

Hi there, thanks for the report!

Related: [45611/trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php], which removed error suppression for ftp_nlist() and ftp_pwd() here. It's likely that the issue comes from somewhere else, but is now more visible.

I could not reproduce it on a clean install though, some more details about the environment and the steps to reproduce would be helpful.

#2 @Hinjiriyo
8 months ago

Due to the many websites on many servers I maintain (~15), it is difficult to see anything special about the respective WP installation. The debugging is further complicated by the fact that nowhere in this website the class WP_Filesystem_FTPext seems to be called and used.

#3 @Hinjiriyo
8 months ago

Additional comment: if a plugin is upgraded this text appears on the "Update Plugins" page between "Enabling Maintenance mode..." and "Updating Plugin {x} ({m}/{n})":

Warning: ftp_rmdir(): /.maintenance: File or directory not found in /wp-admin/includes/class-wp-filesystem-ftpext.php on line 381

#4 @Hinjiriyo
7 months ago

  • Severity changed from critical to minor

I could detect the plugin which was the reason of this error. So I would close this ticket. But I think "muting" more PHP file function calls with '@' in the file 'class-wp-filesystem-ftpext.php' makes still sense, since many other function calls in this file are set as muted.

#5 follow-up: @SirLouen
6 months ago

I've found who makes this happen: WPML Multilingual CMS in combination with RankMath.

Last edited 6 months ago by SirLouen (previous) (diff)

#6 in reply to: ↑ 5 @Hinjiriyo
6 months ago

Replying to SirLouen:

I've found who makes this happen: WPML Multilingual CMS in combination with RankMath.

In the case of my website it was the plugin "Amazon Associates Link Builder". Since I deactivated it, there are no error messages. Was it a combination with another plugin? I don't know and didn't research that.

#7 @SirLouen
6 months ago

I have inyected a little bit of extra verbosity through some php error logging function to discover that Rankmath was trying to access to certain files (.htaccess and robots.txt) without success. I'm not sure why WPML (also happened by activating AMP for WP plugin in combination with Rankmath) was hindering Rankmath from this access...

The function that was being hindered is exists from WP Filesystem.
So probably any plugin in combination with WPML or AMP for WP may have this issue?
https://developer.wordpress.org/reference/classes/wp_filesystem_base/exists/
Not 100% sure.

This is the rankmath snippet which was making this misbehaviour.

<?php
public static function get_htaccess_data() {
                $wp_filesystem = WordPress::get_filesystem();
                $htaccess_file = get_home_path() . '.htaccess';

                return ! $wp_filesystem->exists( $htaccess_file ) ? false : [
                        'content'  => $wp_filesystem->get_contents( $htaccess_file ),
                        'writable' => $wp_filesystem->is_writable( $htaccess_file ),
                ];
        }

I'm not a code maintainer of Rankmath. In fact I have uninstalled from a production site, and left it in a staging server. But just wanted to inform about this because it could be useful for WP maintainers (I'm not sure).

Last edited 6 months ago by SirLouen (previous) (diff)

#8 @erikgeurtsplatformiqcom
6 months ago

This changeset https://core.trac.wordpress.org/changeset/45611/trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php (for example in line 226) unearths these PHP warnings by removing the @ symbol. It means the warning is no longer suppressed, but it's been an issue before this change.

In my case, it was also the addition of a plugin, but not the same as the previous comments, that brought out the warnings. The cause is not in these plugins directly, but in the fact that certain plugins in certain environments make an attempt to use the WP filesystem in a way that apparently is not expected.

The actual issue in https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php?rev=45611 since that change in July 2019 is that $this->link doesn't get a value assigned first, so any attempt to use the variable in this code throws the warning.

It seems that the if statement in https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php?rev=45611#L86 is where things go wrong.

In my case, the problem may come from the fact that I'm used to defining the FTP hostname, user and password in the wp-config.php, yet doing this incorrectly or with something missing. So in fact this may be a documentation issue (i.e. not having followed the documentation to the letter).

Where can the documentation for defining the FTP credentials in the wp-config.php be found?

#9 @aiko2011
6 months ago

Проблемный плагин у меня Pirateforms, последнее обновление WP его не поддерживает ;)

Last edited 6 months ago by aiko2011 (previous) (diff)

#10 in reply to: ↑ 1 @aiko2011
6 months ago

Replying to SergeyBiryukov:

Hi there, thanks for the report!

Related: [45611/trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php], which removed error suppression for ftp_nlist() and ftp_pwd() here. It's likely that the issue comes from somewhere else, but is now more visible.

I could not reproduce it on a clean install though, some more details about the environment and the steps to reproduce would be helpful.

Привет!
Были такие же проблемы.
Проблемный плагин у меня Pirateforms, последнее обновление WP его не поддерживает ;)

#11 follow-up: @orenwolf
5 months ago

It appears that this problem occurs whenever a plugin tries to access a file, but doesn't have write access, and tries instead to use FTP to access it.

#12 in reply to: ↑ 11 @aiko2011
5 months ago

Replying to orenwolf:

It appears that this problem occurs whenever a plugin tries to access a file, but doesn't have write access, and tries instead to use FTP to access it.

https://ru.wordpress.org/support/topic/pirate-forms/

#13 @BearlyDoug
5 months ago

I also was receiving this... I thought it was tied to the WP Astra theme (https://wpastra.com/), since I'm not getting it on sites not running the WP Astra Theme and WP Astra Pro plugin.

The first result I found for this is located HERE

I added

if (!defined('FS_METHOD')) define('FS_METHOD', 'direct');

to my wp-config.php file, and now the error messages actually have stopped.

This issue didn't show up until WordPress 5.3 was released, and is KILLING my Apache log files.

Note: See TracTickets for help on using tickets.