If you don’t need the input box, you can use the custom_html
type, like this:
array(
'id' => 'field_id',
'type' => 'custom_html',
'name' => 'Field Name',
'std' => 'Value', // This value is displayed as a HTML text, so users can't change it
)
If you need the input box, you can use the filter rwmb_{$field_id}_html
, like this:
add_filter( 'rwmb_YOUR_FIELD_ID_html', 'prefix_input_readonly' );
function prefix_input_readonly( $html )
{
return str_replace( '<input', '<input readonly', $html );
}
Although I don’t need input box, I prefer second way because MB already bring me the value (lazy programmer here !!). I just did some modification.
Thanks !!
return str_replace(
array(
'<input',
'<textarea',
'<select',
),
array(
'<input readonly',
'<textarea readonly',
'<select disabled',
),
$html );
FYI, I’ve just added this to documentation, so other people can search faster:
https://metabox.io/docs/how-to-set-a-field-as-read-only/