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

Code of readonly() WP 5.9.3

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