| @@ -9,16 +9,16 @@ | ||
| 9 | 9 | public $file_name; |
| 10 | 10 | public $error_message; |
| 11 | 11 | public $uploads; |
| 12 | 12 | private $new_file_path; |
| 13 | - public $chmod_dir = 0755; | |
| 14 | - public $chmod_file = 0644; | |
| 13 | + public $chmod_dir = 0755; | |
| 14 | + public $chmod_file = 0644; | |
| 15 | 15 | private $has_permission = false; |
| 16 | 16 | |
| 17 | 17 | public function __construct( $atts ) { |
| 18 | - $this->folder_name = $atts['folder_name'] ?? ''; | |
| 18 | + $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : ''; | |
| 19 | 19 | $this->file_name = $atts['file_name']; |
| 20 | - $this->error_message = $atts['error_message'] ?? ''; | |
| 20 | + $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : ''; | |
| 21 | 21 | $this->uploads = wp_upload_dir(); |
| 22 | 22 | $this->set_new_file_path( $atts ); |
| 23 | 23 | $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
| 24 | 24 | $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
| @@ -47,12 +47,12 @@ | ||
| 47 | 47 | public function create_file( $file_content ) { |
| 48 | 48 | if ( $this->has_permission ) { |
| 49 | 49 | $dirs_exist = true; |
| 50 | 50 | |
| 51 | - // Create the directories if need be. | |
| 51 | + // Create the directories if need be | |
| 52 | 52 | $this->create_directories( $dirs_exist ); |
| 53 | 53 | |
| 54 | - // Only write the file if the folders exist. | |
| 54 | + // only write the file if the folders exist | |
| 55 | 55 | if ( $dirs_exist ) { |
| 56 | 56 | global $wp_filesystem; |
| 57 | 57 | $wp_filesystem->put_contents( $this->new_file_path, $file_content, $this->chmod_file ); |
| 58 | 58 | } |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | * Combine an array of files into one |
| 82 | 82 | * |
| 83 | 83 | * @since 3.0 |
| 84 | 84 | * |
| 85 | - * @param array $file_names And array of file paths. | |
| 85 | + * @param array $file_names And array of file paths | |
| 86 | 86 | * |
| 87 | 87 | * @return void |
| 88 | 88 | */ |
| 89 | 89 | public function combine_files( $file_names ) { |
| @@ -165,9 +165,9 @@ | ||
| 165 | 165 | $needed_dirs = array(); |
| 166 | 166 | |
| 167 | 167 | $next_dir = ''; |
| 168 | 168 | foreach ( $dir_names as $dir ) { |
| 169 | - $next_dir .= '/' . $dir; | |
| 169 | + $next_dir .= '/' . $dir; | |
| 170 | 170 | $needed_dirs[] = $this->uploads['basedir'] . $next_dir; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return $needed_dirs; |
| @@ -174,9 +174,9 @@ | ||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | private function get_creds() { |
| 177 | 177 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
| 178 | - include_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 178 | + include_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $access_type = get_filesystem_method(); |
| 182 | 182 | if ( $access_type === 'direct' ) { |
| @@ -203,15 +203,14 @@ | ||
| 203 | 203 | $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname']; |
| 204 | 204 | $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username']; |
| 205 | 205 | $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ''; |
| 206 | 206 | |
| 207 | - // Check to see if we are setting the public/private keys for ssh. | |
| 207 | + // Check to see if we are setting the public/private keys for ssh | |
| 208 | 208 | $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; |
| 209 | 209 | $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ''; |
| 210 | 210 | |
| 211 | - // Sanitize the hostname, Some people might pass in odd-data. | |
| 212 | - // Strip any schemes off. | |
| 213 | - $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); | |
| 211 | + // Sanitize the hostname, Some people might pass in odd-data: | |
| 212 | + $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off | |
| 214 | 213 | |
| 215 | 214 | if ( strpos( $credentials['hostname'], ':' ) ) { |
| 216 | 215 | list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 ); |
| 217 | 216 | if ( ! is_numeric( $credentials['port'] ) ) { |
| @@ -223,12 +222,12 @@ | ||
| 223 | 222 | |
| 224 | 223 | if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) { |
| 225 | 224 | $credentials['connection_type'] = 'ssh'; |
| 226 | 225 | } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { |
| 227 | - // Only the FTP Extension understands SSL. | |
| 226 | + //Only the FTP Extension understands SSL | |
| 228 | 227 | $credentials['connection_type'] = 'ftps'; |
| 229 | 228 | } elseif ( ! isset( $credentials['connection_type'] ) ) { |
| 230 | - // All else fails (And it's not defaulted to something else saved), Default to FTP. | |
| 229 | + //All else fails (And it's not defaulted to something else saved), Default to FTP | |
| 231 | 230 | $credentials['connection_type'] = 'ftp'; |
| 232 | 231 | } |
| 233 | 232 | |
| 234 | 233 | $has_creds = ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) ); |
| @@ -235,9 +234,9 @@ | ||
| 235 | 234 | $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) ); |
| 236 | 235 | if ( $has_creds || $can_ssh ) { |
| 237 | 236 | $stored_credentials = $credentials; |
| 238 | 237 | if ( ! empty( $stored_credentials['port'] ) ) { |
| 239 | - // Save port as part of hostname to simplify above code. | |
| 238 | + //save port as part of hostname to simplify above code. | |
| 240 | 239 | $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; |
| 241 | 240 | } |
| 242 | 241 | |
| 243 | 242 | unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] ); |