WP_Upgrader::fs_connect( string[] $directories = array(), bool $allow_relaxed_file_ownership = false ): bool|WP_Error
- Since
- 2.8.0
- Source
wp-admin/includes/class-wp-upgrader.php:236
Compatibility
- WordPress
- since 2.8.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$directoriesstring[]optional- Array of directories. If any of these do not exist, a WP_Error object will be returned.
Default empty array.Default:array() $allow_relaxed_file_ownershipbooloptional- Whether to allow relaxed file ownership.
Default false.Default:false
Return value
bool|WP_Error- True if able to connect, false or a WP_Error otherwise.
Performance profile
How much work a call to WP_Upgrader::fs_connect() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 15–73
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 160.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Upgrader::fs_connect()
Further down the call graph this can also reach option, cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Upgrader::fs_connect() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$credentials === false | 15 | ->request_filesystem_credentials() |
$credentials !== false && WP_Filesystem() && !is_object($wp_filesystem) | 32 | ->request_filesystem_credentials(), WP_Filesystem() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() | 34–35 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error() |
$credentials !== false && !WP_Filesystem() && !is_object($wp_filesystem) | 34 | ->request_filesystem_credentials(), WP_Filesystem(), ->request_filesystem_credentials() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() | 38–45 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors() |
$credentials !== false && !WP_Filesystem() && is_object($wp_filesystem) | 38–39 | ->request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), ->request_filesystem_credentials() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !$directories && $dir == false && !->abspath() | 48 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->abspath() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !$directories && $dir != false && $dir == false && !->wp_content_dir() | 51 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->wp_content_dir() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !$directories && $dir == false && !->abspath() | 52 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->abspath() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !$directories && $dir != false && $dir == false && !->wp_plugins_dir() | 54 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->wp_plugins_dir() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !$directories && $dir != false && $dir == false && !->wp_content_dir() | 55 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_content_dir() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !$directories && $dir != false && $dir == false && !->wp_themes_dir() | 58 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), get_theme_root(), ->wp_themes_dir() |
4 further outcomes, up to 73 instructions
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !$directories && $dir != false && $dir == false && !->wp_plugins_dir() | 58 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors(), ->wp_plugins_dir() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !$directories && $dir != false && $dir == false && !->wp_themes_dir() | 62 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors(), get_theme_root(), ->wp_themes_dir() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && !is_wp_error() && !$directories && $dir != false && !->find_folder() | 69 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), get_theme_root(), ->find_folder(), basename(), esc_html(), sprintf() |
$credentials !== false && WP_Filesystem() && is_object($wp_filesystem) && is_wp_error() && !->has_errors() && !$directories && $dir != false && !->find_folder() | 73 | ->request_filesystem_credentials(), WP_Filesystem(), is_wp_error(), ->has_errors(), get_theme_root(), ->find_folder(), basename(), esc_html(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 160 | 15–73 | 18 | |
| 8.5 | 160 | 15–73 | 18 | |
| 8.4 | 160 | 15–73 | 18 | |
| 8.3 | 160 | 15–73 | 18 | |
| 8.2 | 160 | 15–73 | 18 | 1 more instruction than PHP 8.1 |
| 8.1 | 159 | 15–72 | 18 | |
| 7.4 | 159 | 15–72 | 18 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- WP_Filesystem()Initializes and connects the WordPress Filesystem Abstraction classes.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_theme_root()Retrieves path to themes directory.
- esc_html()Escaping for HTML blocks.
- WP_Error::__construct()Initializes the error.
Used by · 1
- WP_Upgrader::run()Runs an upgrade/installation.
Source code
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; }Changelog
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-wp-upgrader.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.