Hi,
I think you can do like this in your plugin:
$options = array(
'ea' => 'Each',
'hr' => 'Hourly',
'day' => 'Daily',
'wk' => 'Weekly',
'mth' => 'Month',
'yr' => 'Yearly',
);
$options = apply_filters( 'prefix_unit_options', $options );
Then when registering meta boxes, just specify 'options' => $options
.
It might be a better idea to wrap the value of options to a function like:
function prefix_get_unit_option() {
$options = ...;
return apply_filters( 'prefix_unit_options', $options );
}
And use 'options' => prefix_get_unit_option()
.
This way you can make a repeatable field in your settings page and get the values, passing them to the prefix_get_unit_option()
to build the array of options.
function prefix_get_unit_option() {
$options = ...; // Default options
$settings = get_option( 'option_name' );
if ( ! empty( $settings['unit_options'] ) ) {
foreach ( $settings['unit_options'] as $value => $label ) {
$options[$value] = $label;
}
}
return apply_filters( 'prefix_unit_options', $options );
}