';
$close = '';
$paths = '';
switch ($section_id) {
case 'company':
// House icon — represents the business / company.
$paths = ' '
. ' ';
break;
case 'invoice':
// Document with $ inside — distinct from the quote icon.
$paths = ' '
. ' '
. ' '
. ' ';
break;
case 'quote':
// Document with checkmark — proposal / awaiting approval.
$paths = ' '
. ' '
. ' ';
break;
case 'currency':
// Dollar-sign-in-circle.
$paths = ' '
. ' '
. ' ';
break;
case 'tax':
// Percent symbol — clean tax glyph.
$paths = ' '
. ' '
. ' ';
break;
case 'payment':
// Card with horizontal stripe.
$paths = ' '
. ' ';
break;
case 'email':
// Envelope with flap.
$paths = ' '
. ' ';
break;
case 'text_settings':
// Document with text lines + edit-arrow indicator.
$paths = ' '
. ' '
. ' '
. ' '
. ' '
. ' ';
break;
case 'account':
// User in circle — distinct from the gear used elsewhere.
$paths = ' '
. ' '
. ' ';
break;
case 'advanced':
default:
// Gear icon — used by Advanced + as the fallback for any
// section that didn't ship a case here.
$paths = ' '
. ' ';
break;
}
echo $open . $paths . $close;
}
}
/**
* Helper function to render a single settings field.
*
* @param string $option_key The option key.
* @param array $field_config The field configuration.
* @param mixed $current_value The current value of the field.
*/
function easy_invoice_render_field($option_key, $field_config, $current_value) {
$label = esc_html($field_config['label'] ?? '');
$type = $field_config['type'] ?? 'text';
$default = $field_config['default'] ?? '';
$value = $current_value ?? $default;
$description_text = $field_config['description'] ?? '';
$field_id = esc_attr($option_key);
$field_name = 'settings[' . esc_attr($option_key) . ']';
$col_span_class = esc_attr($field_config['col_span'] ?? 'sm:col-span-6');
$placeholder = isset($field_config['placeholder']) ? esc_attr($field_config['placeholder']) : '';
$required = !empty($field_config['required']) ? 'required' : '';
$aria_describedby = !empty($description_text) ? 'aria-describedby="' . $field_id . '-description"' : '';
echo '
'; // Added 'form-group' class for JS show/hide functionality
// Special layout for checkboxes with descriptions (e.g., Invoice Numbering type)
if ($type === 'checkbox' && !empty($description_text) && ($option_key === 'easy_invoice_invoice_numbering')) {
echo '
';
echo '
';
echo ' ';
echo '
';
echo '
';
echo '
' . $label . ' ';
echo '
' . wp_kses($description_text, array(
'a' => array(
'href' => array(),
'target' => array(),
'class' => array()
)
)) . '
';
echo '
';
echo '
';
} else {
// Standard label for other types, or checkboxes without the special description structure
if ($type !== 'checkbox') {
echo '
' . $label . ' ';
}
$input_class = 'mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm';
$select_class = 'mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md';
switch ($type) {
case 'text':
case 'email':
case 'url':
case 'tel':
echo '
';
break;
case 'number':
$min = isset($field_config['min']) ? ' min="' . esc_attr($field_config['min']) . '"' : '';
$max = isset($field_config['max']) ? ' max="' . esc_attr($field_config['max']) . '"' : '';
$step = isset($field_config['step']) ? ' step="' . esc_attr($field_config['step']) . '"' : '';
echo '
';
break;
case 'textarea':
echo '
';
break;
case 'select':
echo '
';
if (!empty($field_config['options']) && is_array($field_config['options'])) {
foreach ($field_config['options'] as $opt_val => $opt_label) {
echo '' . esc_html($opt_label) . ' ';
}
}
echo ' ';
break;
case 'multiselect':
echo '
';
if (!empty($field_config['options']) && is_array($field_config['options'])) {
foreach ($field_config['options'] as $opt_val => $opt_label) {
$selected = is_array($value) && in_array($opt_val, $value) ? 'selected="selected"' : '';
echo '' . esc_html($opt_label) . ' ';
}
}
echo ' ';
break;
case 'readonly':
echo '
';
echo '
';
break;
case 'checkbox': // Checkboxes that don't use the special description layout
echo '
'; // Original 'tax_enabled' was just this simple structure
echo ' ';
echo ' ' . $label . ' ';
echo '
';
if (!empty($description_text)) { // Show description below the field
echo '
' . wp_kses($description_text, array(
'a' => array(
'href' => array(),
'target' => array(),
'class' => array()
)
)) . '
';
}
break;
case 'image':
echo '
';
echo '
';
echo ' ';
echo ' ';
echo '
';
echo esc_html__('Change', 'easy-invoice');
echo ' ';
echo '
';
echo '
';
break;
case 'wp_editor':
// For wp_editor, the label is usually handled before calling it.
// The col_span div wraps this.
wp_editor( $value, $field_id, ['textarea_name' => $field_name, 'teeny' => true, 'media_buttons' => false, 'textarea_rows' => 7, 'editor_class' => 'mt-1'] );
// Handle description for wp_editor specifically
if (!empty($description_text)) {
echo '
' . wp_kses($description_text, array(
'a' => array(
'href' => array(),
'target' => array(),
'class' => array()
)
)) . '
';
}
break;
case 'test_email':
echo '
';
echo '
';
echo ' ';
echo ' ';
echo ' ';
echo ' ' . esc_html__('Send Test Email', 'easy-invoice');
echo ' ';
echo '
';
echo '
';
echo '
';
break;
case 'color':
echo '
';
break;
case 'range':
$min = isset($field_config['min']) ? ' min="' . esc_attr($field_config['min']) . '"' : '';
$max = isset($field_config['max']) ? ' max="' . esc_attr($field_config['max']) . '"' : '';
$step = isset($field_config['step']) ? ' step="' . esc_attr($field_config['step']) . '"' : '';
echo '
';
echo '
' . esc_html($value) . '% ';
break;
case 'button':
$button_text = $field_config['button_text'] ?? $label;
$button_class = $field_config['button_class'] ?? 'button button-secondary';
$button_class_name = 'regenerate-invoice-numbers-button';
if ($option_key === 'easy_invoice_regenerate_quote_numbers') {
$button_class_name = 'regenerate-quote-numbers-button';
}
echo '
';
echo esc_html($button_text);
echo ' ';
break;
case 'image_upload':
echo '
';
echo '
';
echo ' ';
echo ' ';
echo esc_html__('Upload Image', 'easy-invoice');
echo ' ';
echo '
';
echo '
';
if (!empty($value)) {
echo '
';
}
echo '
';
echo '
';
break;
default:
// Special handling for regenerate invoice numbers button
if ($option_key === 'easy_invoice_regenerate_invoice_numbers') {
$button_text = $field_config['button_text'] ?? $label;
$button_class = $field_config['button_class'] ?? 'button button-secondary';
echo '
';
echo esc_html($button_text);
echo ' ';
} elseif ($option_key === 'easy_invoice_regenerate_quote_numbers') {
$button_text = $field_config['button_text'] ?? $label;
$button_class = $field_config['button_class'] ?? 'button button-secondary';
echo '
';
echo esc_html($button_text);
echo ' ';
} else {
echo '
';
}
break;
}
// General description for non-checkbox and non-wp_editor fields (if it exists and not handled by special layouts)
if ($type !== 'checkbox' && $type !== 'wp_editor' && !empty($description_text)) {
echo '
' . wp_kses($description_text, array(
'a' => array(
'href' => array(),
'target' => array(),
'class' => array()
)
)) . '
';
}
}
echo '
'; // End col_span div
}
/**
* Filter settings config to allow extensions to modify it
* Note: This filter is already applied in the controller, so this is redundant
*/
// $settings_config = apply_filters('easy_invoice_settings_fields_config', $settings_config);
$active_section = $_GET['section'] ?? key($settings_config);
if (!isset($settings_config[$active_section])) {
$active_section = key($settings_config);
}
?>