'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- tid() emits an esc_attr()-escaped attribute.
if ( '' !== $title ) {
echo '
' . esc_html( $title ) . '
';
}
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- documented contract: caller passes an escaped fragment.
echo '
';
}
/**
* Coerce a display string, tolerating null.
*
* These parameters used to be strictly `string`, and a null reaching one
* was a TypeError -- which in an admin page render means a white screen
* on a customer's site, raised by a plugin they may not even be looking
* at. That is the one failure mode this kit must never cause: it is
* vendored into every 404ops plugin, so a fatal here is not one broken
* screen but a broken admin.
*
* It is not hypothetical. Nine call sites across three plugins pass
* `get_admin_page_title()` straight in, and core's implementation falls
* through every one of its lookups and returns the unset `$title` global
* when nothing matches. A normal admin request sets that global first, so
* the path is uncommon rather than routine -- but a render helper has no
* business being the thing that kills the page either way.
*
* Null becomes an empty string, and under WP_DEBUG the caller is told,
* the same bargain assert_token() already makes: never break the page,
* never hide the mistake from the developer.
*/
private static function text( ?string $value, string $method ): string {
if ( null !== $value ) {
return $value;
}
if (
defined( 'WP_DEBUG' ) && WP_DEBUG
&& function_exists( '_doing_it_wrong' )
&& ! ( function_exists( 'wp_doing_ajax' ) && wp_doing_ajax() )
&& ! ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() )
) {
_doing_it_wrong(
esc_html( $method ),
'A null display string was passed and rendered as empty. get_admin_page_title() returns null when core cannot resolve a title -- pass a literal fallback.',
'0.5.2'
);
}
return '';
}
/**
* Validate a design token, falling back to a safe default.
*
* The fallback itself is old behaviour and stays — an unknown state has
* always rendered as `neutral`/`info` rather than fatally. What is new
* is that it no longer does so SILENTLY.
*
* Why this exists (404ops-link-sentinel, fixed 2026-08-19): a call site
* passed `'yellow'` to chip(), which accepts only green|amber|red|neutral,
* so every redirect rendered as a grey "no problem here" chip instead of
* amber. It shipped that way for months. phpcs saw string-to-string,
* phpstan agreed, this kit's own test asserts the fallback is correct,
* and the page rendered fine — a WRONG SEVERITY SIGNAL WAS INVISIBLE TO
* EVERY GATE WE OWN. A design language that silently accepts a token it
* does not have is not a design language.
*
* Deliberately narrow about when it speaks up:
* - `WP_DEBUG` only, so production sites never see it;
* - never during AJAX or REST, because `_doing_it_wrong()` prints
* through `trigger_error()` and text emitted ahead of a JSON body
* breaks the client-side parse in a way that looks nothing like its
* cause;
* - `function_exists()` guarded, so the WordPress-free unit suite and
* any standalone use are unaffected.
*
* @param string $value Caller-supplied token.
* @param list