id, 'easy-invoice') !== false) {
// Remove all WordPress admin styles
global $wp_styles;
$styles_to_remove = [
'wp-admin', 'admin-bar', 'colors', 'ie', 'common', 'forms', 'admin-menu',
'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about',
'nav-menus', 'widgets', 'site-icon', 'l10n', 'code-editor', 'wp-auth-check',
'dashicons', 'wp-pointer', 'buttons', 'wp-jquery-ui-dialog', 'wp-color-picker',
'wp-components', 'wp-edit-post', 'wp-format-library', 'wp-block-library',
'wp-block-library-theme', 'wp-nux', 'wp-reusable-blocks', 'wp-editor',
'wp-edit-blocks', 'wp-block-editor',
];
$styles_to_remove = array_unique($styles_to_remove); // Ensure no duplicates
foreach ($styles_to_remove as $style) {
if (isset($wp_styles->registered[$style])) {
wp_dequeue_style($style);
wp_deregister_style($style);
}
}
add_filter('show_admin_bar', '__return_false');
// Add custom CSS to hide screen-meta-links
echo '';
}
}
add_action('admin_enqueue_scripts', 'easy_invoice_dequeue_admin_styles', 9999);
/**
* 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
*/
$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);
}
?>