A CodeMirror-backed code editor with syntax highlighting.
Field::code(string $key): CodeField->language(string $lang): staticProgramming language for syntax highlighting. Default: 'text'. Common values: 'php', 'javascript', 'css', 'html', 'json', 'bash'.
->rows(int $rows): staticEditor height in lines. Default: 10.
->wrapLines(bool $wrap = true): staticWrap long lines. Default: false.
Stored as a string. Sanitized with wp_kses_post() (strips <script> and unsafe tags while preserving code characters like <, >, &).
Field::code('custom_css')
->label('Custom CSS')
->language('css')
->rows(15),
Field::code('template_snippet')
->label('PHP Snippet')
->language('php')
->wrapLines(),To display code in a <pre> block:
<pre><code class="language-{{ 'php' }}">{{ ctrlfield_get('template_snippet') }}</code></pre>To execute PHP stored in the field (use with extreme caution):
// Only do this if code comes from a trusted admin — never from public input
$code = ctrlfield_get('custom_script');
if ($code) {
eval($code);
}