/** * @param string $file path to file * @param $permission * @param string $method * @param string $url * @param bool|string $context * @return bool * @throws FilesystemCredentialException with S/FTP form if it can't get the required filesystem credentials * @throws FileOperationException */ function w3_chmod_file($file, $permission, $method = '', $url = '', $context = false) { if (!file_exists($file)) { return false; } if (@chmod($file, $permission)) { return true; } w3_wp_request_filesystem_credentials($method, $url, $context); global $wp_filesystem; if (!$wp_filesystem->chmod($file, $permission)) { throw new FileOperationException('Could not chmod file: ' . $file, 'chmod', 'file', $file); } return true; }
/** * @param $file * @param string $method * @param string $url * @param bool|string $context folder where file to be deleted resides * @throws FilesystemOperationException with S/FTP form if it can't get the required filesystem credentials */ function w3_wp_delete_file($filename) { if (!@file_exists($filename)) { return; } if (@unlink($filename)) { return; } try { w3_wp_request_filesystem_credentials(); } catch (FilesystemOperationException $ex) { throw new FilesystemRmException($ex->getMessage(), $ex->credentials_form(), $filename); } global $wp_filesystem; if (!$wp_filesystem->delete($filename)) { throw new FilesystemRmException(__('FTP credentials don\'t allow to delete ', 'w3-total-cache') . '<strong>' . $filename . '</strong>', w3_get_filesystem_credentials_form(), $filename); } }