request_filesystem_credentials( string $form_post, string $type = '', bool|WP_Error $error = false, string $context = '', array $extra_fields = null, bool $allow_relaxed_file_ownership = false ): bool|array
- Since
- 2.5.0, 4.6.0
- Source
wp-admin/includes/file.php:2375
Description
All chosen/entered details are saved, excluding the password.
Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port.
Plugins may override this form by returning true|false via the 'request_filesystem_credentials' filter.
Compatibility
- WordPress
- since 4.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$form_poststring- The URL to post the form to.
$typestringoptional- Chosen type of filesystem. Default empty.Default:
'' $errorbool|WP_Erroroptional- Whether the current request has failed to connect, or an error object. Default false.Default:
false $contextstringoptional- Full path to the directory that is tested for being writable. Default empty.Default:
'' $extra_fieldsarrayoptional- Extra
POSTfields to be checked for inclusion in the post. Default null.Default:null $allow_relaxed_file_ownershipbooloptional- Whether to allow Group/World writable.
Default false.Default:false
Return value
bool|array- True if no filesystem credentials are required, false if they are required but have not been provided, array of credentials if they are required and have been provided.
Performance profile
How much work a call to request_filesystem_credentials() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 267–323
- Plugin surface
- 2 hooks
- Called by
- 12
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 533.
Third-party callbacks on 'request_filesystem_credentials', 'fs_ftp_connection_types' run inside this call, and their cost is not bounded by anything here.
12 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below request_filesystem_credentials() - serializeserialisation
maybe_unserialize()one call below request_filesystem_credentials()
Further down the call graph this can also reach transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost request_filesystem_credentials() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$req_cred === "" && !empty($type) && $type !== "direct" && $extra_fields !== null && !isset($value) && !defined('FTP_SSH') && !defined('FS_METHOD') && !defined('FTP_SSL') && empty($submitted_form) && isset($credentials) && !$credentials && $pagenow === "plugins.php" && defined('FTP_PASS') | 267–277 | apply_filters(), get_option(), wp_unslash(), extension_loaded(), __(), extension_loaded(), extension_loaded(), apply_filters(), esc_url(), __(), __(), __(), _e(), _e(), __(), __(), _e(), esc_attr(), _e(), esc_attr_e(), disabled(), esc_attr(), disabled(), disabled(), _e(), disabled(), function_exists(), wp_nonce_field(), _e(), __(), submit_button() |
$req_cred === "" && !empty($type) && $type !== "direct" && $extra_fields !== null && !isset($value) && !defined('FTP_SSH') && !defined('FS_METHOD') && !defined('FTP_SSL') && empty($submitted_form) && isset($credentials) && !$credentials && $pagenow === "plugins.php" && empty($port) && !defined('FTP_PASS') | 270–280 | apply_filters(), get_option(), wp_unslash(), extension_loaded(), __(), extension_loaded(), extension_loaded(), apply_filters(), esc_url(), __(), __(), __(), _e(), _e(), __(), __(), _e(), esc_attr(), _e(), esc_attr_e(), disabled(), esc_attr(), disabled(), disabled(), _e(), _e(), disabled(), function_exists(), wp_nonce_field(), _e(), __(), submit_button() |
$req_cred === "" && !empty($type) && $type !== "direct" && $extra_fields !== null && !isset($value) && !defined('FTP_SSH') && !defined('FS_METHOD') && !defined('FTP_SSL') && empty($submitted_form) && isset($credentials) && !$credentials && $pagenow === "plugins.php" && defined('FTP_PASS') | 309–320 | apply_filters(), get_option(), wp_unslash(), extension_loaded(), __(), extension_loaded(), extension_loaded(), apply_filters(), esc_url(), __(), __(), __(), _e(), _e(), __(), __(), _e(), esc_attr(), _e(), esc_attr_e(), disabled(), esc_attr(), disabled(), disabled(), _e(), disabled(), _e(), _e(), esc_attr(), disabled(), _e(), esc_attr(), disabled(), _e(), function_exists(), wp_nonce_field(), _e(), __(), submit_button() |
$req_cred === "" && !empty($type) && $type !== "direct" && $extra_fields !== null && !isset($value) && !defined('FTP_SSH') && !defined('FS_METHOD') && !defined('FTP_SSL') && empty($submitted_form) && isset($credentials) && !$credentials && $pagenow === "plugins.php" && empty($port) && !defined('FTP_PASS') | 312–323 | apply_filters(), get_option(), wp_unslash(), extension_loaded(), __(), extension_loaded(), extension_loaded(), apply_filters(), esc_url(), __(), __(), __(), _e(), _e(), __(), __(), _e(), esc_attr(), _e(), esc_attr_e(), disabled(), esc_attr(), disabled(), disabled(), _e(), _e(), disabled(), _e(), _e(), esc_attr(), disabled(), _e(), esc_attr(), disabled(), _e(), function_exists(), wp_nonce_field(), _e(), __(), submit_button() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 533 | 267–323 | 61 | |
| 8.5 | 533 | 267–323 | 61 | |
| 8.4 | 533 | 267–323 | 61 | 8 fewer instructions than PHP 8.3 |
| 8.3 | 541 | 273–329 | 61 | |
| 8.2 | 541 | 273–329 | 61 | 11 more instructions than PHP 8.1 |
| 8.1 | 530 | 270–326 | 59 | |
| 7.4 | 530 | 270–326 | 59 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while request_filesystem_credentials() runs, in this order:
- apply_filters( request_filesystem_credentials )filterline 2400 (+25 into the body)
Filters the filesystem credentials.
- apply_filters( fs_ftp_connection_types )filterline 2554 (+179 into the body)
Filters the connection types to output to the filesystem credentials form.
Uses · 19
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_filesystem_method()Determines which method to use for reading, writing, modifying, or deleting files on the filesystem.
- get_option()Retrieves an option value based on an option name.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- wp_verify_nonce()Verifies that a correct security nonce was used with time limit.
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- update_option()Updates the value of an option that was already added.
- __()Retrieves the translation of $text.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- esc_html()Escaping for HTML blocks.
- wp_admin_notice()Outputs an admin notice.
- esc_url()Checks and cleans a URL.
Show all 19
- _e()Displays translated text.
- esc_attr()Escaping for HTML attributes.
- esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.
- disabled()Outputs the HTML disabled attribute.
- checked()Outputs the HTML checked attribute.
- wp_nonce_field()Retrieves or display nonce hidden field for forms.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
Used by · 12
- WP_Customize_Manager::customize_pane_settings()Prints JavaScript settings for parent window.
- WP_REST_Plugins_Controller::is_filesystem_available()Determine if the endpoints are available.
- WP_Site_Health::get_test_update_temp_backup_writable()Tests if plugin and theme temporary backup directories are writable or can be created.
- WP_Upgrader::maintenance_mode()Toggles maintenance mode for the site.
- WP_Upgrader_Skin::request_filesystem_credentials()Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
- _wp_delete_all_temp_backups()Deletes all contents in the temporary backup directory.
- delete_plugins()Removes directory and files of a plugin for a list of plugins.
- delete_theme()Removes a theme.
- do_core_upgrade()Upgrades WordPress core display.
- wp_ajax_delete_plugin()Handles deleting a plugin via AJAX.
- wp_ajax_delete_theme()Handles deleting a theme via AJAX.
- wp_print_request_filesystem_credentials_modal()Prints the filesystem credentials modal when needed.
Source code
function request_filesystem_credentials( $form_post, $type = '', $error = false, $context = '', $extra_fields = null, $allow_relaxed_file_ownership = false ) { global $pagenow; /** * Filters the filesystem credentials. * * Returning anything other than an empty string will effectively short-circuit * output of the filesystem credentials form, returning that value instead. * * A filter should return true if no filesystem credentials are required, false if they are required but have not been * provided, or an array of credentials if they are required and have been provided. * * @since 2.5.0 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string. * * @param mixed $credentials Credentials to return instead. Default empty string. * @param string $form_post The URL to post the form to. * @param string $type Chosen type of filesystem. * @param bool|WP_Error $error Whether the current request has failed to connect, * or an error object. * @param string $context Full path to the directory that is tested for * being writable. * @param array $extra_fields Extra POST fields. * @param bool $allow_relaxed_file_ownership Whether to allow Group/World writable. */ $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership ); if ( '' !== $req_cred ) { return $req_cred; } if ( empty( $type ) ) { $type = get_filesystem_method( array(), $context, $allow_relaxed_file_ownership ); } if ( 'direct' === $type ) { return true; } if ( is_null( $extra_fields ) ) { $extra_fields = array( 'version', 'locale' ); } $credentials = get_option( 'ftp_credentials', array( 'hostname' => '', 'username' => '', ) ); $submitted_form = wp_unslash( $_POST ); // Verify nonce, or unset submitted form field values on failure. if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) { unset( $submitted_form['hostname'], $submitted_form['username'], $submitted_form['password'], $submitted_form['public_key'], $submitted_form['private_key'], $submitted_form['connection_type'] ); } $ftp_constants = array( 'hostname' => 'FTP_HOST', 'username' => 'FTP_USER', 'password' => 'FTP_PASS', 'public_key' => 'FTP_PUBKEY', 'private_key' => 'FTP_PRIKEY', ); /* * If defined, set it to that. Else, if POST'd, set it to that. If not, set it to an empty string. * Otherwise, keep it as it previously was (saved details in option). */ foreach ( $ftp_constants as $key => $constant ) { if ( defined( $constant ) ) { $credentials[ $key ] = constant( $constant );Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$context parameter default changed from false to an empty string.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/file.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.