Filesystem API Class Reference
Filesystem API Class Reference:
Class: WP_Filesystem_Base
Class: WP_Filesystem_Direct
Class: WP_Filesystem_FTPext
Class: WP_Filesystem_ftpsocket
Class: WP_Filesystem_SSH2
Function: request_filesystem_credentials()
Getting Credentials:
The first step in using the WP_Filesystem is requesting credentials from the user. The normal way this is accomplished is at the time when you’re saving the results of a form input, or you have otherwise determined that you need to write to a file.
The request_filesystem_credentials() function accepts 5 parameters:
$form_post
$method
$error
$context
$extra_fields
$form_post is the URL in which the resulting form should be posted to. Security is always an issue, so you should be using wp_nonce_url() to build this URL, where the nonce field matches the nonce in the submitted form field. You can easily pass along extra query args here as well using add_query_arg().
$method is the method in which you want WP_Filesystem to use. Because WP_Filesystem automatically determines and populates the best method for use, there’s really no need to specify a particular method here unless you are doing it for testing purposes. A good use-case would be to force a particular method and ensure that WP_Filesystem will write files to your webserver correctly if it can’t verify the ownership of files.
$error is a boolean to specify whether you want to output an error message if WP_Filesystem fails to connect. It is false by default, but can be helpful to turn on for testing and debugging.
$context is the directory in which you want to test WP_Filesystem so that it can verify ownership of files. By default, it will attempt to write a temporary file to the wp-content directory (specified by the constant WP_CONTENT_DIR). This field can be useful if you want to test the particular directory in which you are about to write files.
$extra_fields are extra $_POST fields from the previous form that should be included in the resulting post form. The $_POST fields must be strings (arrays are not currently accepted ).
request_filesystem_credentials($form_post, $type, $error, $context, $extra_fields);