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 ' '; 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 ''; } $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 ''; break; case 'multiselect': 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 ' '; 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 ' ' . esc_attr($label) . ''; echo ' '; 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 ' '; 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 ''; break; case 'image_upload': echo '
'; echo '
'; echo ' '; echo ' '; echo '
'; echo '
'; if (!empty($value)) { echo 'Preview'; } 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 ''; } 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 ''; } 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); } ?>

$section_data) : ?>

'; // Render the other three fields in a 3-column grid echo '
'; $tax_keys = ['easy_invoice_tax_entry_method', 'easy_invoice_tax_rate', 'easy_invoice_tax_name']; $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'; $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'; foreach ($tax_keys as $tax_key) { $field_config = $section_data['fields'][$tax_key]; $current_value = $settings[$tax_key] ?? ($field_config['default'] ?? ''); echo '
'; if ($field_config['type'] !== 'checkbox') { echo ''; } switch ($field_config['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 'select': echo ''; break; } if (!empty($field_config['description'])) { echo '

' . esc_html($field_config['description']) . '

'; } echo '
'; } echo '
'; // Allow additional fields to be added to the tax section $additional_tax_fields = apply_filters('easy_invoice_tax_section_additional_fields', [], $settings); if (!empty($additional_tax_fields)) { echo '
'; echo '

' . __('Additional Tax Settings', 'easy-invoice-pro') . '

'; echo '
'; foreach ($additional_tax_fields as $field_key => $field_config) { $current_value = $settings[$field_key] ?? ($field_config['default'] ?? ''); easy_invoice_render_field($field_key, $field_config, $current_value); } echo '
'; echo '
'; } } else { // Use a two-column grid for currency and company settings $is_grid = ($section_id === 'currency' || $section_id === 'company'); // Use a 6-column grid for invoice and quote settings to allow specific field pairing $is_invoice_grid = ($section_id === 'invoice'); $is_quote_grid = ($section_id === 'quote'); // Use a specific grid for advanced settings to improve spacing $is_advanced_grid = ($section_id === 'advanced'); // Use a 3-column grid for text settings $is_text_settings_grid = ($section_id === 'text_settings'); if ($is_grid) echo '
'; if ($is_invoice_grid) echo '
'; if ($is_quote_grid) echo '
'; if ($is_advanced_grid) echo '
'; if ($is_text_settings_grid) echo '
'; foreach ($section_data['fields'] as $option_key => $field_config) { $current_value = $settings[$option_key] ?? ($field_config['default'] ?? ''); $field_id = esc_attr($option_key); $field_type = $field_config['type'] ?? 'text'; $field_label = esc_html($field_config['label'] ?? ''); $field_placeholder = isset($field_config['placeholder']) ? esc_attr($field_config['placeholder']) : ''; $field_description = $field_config['description'] ?? ''; $field_name = 'settings[' . esc_attr($option_key) . ']'; $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'; $col_span_class = esc_attr($field_config['col_span'] ?? 'sm:col-span-6'); $form_group_class = ''; if ($is_grid) { $form_group_class = ''; } elseif ($is_invoice_grid || $is_quote_grid || $is_advanced_grid || $is_text_settings_grid) { $form_group_class = $col_span_class; } else { $form_group_class = $col_span_class; } // Handle conditional display $conditional_class = ''; if (isset($field_config['depends_on']) && is_array($field_config['depends_on'])) { $conditional_class = ' conditional-field'; foreach ($field_config['depends_on'] as $depends_key => $depends_value) { $depends_field_name = 'settings[' . esc_attr($depends_key) . ']'; $conditional_class .= ' depends-on-' . esc_attr($depends_key) . '-' . esc_attr($depends_value); } } echo '
'; if ($field_type !== 'checkbox') { echo ''; } // Define required and aria_describedby variables $required = !empty($field_config['required']) ? 'required' : ''; $aria_describedby = !empty($field_description) ? 'aria-describedby="' . $field_id . '-description"' : ''; switch ($field_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 ''; break; case 'multiselect': echo ''; break; case 'readonly': echo ''; echo ''; break; case 'checkbox': echo '
'; echo ' '; echo ' '; echo '
'; if (!empty($field_description)) { echo '

' . esc_html($field_description) . '

'; } break; case 'image': echo '
'; echo ' '; echo ' ' . esc_attr($field_label) . ''; echo ' '; echo ' '; echo ' '; echo '
'; break; case 'wp_editor': wp_editor( $current_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($field_description)) { echo '

' . esc_html($field_description) . '

'; } 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($current_value) . '%'; break; case 'image_upload': echo '
'; echo '
'; echo ' '; echo ' '; echo '
'; echo '
'; if (!empty($current_value)) { echo 'Preview'; } echo '
'; echo '
'; break; case 'button': $button_text = $field_config['button_text'] ?? $field_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 ''; break; default: echo ''; break; } if ($field_type !== 'checkbox' && $field_type !== 'wp_editor' && !empty($field_description)) { echo '

' . esc_html($field_description) . '

'; } echo '
'; } if ($is_grid) echo '
'; if ($is_invoice_grid) echo '
'; if ($is_quote_grid) echo '
'; if ($is_advanced_grid) echo '
'; if ($is_text_settings_grid) echo '
'; } } ?>