We do not have official Documents and information about the filter wpt_field_options
but we work on this.
The filter wpt_field_options
can be used to manipulate the options of select and radio field.
Arguments:
$current_options
$title
(the title of the field)
Output:
Array
Required format:
array(
array(
'#title' => 'First Title',
'#value' => 'first-value'
),
array(
'#title' => 'Second Title',
'#value' => 'second-value'
),
)
Example of usage:
Let’s assume your theme has a colorset of dark, light and accent color, which are editable in the theme options. The theme stores these values as a wp_option
theme_name_colorset
in this format:
array(
'Dark' => '#333333',
'Light' => '#eeeeee',
'Accent Color' => '#ff3300'
)
You want to use these colors on a custom select field to define the headline color of the post. So we create a post field group with a select field:
https://drive.google.com/file/d/0B-e4FFHtzndlU1dfaXZtMFJlV2c/view?usp=sharing
Now we adding this function to our themes functions.php:
add_filter( 'wpt_field_options', function ( $current_options, $title_of_field ) {
if ( $title_of_field != 'Headline Color' ) {
// not our "Headline Color" field
return $current_options;
}
$theme_colorset = get_option( 'theme_name_colorset' );
if ( ! $theme_colorset ) {
// no theme colors are set yet
return array(
array(
'#title' => 'No colors available',
'#value' => 0
)
);
}
$new_options = array();
foreach ( $theme_colorset as $color_title => $color_value ) {
$new_options[] = array(
'#title' => $color_title . ' (' . $color_value . ')',
'#value' => $color_value
);
}
return $new_options;
}, 10, 2 );
This is the result:
https://drive.google.com/open?id=0B-e4FFHtzndlenRNVVowNW44RFk
https://drive.google.com/open?id=0B-e4FFHtzndlaE83blNKeVRKSWc
I cannot assist Custom Code further, but this should give you enough informations to work with it.
Soon we will publish a DOC about it as well.