WP_Filesystem_FTPext::__construct( array $opt = '' )
- Since
- 2.5.0
- Source
wp-admin/includes/class-wp-filesystem-ftpext.php:31
Compatibility
- WordPress
- since 2.5.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
$optarrayoptional- Default:
''
Performance profile
How much work a call to WP_Filesystem_FTPext::__construct() 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
- Trivial
- Scaling
- Constant
- Instructions
- 20–70
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 95.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Filesystem_FTPext::__construct() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 20–54 | extension_loaded(), __(), ->add() |
extension_loaded() && defined('FS_TIMEOUT') && !empty($opt) | 43–49 | extension_loaded() |
extension_loaded() && !defined('FS_TIMEOUT') && !empty($opt) | 49–55 | extension_loaded(), define() |
extension_loaded() && defined('FS_TIMEOUT') | 53–59 | extension_loaded(), __(), ->add(), __(), ->add() |
extension_loaded() && !defined('FS_TIMEOUT') | 54–60 | extension_loaded(), define(), __(), ->add() |
extension_loaded() && defined('FS_TIMEOUT') && empty($opt) | 58–64 | extension_loaded(), __(), ->add(), __(), ->add(), __(), ->add() |
extension_loaded() && !defined('FS_TIMEOUT') | 59–65 | extension_loaded(), define(), __(), ->add(), __(), ->add() |
extension_loaded() && !defined('FS_TIMEOUT') && empty($opt) | 64–70 | extension_loaded(), define(), __(), ->add(), __(), ->add(), __(), ->add() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 95 | 20–70 | 8 | |
| 8.5 | 95 | 20–70 | 8 | |
| 8.4 | 95 | 20–70 | 8 | |
| 8.3 | 95 | 20–70 | 8 | |
| 8.2 | 95 | 20–70 | 8 | 13 more instructions than PHP 8.1 |
| 8.1 | 82 | 39–66 | 7 | |
| 7.4 | 82 | 39–66 | 7 |
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 · 2
- __()Retrieves the translation of $text.
- WP_Error::__construct()Initializes the error.
Source code
public function __construct( $opt = '' ) { $this->method = 'ftpext'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! extension_loaded( 'ftp' ) ) { $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) ); return; } // This class uses the timeout on a per-connection basis, others use it on a per-action basis. if ( ! defined( 'FS_TIMEOUT' ) ) { define( 'FS_TIMEOUT', 4 * MINUTE_IN_SECONDS ); } if ( empty( $opt['port'] ) ) { $this->options['port'] = 21; } else { $this->options['port'] = $opt['port']; } if ( empty( $opt['hostname'] ) ) { $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) ); } else { $this->options['hostname'] = $opt['hostname']; } // Check if the options provided are OK. if ( empty( $opt['username'] ) ) { $this->errors->add( 'empty_username', __( 'FTP username is required' ) ); } else { $this->options['username'] = $opt['username']; } if ( empty( $opt['password'] ) ) { $this->errors->add( 'empty_password', __( 'FTP password is required' ) ); } else { $this->options['password'] = $opt['password']; } $this->options['ssl'] = false; if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { $this->options['ssl'] = true; } }Changelog
Introduced in 2.5.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 6.8.8 tag, from
src/wp-admin/includes/class-wp-filesystem-ftpext.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.