函数文档

wp_is_writable()

💡 云策文档标注

概述

wp_is_writable() 函数用于检查目录是否可写,主要解决 PHP 中影响 Windows 服务器的 ACL 问题。它通过调用 win_is_writable() 在 Windows 系统上提供兼容性。

关键要点

  • 函数用途:判断指定路径是否可写,特别针对 Windows 服务器的 ACL 问题提供解决方案。
  • 参数:$path(字符串,必需),表示要检查的路径。
  • 返回值:布尔值,指示路径是否可写。
  • 系统依赖:在 Windows 系统上调用 win_is_writable(),否则使用 PHP 内置的 is_writable() 函数。
  • 相关函数:win_is_writable() 作为辅助函数处理 Windows 特定问题。
  • 使用场景:被 WP_Debug_Data::get_wp_filesystem()、WP_Http::request() 和 get_temp_dir() 等函数调用。
  • 版本历史:自 WordPress 3.6.0 版本引入。

代码示例

function wp_is_writable( $path ) {
    if ( 'Windows' === PHP_OS_FAMILY ) {
        return win_is_writable( $path );
    }

    return @is_writable( $path );
}

📄 原文内容

Determines if a directory is writable.

Description

This function is used to work around certain ACL issues in PHP primarily affecting Windows Servers.

See also

Parameters

$pathstringrequired
Path to check for write-ability.

Return

bool Whether the path is writable.

Source

function wp_is_writable( $path ) {
	if ( 'Windows' === PHP_OS_FAMILY ) {
		return win_is_writable( $path );
	}

	return @is_writable( $path );
}

Changelog

Version Description
3.6.0 Introduced.