Admin System
Jankx Theme's Admin System provides comprehensive tools for theme management, options handling, and form processing.
Form Handler
The FormHandler class processes admin form submissions with built-in security checks.
use Jankx\Admin\Handlers\FormHandler;
use Jankx\Foundation\Application;
$app = Application::getInstance();
$formHandler = new FormHandler($app);
// Process requests (usually called on admin_init)
add_action('admin_init', [$formHandler, 'handleRequests']);
Built-in Actions
| Action | Description | Capability |
|---|---|---|
save_image_sizes | Save image size settings | manage_options |
clear_debug_log | Clear debug log file | manage_options |
activate_license | Activate license key PRO | manage_options |
deactivate_license | Deactivate license PRO | manage_options |
Custom Actions
// Register custom action handler
add_action('jankx/form/handle/{action}', function($data, $formHandler) {
// Handle custom action
update_option('my_custom_option', $data['value']);
// Add success notice
$formHandler->addAdminNotice('Settings saved successfully!', 'success');
}, 10, 2);
Admin Notices
Display feedback messages to admin users.
// Add a notice
$formHandler->addAdminNotice('Settings saved!', 'success');
$formHandler->addAdminNotice('Please check your input', 'warning');
$formHandler->addAdminNotice('An error occurred', 'error');
$formHandler->addAdminNotice('For your information', 'info');
Notice Types
| Type | Color | Use Case |
|---|---|---|
success | Green | Operation successful |
warning | Yellow | Attention needed |
error | Red | Operation failed |
info | Blue | Informational |
Theme Options
Options Service
class ThemeOptionsService
{
protected $options = [];
public function get(string $key, $default = null)
{
return $this->options[$key] ?? $default;
}
public function set(string $key, $value): void
{
$this->options[$key] = $value;
update_option('jankx_options', $this->options);
}
}
Font Manager PRO
use Jankx\Facades\Fonts;
// Add custom font
Fonts::add([
'name' => 'Custom Font',
'family' => 'Custom, sans-serif',
'category' => 'custom',
]);
// Get active fonts
$fonts = Fonts::getActive();
// Apply font to element
Fonts::apply('#header', 'Custom Font');
Icon Manager PRO
use Jankx\Facades\Icons;
// Get icons by type
$icons = Icons::get('fontawesome');
// Get all available icon sets
$sets = Icons::getSets();
// Render icon
Icons::render('star', ['class' => 'text-primary']);
Security
Nonce Verification
// Generate nonce
$nonce = wp_create_nonce('my_action');
// Verify in handler
if (!wp_verify_nonce($_POST['_wpnonce'] ?? '', 'my_action')) {
wp_die('Security check failed');
}
Capability Checks
// Check user capabilities
if (!current_user_can('manage_options')) {
wp_die('You do not have permission');
}
Data Sanitization
// FormHandler provides built-in sanitization
$data = $this->sanitizeRequestData($_POST);
// Manual sanitization
$clean = [
'text' => sanitize_text_field($input['text']),
'email' => sanitize_email($input['email']),
'url' => esc_url_raw($input['url']),
'html' => wp_kses_post($input['html']),
];
Best Practices
- Always Verify Nonces - Use
wp_verify_nonce()for form submissions - Check Capabilities - Verify user has proper permissions
- Validate Input - Sanitize all user input
- Escape Output - Use
esc_html(),esc_url(),esc_attr() - Use Admin Notices - Provide feedback for user actions