wppaste
WordPress

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:2364
Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.

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 POST fields 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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
267–323

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 533.

Plugin surface
2 hooks

Third-party callbacks on 'request_filesystem_credentials', 'fs_ftp_connection_types' run inside this call, and their cost is not bounded by anything here.

Called by
12

12 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below request_filesystem_credentials()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls 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–277apply_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–280apply_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–320apply_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–323apply_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

PHPCompiledExecutedBranchesNotes
8.6-dev533267–32361
8.5533267–32361
8.4533267–323618 fewer instructions than PHP 8.3
8.3541273–32961
8.2541273–3296111 more instructions than PHP 8.1
8.1530270–32659
7.4530270–32659

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:

  1. apply_filters( request_filesystem_credentials )filterline 2389 (+25 into the body)

    Filters the filesystem credentials.

  2. apply_filters( fs_ftp_connection_types )filterline 2543 (+179 into the body)

    Filters the connection types to output to the filesystem credentials form.

Uses · 19

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.6.0
The $context parameter default changed from false to an empty string.from the docblock
2.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.