Automattic\WooCommerce\Internal\Utilities

FilesystemUtil::is_usable_ftp_filesystemprivate staticWC 1.0

Check if an FTP-based filesystem instance is usable.

Checks both the connection resource and the error state. The connection resource can be null if PHP's max execution time interrupted ftp_connect() before it completed, leaving the instance in a broken state without errors.

Method of the class: FilesystemUtil{}

No Hooks.

Returns

true|false. False if FTP-based and unusable, true otherwise.

Usage

$result = FilesystemUtil::is_usable_ftp_filesystem( $wp_filesystem ): bool;
$wp_filesystem(WP_Filesystem_Base) (required)
The filesystem instance to check.

FilesystemUtil::is_usable_ftp_filesystem() code WC 10.7.0

private static function is_usable_ftp_filesystem( WP_Filesystem_Base $wp_filesystem ): bool {
	$has_broken_state = false;
	$has_errors       = false;

	if ( 'ftpext' === $wp_filesystem->method ) {
		$has_broken_state = empty( $wp_filesystem->link );
		$has_errors       = is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors();
	}

	if ( 'ftpsockets' === $wp_filesystem->method ) {
		$has_broken_state = empty( $wp_filesystem->ftp );
		$has_errors       = is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors();
	}

	return ! $has_broken_state && ! $has_errors;
}