readonly()
云策文档标注
概述
readonly() 函数用于输出 HTML readonly 属性,通过比较两个参数值来决定是否标记为只读。该函数已弃用,不适用于 PHP 8.1 及以上版本,建议使用 wp_readonly() 替代。
关键要点
- 函数作用:比较参数并输出 HTML readonly 属性字符串。
- 弃用状态:自 WordPress 5.9.0 起弃用,推荐使用 wp_readonly()。
- 兼容性:不能在 PHP >= 8.1 环境中使用。
- 参数说明:$readonly_value(必需,比较值),$current(可选,默认 true,比较值),$display(可选,默认 true,控制输出方式)。
- 返回值:返回 HTML 属性字符串或空字符串。
代码示例
function readonly( $readonly_value, $current = true, $display = true ) {
_deprecated_function( __FUNCTION__, '5.9.0', 'wp_readonly()' );
return wp_readonly( $readonly_value, $current, $display );
}注意事项
- 使用此函数会触发弃用警告,建议尽快迁移到 wp_readonly()。
- 相关函数:wp_readonly() 和 _deprecated_function()。
原文内容
Outputs the HTML readonly attribute.
Description
Compares the first two arguments and if identical marks as readonly.
This function is deprecated, and cannot be used on PHP >= 8.1.
See also
Parameters
$readonly_valuemixedrequired-
One of the values to compare.
$currentmixedoptional-
The other value to compare if not just true.
Default:
true $displaybooloptional-
Whether to echo or just return the string.
Default:
true
Source
function readonly( $readonly_value, $current = true, $display = true ) {
_deprecated_function( __FUNCTION__, '5.9.0', 'wp_readonly()' );
return wp_readonly( $readonly_value, $current, $display );
}
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Deprecated. Use wp_readonly() introduced in 5.9.0. |
| 4.9.0 | Introduced. |