Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2014 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/726ef3a080bf43b52cc5 to your computer and use it in GitHub Desktop.
Save anonymous/726ef3a080bf43b52cc5 to your computer and use it in GitHub Desktop.
ACF Custom field
<?php
class acf_field_graphic_radio extends acf_field {
function __construct()
{
$this->name = 'graphic_radio';
$this->label = 'Graphic Radio';
$this->category = 'choice';
$this->defaults = [
'per_row' => 4,
'choices' => []
];
$this->l10n = ['error' => 'Error! Please enter a higher value'];
parent::__construct();
}
function render_field_settings($field)
{
$field['choices'] = acf_encode_choices($field['choices']);
acf_render_field_setting( $field, [
'label' => 'Choices',
'instructions' => 'type a choice per row like:<br><br>value : url',
'type' => 'textarea',
'name' => 'choices'
]);
acf_render_field_setting( $field, [
'label' => 'Per row',
'instructions' => 'How many choices shoud be display pr. row?',
'type' => 'number',
'name' => 'per_row'
]);
}
function validate_value($valid, $value, $field, $input)
{
return !!trim($value);
}
function render_field($field)
{
include __DIR__."/view.php";
}
function update_field($field)
{
// decode choices (convert to array)
$field['choices'] = acf_decode_choices($field['choices']);
return $field;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment