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.

Метод класса: FilesystemUtil{}

Хуков нет.

Возвращает

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

Использование

$result = FilesystemUtil::is_usable_ftp_filesystem( $wp_filesystem ): bool;
$wp_filesystem(WP_Filesystem_Base) (обязательный)
The filesystem instance to check.

Код FilesystemUtil::is_usable_ftp_filesystem() WC 10.9.1

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;
}