` for a while and that was one more
* copy of core's markup than anybody needed.
*
* @since 1.4.0
*/
class Notices {
/**
* Render the queued notices for one settings-error group.
*
* @since 1.4.0
*
* @param string $group The `add_settings_error()` slug to render (e.g.
* `albert_settings`, `albert_connections`).
*
* @return void
*/
public static function render( string $group ): void {
// Reads the transient the redirect left behind when `settings-updated`
// is present, exactly as settings_errors() would.
$errors = get_settings_errors( $group );
if ( $errors === [] ) {
return;
}
echo '
';
foreach ( $errors as $error ) {
if ( ! is_array( $error ) || empty( $error['message'] ) ) {
continue;
}
// Core maps its own 'updated' alias onto the success style; do the
// same so a caller can use either spelling.
$type = isset( $error['type'] ) && is_string( $error['type'] ) ? $error['type'] : 'error';
if ( $type === 'updated' ) {
$type = 'success';
}
$code = isset( $error['code'] ) && is_string( $error['code'] ) ? $error['code'] : '';
wp_admin_notice(
'' . esc_html( (string) $error['message'] ) . '',
[
'id' => 'setting-error-' . sanitize_html_class( $code ),
'type' => $type,
'dismissible' => true,
// `inline` is the whole reason this class exists: it is what
// opts the notice out of core's hoist. `settings-error` keeps
// the class settings_errors() would have emitted, so anything
// selecting on it still finds these.
'additional_classes' => [ 'settings-error', 'inline' ],
'paragraph_wrap' => true,
]
);
}
echo '
';
}
}