Skip to content

Commit fa93a8b

Browse files
nickbarrettjbnickforddev
authored andcommitted
add return format option
1 parent 2551951 commit fa93a8b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

acf-swatch-v5.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function __construct() {
4040
'default_value' => '',
4141
'other_choice' => 0,
4242
'save_other_choice' => 0,
43+
'return_format' => 'value'
4344
);
4445
$this->settings = array(
4546
'basename' => plugin_basename( __FILE__ ),
@@ -298,6 +299,20 @@ function render_field_settings( $field ) {
298299
)
299300
));
300301

302+
// return value
303+
acf_render_field_setting( $field, array(
304+
'label' => __('Return Value','acf'),
305+
'instructions' => __('Specify the returned value on front end','acf'),
306+
'type' => 'radio',
307+
'name' => 'return_format',
308+
'layout' => 'horizontal',
309+
'choices' => array(
310+
'value' => __('Value','acf'),
311+
'label' => __('Label','acf'),
312+
'array' => __('Both (Array)','acf')
313+
)
314+
));
315+
301316
}
302317

303318

@@ -414,6 +429,27 @@ function load_value( $value, $post_id, $field ) {
414429

415430
}
416431

432+
/*
433+
* format_value()
434+
*
435+
* This filter is appied to the $value after it is loaded from the db and before it is returned to the template
436+
*
437+
* @type filter
438+
* @since 3.6
439+
* @date 23/01/13
440+
*
441+
* @param $value (mixed) the value which was loaded from the database
442+
* @param $post_id (mixed) the $post_id from which the value was loaded
443+
* @param $field (array) the field array holding all the field options
444+
*
445+
* @return $value (mixed) the modified value
446+
*/
447+
function format_value( $value, $post_id, $field ) {
448+
449+
return acf_get_field_type('select')->format_value( $value, $post_id, $field );
450+
451+
}
452+
417453
function input_admin_enqueue_scripts() {
418454

419455
// vars
@@ -442,4 +478,4 @@ function input_admin_enqueue_scripts() {
442478

443479
new acf_field_swatch();
444480

445-
endif;
481+
endif;

0 commit comments

Comments
 (0)