WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Upgrader::fs_connect() public WP 2.8.0

Connect to the filesystem.

Это метод класса: WP_Upgrader{}

Хуков нет.

Возвращает

true/false/WP_Error. True if able to connect, false or a WP_Error otherwise.

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

$WP_Upgrader = new WP_Upgrader();
$WP_Upgrader->fs_connect( $directories, $allow_relaxed_file_ownership );
$directories(строка[])
Array of directories. If any of these do not exist, a WP_Error object will be returned.
По умолчанию: empty array
$allow_relaxed_file_ownership(true/false)
Whether to allow relaxed file ownership.
По умолчанию: false

Заметки

  • Global. WP_Filesystem_Base. $wp_filesystem WordPress filesystem subclass.

Список изменений

С версии 2.8.0 Введена.

Код WP_Upgrader::fs_connect() WP 5.5.1

wp-admin/includes/class-wp-upgrader.php
<?php
public function fs_connect( $directories = array(), $allow_relaxed_file_ownership = false ) {
	global $wp_filesystem;

	$credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership );
	if ( false === $credentials ) {
		return false;
	}

	if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) {
		$error = true;
		if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
			$error = $wp_filesystem->errors;
		}
		// Failed to connect. Error and request again.
		$this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership );
		return false;
	}

	if ( ! is_object( $wp_filesystem ) ) {
		return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] );
	}

	if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
		return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors );
	}

	foreach ( (array) $directories as $dir ) {
		switch ( $dir ) {
			case ABSPATH:
				if ( ! $wp_filesystem->abspath() ) {
					return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] );
				}
				break;
			case WP_CONTENT_DIR:
				if ( ! $wp_filesystem->wp_content_dir() ) {
					return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
				}
				break;
			case WP_PLUGIN_DIR:
				if ( ! $wp_filesystem->wp_plugins_dir() ) {
					return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] );
				}
				break;
			case get_theme_root():
				if ( ! $wp_filesystem->wp_themes_dir() ) {
					return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] );
				}
				break;
			default:
				if ( ! $wp_filesystem->find_folder( $dir ) ) {
					return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );
				}
				break;
		}
	}
	return true;
}