函数文档

wp_print_request_filesystem_credentials_modal()

💡 云策文档标注

概述

wp_print_request_filesystem_credentials_modal() 函数用于在需要时输出文件系统凭据模态框,主要用于处理非直接文件系统方法(如FTP/SSH)的凭据请求。

关键要点

  • 函数检查文件系统方法是否为非直接方式(如FTP/SSH),并验证凭据是否已存储。
  • 如果文件系统方法为'direct'或凭据已存储,函数将直接返回,不输出任何内容。
  • 当需要时,函数会输出一个包含凭据请求表单的模态框,用于用户输入FTP/SSH详细信息。
  • 此函数在WordPress 4.2.0版本中引入,常用于插件安装等需要文件系统访问的场景。

相关函数

  • get_filesystem_method(): 确定用于文件系统操作的方法。
  • request_filesystem_credentials(): 显示请求FTP/SSH凭据的表单。
  • self_admin_url(): 获取当前站点或网络的管理区域URL。
  • site_url(): 获取当前站点的URL,用于访问WordPress应用文件。

📄 原文内容

Prints the filesystem credentials modal when needed.

Source

function wp_print_request_filesystem_credentials_modal() {
$filesystem_method = get_filesystem_method();

ob_start();
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
ob_end_clean();

$request_filesystem_credentials = ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored );
if ( ! $request_filesystem_credentials ) {
return;
}
?>
<div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
<div class="notification-dialog-background"></div>
<div class="notification-dialog" role="dialog" aria-labelledby="request-filesystem-credentials-title" tabindex="0">
<div class="request-filesystem-credentials-dialog-content">

</div>
</div>
</div>
</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#L2674">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/file.php#L2674-L2695">View on GitHub</a></p></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/get_filesystem_method/">get_filesystem_method()</a><code>wp-admin/includes/file.php

Determines which method to use for reading, writing, modifying, or deleting files on the filesystem.

request_filesystem_credentials()wp-admin/includes/file.php

Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.

self_admin_url()wp-includes/link-template.php

Retrieves the URL to the admin area for either the current site or the network depending on context.

site_url()wp-includes/link-template.php

Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.

Used by Description
install_plugin_information()wp-admin/includes/plugin-install.php

Displays plugin information in dialog box form.

Changelog

Version Description
4.2.0 Introduced.