| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
class Vimeography_Filesystem { |
| 7 |
|
| 8 |
/** |
| 9 |
* Set to ftp for testing |
| 10 |
* @var string |
| 11 |
*/ |
| 12 |
protected $_method = ''; |
| 13 |
|
| 14 |
/** |
| 15 |
* [$_url description] |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $_url = ''; |
| 19 |
|
| 20 |
/** |
| 21 |
* [$_fields description] |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
protected $_fields = array(); |
| 25 |
|
| 26 |
/** |
| 27 |
* [__construct description] |
| 28 |
* @param string $url [description] |
| 29 |
* @param array $fields [description] |
| 30 |
*/ |
| 31 |
public function __construct( $url = '', $fields = array() ) { |
| 32 |
$this->_url = $url; |
| 33 |
$this->_fields = $fields; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* [connect description] |
| 38 |
* @return [type] [description] |
| 39 |
*/ |
| 40 |
public function connect() { |
| 41 |
// Try to setup WP_Filesystem |
| 42 |
if ( FALSE === ( $creds = request_filesystem_credentials( $this->_url, $this->_method, FALSE, FALSE, $this->_fields ) ) ) |
| 43 |
// A form has just been output asking the user to verify file ownership |
| 44 |
return FALSE; |
| 45 |
|
| 46 |
// If the user enters the credentials but the credentials can't be verified to setup WP_Filesystem, output the form again |
| 47 |
if ( ! WP_Filesystem( $creds ) ) { |
| 48 |
// This time produce the error that tells the user there was an error connecting |
| 49 |
request_filesystem_credentials( $this->_url, $this->_method, TRUE, FALSE, $this->_fields ); |
| 50 |
return FALSE; |
| 51 |
} |
| 52 |
|
| 53 |
return TRUE; |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
|