readonly()WP 4.9.0

Deprecated since 5.9.0. It is no longer supported and may be removed in future releases. Use wp_readonly() introduced in 5.9.0 instead.

Compares 2 values, if they match, outputs the string readonly='readonly'. Used for the tag <input>.

The function is deprecated, use wp_readonly() instead.

This is one of 4 helper functions for forms: checked(), disabled(), selected(), readonly().

No Hooks.

Returns

String. Outputs readonly='readonly' or an empty string ''.

If the last parameter $echo is false, the function will return the value instead of outputting it.

Usage

readonly( $readonly_value, $current, $display );
$readonly(mixed) (required)
One of the values to compare.
$current(mixed)
The second value to compare.
Default: true
$display(boolean)
Whether to output the result.
Default: true

Examples

0

#1 Let's add the readonly attribute

Suppose you want to add a readonly value to the field if the current user can't edit post 25:

<input type='text' name='myname' value='Value' <?php readonly( current_user_can('edit_post', 25 ) ?> />

Notes

Changelog

Since 4.9.0 Introduced.
Deprecated since 5.9.0 Use wp_readonly() introduced in 5.9.0.

readonly() code WP 6.9.1

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