readonly()WP 4.9.0

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

Outputs the html readonly attribute.

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

This function is deprecated, and cannot be used on PHP >= 8.1.

No Hooks.

Return

String. HTML attribute or empty string.

Usage

readonly( $readonly_value, $current, $display );
$readonly_value(mixed) (required)
One of the values to compare.
$current(mixed)
The other value to compare if not just true.
Default: true
$display(true|false)
Whether to echo or just return the string.
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.5.2

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