WP_Filesystem_FTPext::__construct
Constructor.
Method of the class: WP_Filesystem_FTPext{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Filesystem_FTPext = new WP_Filesystem_FTPext(); $WP_Filesystem_FTPext->__construct( $opt );
- $opt(array)
Array of connection options.
Default:
null-
hostname(string)
Required. FTP server hostname. -
username(string)
Required. FTP username. -
password(string)
Required. FTP password. -
port(int)
Optional. FTP server port.
Default: 21 - connection_type(string)
Optional. Connection type. Use 'ftps' to enable SSL.
-
Changelog
| Since 2.5.0 | Introduced. |
WP_Filesystem_FTPext::__construct() WP Filesystem FTPext:: construct code WP 7.1
public function __construct( $opt = null ) {
$this->method = 'ftpext';
$this->errors = new WP_Error();
$this->options = array(
'port' => 21,
'hostname' => '',
'username' => '',
'password' => '',
'ssl' => false,
);
// 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 ( ! is_array( $opt ) ) {
$opt = array();
}
if ( ! empty( $opt['port'] ) ) {
$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'];
}
if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) {
$this->options['ssl'] = true;
}
}