函数文档

wp_readonly()

💡 云策文档标注

概述

wp_readonly() 函数用于输出 HTML readonly 属性,通过比较两个参数值来标记表单元素为只读状态。

关键要点

  • 函数基于 __checked_selected_helper() 实现,用于生成 readonly 属性字符串。
  • 参数包括 $readonly_value(必需,比较值)、$current(可选,默认 true)和 $display(可选,控制输出方式)。
  • 返回 HTML 属性字符串或空字符串,常用于表单字段的只读条件判断。

代码示例

function wp_readonly( $readonly_value, $current = true, $display = true ) {
    return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
}

注意事项

  • 该函数在 WordPress 5.9.0 版本中引入,是私有辅助函数的一部分。
  • 与 readonly() 函数相关,但 wp_readonly() 是核心函数,用于更通用的只读属性输出。

📄 原文内容

Outputs the HTML readonly attribute.

Description

Compares the first two arguments and if identical marks as readonly.

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

Return

string HTML attribute or empty string.

Source

function wp_readonly( $readonly_value, $current = true, $display = true ) {
	return __checked_selected_helper( $readonly_value, $current, $display, 'readonly' );
}

Changelog

Version Description
5.9.0 Introduced.