钩子文档

request_filesystem_credentials

💡 云策文档标注

概述

request_filesystem_credentials 是一个 WordPress 过滤器,用于过滤文件系统凭据。它允许开发者自定义凭据处理逻辑,例如短路表单输出或返回凭据数组。

关键要点

  • 过滤器返回非空字符串时,会短路文件系统凭据表单的输出,直接返回该值。
  • 返回 true 表示不需要凭据,false 表示需要但未提供,数组表示已提供凭据。
  • 参数包括 $credentials(默认空字符串)、$form_post、$type、$error、$context、$extra_fields 和 $allow_relaxed_file_ownership。
  • 在 request_filesystem_credentials() 函数中使用,用于请求 FTP/SSH 详细信息以连接文件系统。
  • 版本变更:4.6.0 中 $context 参数默认值从 false 改为空字符串,2.5.0 引入。

📄 原文内容

Filters the filesystem credentials.

Description

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.

Parameters

$credentialsmixed
Credentials to return instead. Default empty string.
$form_poststring
The URL to post the form to.
$typestring
Chosen type of filesystem.
$errorbool|WP_Error
Whether the current request has failed to connect, or an error object.
$contextstring
Full path to the directory that is tested for being writable.
$extra_fieldsarray
Extra POST fields.
$allow_relaxed_file_ownershipbool
Whether to allow Group/World writable.

Source

$req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields, $allow_relaxed_file_ownership );

Changelog

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