Used for adding custom fields to the popup editor
PHP
// Example of adding custom fields to the edit form
add_action('kanbanpress_custom_edit_fields', function($post) {
echo '<input type="text" name="custom_field_1" value="' . esc_attr(get_post_meta($post->ID, 'custom_field_1', true)) . '" class="custom-field" placeholder="Custom Field 1" />';
echo '<input type="text" name="custom_field_2" value="' . esc_attr(get_post_meta($post->ID, 'custom_field_2', true)) . '" class="custom-field" placeholder="Custom Field 2" />';
});
// Example of saving custom fields
add_action('kanbanpress_save_custom_fields', function($post_id, $data) {
if (isset($data['custom_field_1'])) {
update_post_meta($post_id, 'custom_field_1', sanitize_text_field($data['custom_field_1']));
}
if (isset($data['custom_field_2'])) {
update_post_meta($post_id, 'custom_field_2', sanitize_text_field($data['custom_field_2']));
}
});
Adding more complex field types
PHP
// Example of adding complex custom fields to the edit form
add_action('kanbanpress_custom_edit_fields', function($post) {
$options = array(
'option1' => 'Option 1',
'option2' => 'Option 2',
'option3' => 'Option 3'
);
$selected_option = get_post_meta($post->ID, 'custom_dropdown', true);
echo '<label for="custom_dropdown">Select Option:</label>';
echo '<select name="custom_dropdown" class="custom-field">';
foreach ($options as $value => $label) {
echo '<option value="' . esc_attr($value) . '" ' . selected($selected_option, $value, false) . '>' . esc_html($label) . '</option>';
}
echo '</select>';
$custom_date = get_post_meta($post->ID, 'custom_date', true);
echo '<label for="custom_date">Select Date:</label>';
echo '<input type="date" name="custom_date" value="' . esc_attr($custom_date) . '" class="custom-field" />';
});
// Example of saving complex custom fields
add_action('kanbanpress_save_custom_fields', function($post_id, $data) {
if (isset($data['custom_dropdown'])) {
update_post_meta($post_id, 'custom_dropdown', sanitize_text_field($data['custom_dropdown']));
}
if (isset($data['custom_date'])) {
update_post_meta($post_id, 'custom_date', sanitize_text_field($data['custom_date']));
}
});