-
-
Save anonymous/726ef3a080bf43b52cc5 to your computer and use it in GitHub Desktop.
ACF Custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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