|
| 1 | +# Badges |
| 2 | + |
| 3 | +Display upgrade or tier indicators on individual fields or entire sections. Badges render as small inline pills next to labels and section titles. Combine with `disabled` to create a locked preview state for premium features. |
| 4 | + |
| 5 | +## Field Badge |
| 6 | + |
| 7 | +Add a `badge` key to any field config: |
| 8 | + |
| 9 | +```php |
| 10 | +'advanced_sync' => [ |
| 11 | + 'type' => 'toggle', |
| 12 | + 'label' => 'Advanced Sync', |
| 13 | + 'badge' => 'Pro', |
| 14 | + 'disabled' => true, |
| 15 | +], |
| 16 | +``` |
| 17 | + |
| 18 | +The badge appears inline after the field label, between the required asterisk and the tooltip icon. |
| 19 | + |
| 20 | +### Full Config |
| 21 | + |
| 22 | +```php |
| 23 | +'webhook_mode' => [ |
| 24 | + 'type' => 'select', |
| 25 | + 'label' => 'Webhook Mode', |
| 26 | + 'badge' => [ |
| 27 | + 'text' => 'Business', |
| 28 | + 'url' => 'https://example.com/upgrade', |
| 29 | + 'class' => 'setting-fields-badge--gold', |
| 30 | + 'icon' => 'dashicons-lock', |
| 31 | + ], |
| 32 | + 'disabled' => true, |
| 33 | +], |
| 34 | +``` |
| 35 | + |
| 36 | +When `url` is set, the badge renders as a link that opens in a new tab — useful for pointing users to an upgrade page. |
| 37 | + |
| 38 | +## Section Badge |
| 39 | + |
| 40 | +Add a `badge` to a section definition. When combined with `disabled`, all fields in the section are automatically disabled: |
| 41 | + |
| 42 | +```php |
| 43 | +'sections' => [ |
| 44 | + 'advanced' => [ |
| 45 | + 'title' => 'Advanced Settings', |
| 46 | + 'description' => 'These features require a Pro license.', |
| 47 | + 'tab' => 'general', |
| 48 | + 'badge' => [ |
| 49 | + 'text' => 'Pro', |
| 50 | + 'url' => 'https://example.com/upgrade', |
| 51 | + ], |
| 52 | + 'disabled' => true, |
| 53 | + ], |
| 54 | +], |
| 55 | +``` |
| 56 | + |
| 57 | +The section title and badge remain fully visible and clickable (for upgrade links) even when the section's fields are dimmed and disabled. |
| 58 | + |
| 59 | +## Badge Options |
| 60 | + |
| 61 | +| Key | Type | Required | Default | Description | |
| 62 | +|---------|--------|----------|---------|------------------------------------------------| |
| 63 | +| `text` | string | Yes | — | Badge label | |
| 64 | +| `url` | string | No | `''` | Links badge to upgrade page (opens new tab) | |
| 65 | +| `class` | string | No | `''` | Additional CSS class for styling | |
| 66 | +| `icon` | string | No | `''` | Dashicon class (e.g., `dashicons-lock`) | |
| 67 | + |
| 68 | +If `badge` is a string (e.g., `'Pro'`), it's treated as `['text' => 'Pro']`. |
| 69 | + |
| 70 | +## Built-in Color Variants |
| 71 | + |
| 72 | +Use the `class` key to apply a color variant: |
| 73 | + |
| 74 | +| Class | Colors | |
| 75 | +|----------------------------------|----------------| |
| 76 | +| *(default — no class)* | Neutral grey | |
| 77 | +| `setting-fields-badge--pro` | Amber/orange | |
| 78 | +| `setting-fields-badge--premium` | Purple | |
| 79 | +| `setting-fields-badge--business` | Green | |
| 80 | +| `setting-fields-badge--gold` | Gold/yellow | |
| 81 | + |
| 82 | +```php |
| 83 | +'badge' => [ |
| 84 | + 'text' => 'Premium', |
| 85 | + 'class' => 'setting-fields-badge--premium', |
| 86 | + 'url' => 'https://example.com/upgrade', |
| 87 | +], |
| 88 | +``` |
| 89 | + |
| 90 | +Linked badges change to a solid color on hover. |
| 91 | + |
| 92 | +## Disabled Cascade |
| 93 | + |
| 94 | +When a section has `'disabled' => true`, all child fields inherit the disabled state automatically. You don't need to set `disabled` on each field individually. The section's form table is dimmed with reduced opacity while the section header remains fully interactive. |
| 95 | + |
| 96 | +## Dynamic Badges |
| 97 | + |
| 98 | +You can conditionally add badges based on license status or feature flags: |
| 99 | + |
| 100 | +```php |
| 101 | +$is_pro = is_setting_field_license_active( 'my_plugin', 'license' ); |
| 102 | + |
| 103 | +'advanced_sync' => [ |
| 104 | + 'type' => 'toggle', |
| 105 | + 'label' => 'Advanced Sync', |
| 106 | + 'badge' => $is_pro ? '' : [ |
| 107 | + 'text' => 'Pro', |
| 108 | + 'url' => 'https://example.com/upgrade', |
| 109 | + ], |
| 110 | + 'disabled' => ! $is_pro, |
| 111 | +], |
| 112 | +``` |
| 113 | + |
| 114 | +When the license is active, the badge disappears and the field becomes editable. |
0 commit comments