arraypress / wp-status-badge
A lightweight WordPress library for rendering styled status badges
Requires
- php: >=8.3
- arraypress/wp-composer-assets: dev-main
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This library has moved. It is now part of
sugarcommerce/status-badge(namespaceSugarCommerce\StatusBadge, PHP 8.3+). That package's README has a "Moving from arraypress/wp-*" table. This repository is archived and read-only.
Status Badge
Render a coloured pill for a status, without inventing the colours each time.
What it does
Every admin screen ends up showing statuses — completed, pending, failed, refunded — and every plugin picks its own greens and reds for them, so two plugins on one site disagree about what amber means.
This maps a status name to a type, and the type to a badge. completed and
active are successes, pending and on-hold are warnings, failed and
cancelled are dangers. You pass the status you already have; the colour and
icon follow.
Features
- Render a badge from a status name, with no colour decisions to make
- Get sensible defaults for the statuses WordPress and commerce plugins use
- Add your own statuses, or reassign one to a different type
- Ask whether a status is a success, warning, danger or info, for logic elsewhere
- Get a readable label from a machine status, so
on-holdreads as "On hold" - Override the label when the automatic one is not quite right
Installation
composer require arraypress/wp-status-badge
Quick start
In a list-table column:
use ArrayPress\StatusBadge\StatusBadge; $badges = new StatusBadge(); echo $badges->render( $order->status );
completed comes out green, failed red, pending amber — without the
calling code knowing which is which.
Adding a status the defaults do not cover:
$badges = new StatusBadge( [ 'awaiting_stock' => 'warning', ] );
The glyph
A badge is a tint, a dot and the word. Each type also has a glyph, a
Heroicons outline icon (heroicons-outline:check-circle, clock,
x-circle, information-circle, minus-circle), which get_icon()
returns. With arraypress/wp-field-kit installed it is in the markup as
inline SVG with the class arraypress-icon, hidden by the stylesheet; a
stylesheet that wants it shown can show it:
.wp-status-badge .arraypress-icon { display: inline-block; width: 14px; height: 14px; }
The kit is suggested, not required. Without it there is no glyph, and the badge looks the same.
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
arraypress/wp-field-kit(optional), for the glyph
License
GPL-2.0-or-later