函数文档

request_filesystem_credentials()

💡 云策文档标注

概述

request_filesystem_credentials() 函数用于向用户显示一个表单,以请求 FTP/SSH 凭据来连接文件系统。它处理凭据的收集、验证和存储,并支持通过过滤器进行自定义。

关键要点

  • 函数显示表单以获取 FTP/SSH 主机名、用户名、密码、公钥、私钥和连接类型等凭据,密码不保存。
  • 支持通过 'request_filesystem_credentials' 过滤器覆盖表单逻辑,返回 true、false 或凭据数组以控制流程。
  • 参数包括 $form_post(表单提交URL)、$type(文件系统类型)、$error(错误状态)、$context(目录路径)、$extra_fields(额外POST字段)和 $allow_relaxed_file_ownership(放宽文件所有权)。
  • 返回值:true 表示无需凭据,false 表示需要但未提供,数组表示已提供凭据。
  • 函数内部处理非ce验证、凭据从常量或POST获取、主机名和端口解析、连接类型确定,并更新选项存储。
  • 使用 'fs_ftp_connection_types' 过滤器可自定义连接类型输出。

代码示例

$creds = request_filesystem_credentials(
    $form_post,
    "",         // type
    false,      // error
    false,      // context
    null,       // extra_fields
);
if ( false === $creds ) {
    return;
}

📄 原文内容

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.

Parameters

$form_poststringrequired
The URL to post the form to.
$typestringoptional
Chosen type of filesystem. Default empty.
$errorbool|WP_Erroroptional
Whether the current request has failed to connect, or an error object.

Default:false

$contextstringoptional
Full path to the directory that is tested for being writable. Default empty.
$extra_fieldsarrayoptional
Extra POST fields to be checked for inclusion in the post.

Default:null

$allow_relaxed_file_ownershipbooloptional
Whether to allow Group/World writable.

Default:false

Return

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.

Source

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 );
		} elseif ( ! empty( $submitted_form[ $key ] ) ) {
			$credentials[ $key ] = $submitted_form[ $key ];
		} elseif ( ! isset( $credentials[ $key ] ) ) {
			$credentials[ $key ] = '';
		}
	}

	// Sanitize the hostname, some people might pass in odd data.
	$credentials['hostname'] = preg_replace( '|w+://|', '', $credentials['hostname'] ); // Strip any schemes off.

	if ( strpos( $credentials['hostname'], ':' ) ) {
		list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 );
		if ( ! is_numeric( $credentials['port'] ) ) {
			unset( $credentials['port'] );
		}
	} else {
		unset( $credentials['port'] );
	}

	if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' === FS_METHOD ) ) {
		$credentials['connection_type'] = 'ssh';
	} elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $type ) { // Only the FTP Extension understands SSL.
		$credentials['connection_type'] = 'ftps';
	} elseif ( ! empty( $submitted_form['connection_type'] ) ) {
		$credentials['connection_type'] = $submitted_form['connection_type'];
	} elseif ( ! isset( $credentials['connection_type'] ) ) { // All else fails (and it's not defaulted to something else saved), default to FTP.
		$credentials['connection_type'] = 'ftp';
	}

	if ( ! $error
		&& ( ! empty( $credentials['hostname'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['password'] )
			|| 'ssh' === $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] )
		)
	) {
		$stored_credentials = $credentials;

		if ( ! empty( $stored_credentials['port'] ) ) { // Save port as part of hostname to simplify above code.
			$stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
		}

		unset(
			$stored_credentials['password'],
			$stored_credentials['port'],
			$stored_credentials['private_key'],
			$stored_credentials['public_key']
		);

		if ( ! wp_installing() ) {
			update_option( 'ftp_credentials', $stored_credentials, false );
		}

		return $credentials;
	}

	$hostname        = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
	$username        = isset( $credentials['username'] ) ? $credentials['username'] : '';
	$public_key      = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
	$private_key     = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
	$port            = isset( $credentials['port'] ) ? $credentials['port'] : '';
	$connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';

	if ( $error ) {
		$error_string = __( '<strong>Error:</strong> Could not connect to the server. Please verify the settings are correct.' );
		if ( is_wp_error( $error ) ) {
			$error_string = esc_html( $error->get_error_message() );
		}
		wp_admin_notice(
			$error_string,
			array(
				'id'                 => 'message',
				'additional_classes' => array( 'error' ),
			)
		);
	}

	$types = array();
	if ( extension_loaded( 'ftp' ) || extension_loaded( 'sockets' ) || function_exists( 'fsockopen' ) ) {
		$types['ftp'] = __( 'FTP' );
	}
	if ( extension_loaded( 'ftp' ) ) { // Only this supports FTPS.
		$types['ftps'] = __( 'FTPS (SSL)' );
	}
	if ( extension_loaded( 'ssh2' ) ) {
		$types['ssh'] = __( 'SSH2' );
	}

	/**
	 * Filters the connection types to output to the filesystem credentials form.
	 *
	 * @since 2.9.0
	 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
	 *
	 * @param string[]      $types       Types of connections.
	 * @param array         $credentials Credentials to connect with.
	 * @param string        $type        Chosen filesystem method.
	 * @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.
	 */
	$types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context );
	?>
<form action="<?php echo esc_url( $form_post ); ?>" method="post">
<div id="request-filesystem-credentials-form" class="request-filesystem-credentials-form">
	" . __( 'Connection Information' ) . "<!--$heading_tag-->";
	?>
<p id="request-filesystem-credentials-desc">
	
</p>
<label for="hostname">
	<span class="field-title"></span>
	<input name="hostname" type="text" id="hostname" aria-describedby="request-filesystem-credentials-desc" class="code" placeholder="<?php esc_attr_e( 'example: www.wordpress.org' ); ?>" value="<?php echo $hostname_value; ?>"<?php disabled( defined( 'FTP_HOST' ) ); ?> />
</label>
<div class="ftp-username">
	<label for="username">
		<span class="field-title"></span>
		<input name="username" type="text" id="username" value="<?php echo esc_attr( $username ); ?>"<?php disabled( defined( 'FTP_USER' ) ); ?> />
	</label>
</div>
<div class="ftp-password">
	<label for="password">
		<span class="field-title"></span>
		<input name="password" type="password" id="password" value="<?php echo $password_value; ?>"<?php disabled( defined( 'FTP_PASS' ) ); ?> spellcheck="false" />
		
	</label>
</div>
<fieldset>
<legend></legend>
	 $text ) :
		?>
	<label for="<?php echo esc_attr( $name ); ?>">
		<input type="radio" name="connection_type" id="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" <?php checked( $name, $connection_type ); ?>  />
		
	</label>
		
</fieldset>
	
<fieldset id="ssh-keys"<?php echo $hidden_class; ?>>
<legend></legend>
<label for="public_key">
	<span class="field-title"></span>
	<input name="public_key" type="text" id="public_key" aria-describedby="auth-keys-desc" value="<?php echo esc_attr( $public_key ); ?>"<?php disabled( defined( 'FTP_PUBKEY' ) ); ?> />
</label>
<label for="private_key">
	<span class="field-title"></span>
	<input name="private_key" type="text" id="private_key" value="<?php echo esc_attr( $private_key ); ?>"<?php disabled( defined( 'FTP_PRIKEY' ) ); ?> />
</label>
<p id="auth-keys-desc"></p>
</fieldset>
		';
		}
	}

	/*
	 * Make sure the `submit_button()` function is available during the REST API call
	 * from WP_Site_Health_Auto_Updates::test_check_wp_filesystem_method().
	 */
	if ( ! function_exists( 'submit_button' ) ) {
		require_once ABSPATH . 'wp-admin/includes/template.php';
	}
	?>
	<p class="request-filesystem-credentials-action-buttons">
		
		<button class="button cancel-button" data-js-action="close" type="button"></button>
		
	</p>
</div>
</form>
	</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/file.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/file.php#L2365">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/file.php#L2365-L2667">View on GitHub</a></p></section>
		<section class="wp-block-wporg-code-reference-hooks"><h2 id="hooks" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#hooks">Hooks</a></h2> <dl><dt class="wp-block-wporg-code-reference-title has-normal-font-size"><a href="https://developer.wordpress.org/reference/hooks/fs_ftp_connection_types/"><span class="hook-func">apply_filters</span>( ‘fs_ftp_connection_types’,  <nobr><span class="arg-type">string[]</span> <span class="arg-name">$types</span></nobr>,  <nobr><span class="arg-type">array</span> <span class="arg-name">$credentials</span></nobr>,  <nobr><span class="arg-type">string</span> <span class="arg-name">$type</span></nobr>,  <nobr><span class="arg-type">bool|WP_Error</span> <span class="arg-name">$error</span></nobr>,  <nobr><span class="arg-type">string</span> <span class="arg-name">$context</span></nobr> )</a></dt><dd><p>Filters the connection types to output to the filesystem credentials form.</p>
</dd><dt class="wp-block-wporg-code-reference-title has-normal-font-size"><a href="https://developer.wordpress.org/reference/hooks/request_filesystem_credentials/"><span class="hook-func">apply_filters</span>( ‘request_filesystem_credentials’,  <nobr><span class="arg-type">mixed</span> <span class="arg-name">$credentials</span></nobr>,  <nobr><span class="arg-type">string</span> <span class="arg-name">$form_post</span></nobr>,  <nobr><span class="arg-type">string</span> <span class="arg-name">$type</span></nobr>,  <nobr><span class="arg-type">bool|WP_Error</span> <span class="arg-name">$error</span></nobr>,  <nobr><span class="arg-type">string</span> <span class="arg-name">$context</span></nobr>,  <nobr><span class="arg-type">array</span> <span class="arg-name">$extra_fields</span></nobr>,  <nobr><span class="arg-type">bool</span> <span class="arg-name">$allow_relaxed_file_ownership</span></nobr> )</a></dt><dd><p>Filters the filesystem credentials.</p>
</dd></dl></section>
		<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_admin_notice/">wp_admin_notice()</a><code>wp-includes/functions.php</code></td><td><p>Outputs an admin notice.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_installing/">wp_installing()</a><code>wp-includes/load.php</code></td><td><p>Checks or sets whether WordPress is in “installation” mode.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/submit_button/">submit_button()</a><code>wp-admin/includes/template.php</code></td><td><p>Echoes a submit button, with provided text and appropriate class(es).</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/get_filesystem_method/">get_filesystem_method()</a><code>wp-admin/includes/file.php</code></td><td><p>Determines which method to use for reading, writing, modifying, or deleting files on the filesystem.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/esc_attr_e/">esc_attr_e()</a><code>wp-includes/l10n.php</code></td><td><p>Displays translated text that has been escaped for safe use in an attribute.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/wp_verify_nonce/">wp_verify_nonce()</a><code>wp-includes/pluggable.php</code></td><td><p>Verifies that a correct security nonce was used with time limit.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/disabled/">disabled()</a><code>wp-includes/general-template.php</code></td><td><p>Outputs the HTML disabled attribute.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/checked/">checked()</a><code>wp-includes/general-template.php</code></td><td><p>Outputs the HTML checked attribute.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/wp_nonce_field/">wp_nonce_field()</a><code>wp-includes/functions.php</code></td><td><p>Retrieves or display nonce hidden field for forms.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/__/">__()</a><code>wp-includes/l10n.php</code></td><td><p>Retrieves the translation of $text.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/_e/">_e()</a><code>wp-includes/l10n.php</code></td><td><p>Displays translated text.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/wp_unslash/">wp_unslash()</a><code>wp-includes/formatting.php</code></td><td><p>Removes slashes from a string or recursively removes slashes from strings within an array.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/esc_html/">esc_html()</a><code>wp-includes/formatting.php</code></td><td><p>Escaping for HTML blocks.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/esc_url/">esc_url()</a><code>wp-includes/formatting.php</code></td><td><p>Checks and cleans a URL.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/esc_attr/">esc_attr()</a><code>wp-includes/formatting.php</code></td><td><p>Escaping for HTML attributes.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/apply_filters/">apply_filters()</a><code>wp-includes/plugin.php</code></td><td><p>Calls the callback functions that have been added to a filter hook.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/update_option/">update_option()</a><code>wp-includes/option.php</code></td><td><p>Updates the value of an option that was already added.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/get_option/">get_option()</a><code>wp-includes/option.php</code></td><td><p>Retrieves an option value based on an option name.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/is_wp_error/">is_wp_error()</a><code>wp-includes/load.php</code></td><td><p>Checks whether the given variable is a WordPress Error.</p>
</td></tr></tbody></table></figure><a class="wp-block-wporg-code-table-show-more" href="#">Show 14 more</a><a class="wp-block-wporg-code-table-show-less" href="#">Show less</a></section>  <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="used-by"><figure class="wp-block-table "><table><thead><tr><th scope="col">Used by</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/_wp_delete_all_temp_backups/">_wp_delete_all_temp_backups()</a><code>wp-includes/update.php</code></td><td><p>Deletes all contents in the temporary backup directory.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/classes/wp_site_health/get_test_update_temp_backup_writable/">WP_Site_Health::get_test_update_temp_backup_writable()</a><code>wp-admin/includes/class-wp-site-health.php</code></td><td><p>Tests if plugin and theme temporary backup directories are writable or can be created.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/is_filesystem_available/">WP_REST_Plugins_Controller::is_filesystem_available()</a><code>wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php</code></td><td><p>Determine if the endpoints are available.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_ajax_delete_plugin/">wp_ajax_delete_plugin()</a><code>wp-admin/includes/ajax-actions.php</code></td><td><p>Handles deleting a plugin via AJAX.</p>
</td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_ajax_delete_theme/">wp_ajax_delete_theme()</a><code>wp-admin/includes/ajax-actions.php</code></td><td><p>Handles deleting a theme via AJAX.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/classes/wp_customize_manager/customize_pane_settings/">WP_Customize_Manager::customize_pane_settings()</a><code>wp-includes/class-wp-customize-manager.php</code></td><td><p>Prints JavaScript settings for parent window.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/wp_print_request_filesystem_credentials_modal/">wp_print_request_filesystem_credentials_modal()</a><code>wp-admin/includes/file.php</code></td><td><p>Prints the filesystem credentials modal when needed.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/classes/wp_upgrader/maintenance_mode/">WP_Upgrader::maintenance_mode()</a><code>wp-admin/includes/class-wp-upgrader.php</code></td><td><p>Toggles maintenance mode for the site.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/delete_theme/">delete_theme()</a><code>wp-admin/includes/theme.php</code></td><td><p>Removes a theme.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/classes/wp_upgrader_skin/request_filesystem_credentials/">WP_Upgrader_Skin::request_filesystem_credentials()</a><code>wp-admin/includes/class-wp-upgrader-skin.php</code></td><td><p>Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/delete_plugins/">delete_plugins()</a><code>wp-admin/includes/plugin.php</code></td><td><p>Removes directory and files of a plugin for a list of plugins.</p>
</td></tr><tr class="wporg-hidden"><td><a href="https://developer.wordpress.org/reference/functions/do_core_upgrade/">do_core_upgrade()</a><code>wp-admin/update-core.php</code></td><td><p>Upgrades WordPress core display.</p>
</td></tr></tbody></table></figure><a class="wp-block-wporg-code-table-show-more" href="#">Show 7 more</a><a class="wp-block-wporg-code-table-show-less" href="#">Show less</a></section> </section>
		<section class="wp-block-wporg-code-reference-changelog"><h2 id="changelog" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#changelog">Changelog</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table"><figure class="wp-block-table "><table><thead><tr><th scope="col">Version</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/since/4.6.0/">4.6.0</a></td><td><span class="since-description">The <code>$context</code> parameter default changed from <code>false</code> to an empty string.</span></td></tr><tr class=""><td><a href="https://developer.wordpress.org/reference/since/2.5.0/">2.5.0</a></td><td>Introduced.</td></tr></tbody></table></figure></section> </section>
		<section class="wp-block-wporg-code-reference-comments" data-nosnippet="true"><h2 id="user-contributed-notes" class="is-toc-heading wp-block-heading" tabindex="-1" ><a href="#user-contributed-notes">User Contributed Notes</a></h2> <ol class="comment-list">			<li id="comment-1465" data-comment-id="1465" class="comment byuser comment-author-codex odd alt thread-odd thread-alt depth-1">
			<article id="div-comment-1465" class="comment-body">

							<a href="#comment-content-1465" class="screen-reader-text">Skip to note 2 content</a>
				<header class="comment-meta">
					<div class="comment-author vcard">
						<span class="comment-author-attribution">
						<a href="https://profiles.wordpress.org/codex/" rel="external nofollow" class="url">Codex</a>						</span>
						<a class="comment-date" href="https://developer.wordpress.org/reference/functions/request_filesystem_credentials/#comment-1465">
							<time datetime="2016-03-24T13:40:46+00:00">
							10 years ago							</time>
						</a>

																													</div>
					<div class="user-note-voting" data-nonce="7c27a62359" data-can-vote="false"><a class="user-note-voting-up" title="You must log in to vote on the helpfulness of this note" data-id="1465" data-vote="up" href="https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frequest_filesystem_credentials%2F%23comment-1465"><span class="screen-reader-text">You must log in to vote on the helpfulness of this note</span></a><span class="user-note-voting-count " title=""><span class="screen-reader-text">Vote results for this note: </span>0</span><a class="user-note-voting-down" title="You must log in to vote on the helpfulness of this note" data-id="1465" data-vote="down" href="https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frequest_filesystem_credentials%2F%23comment-1465"><span class="screen-reader-text">You must log in to vote on the helpfulness of this note</span></a></div>				</header>
				<!-- .comment-metadata -->
			
				<div class="wporg-has-embedded-code comment-content" id="comment-content-1465">
				<p><strong>Usage</strong></p>
<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">$creds = request_filesystem_credentials( 
	 $form_post,
	 "",         // type
	 false,      // error
	 false,      // context
	 null,       // extra_fields
);
if ( false === $creds ) {
	return; 
}