feat(widgets): add phase 4 validation and accessibility

This commit is contained in:
2026-08-17 19:12:38 +08:00
parent 31e72748c3
commit 009b66326a
23 changed files with 8078 additions and 53 deletions
+4 -16
View File
@@ -9,7 +9,7 @@ defined('ABSPATH') || exit;
*/
final class FrontendRenderer {
public static function render(WidgetDefinition $definition, array $args, array $instance, SchemaWidget $widget): void {
if (!self::is_visible($instance)) {
if (!WidgetVisibility::should_render($instance)) {
return;
}
@@ -24,10 +24,9 @@ final class FrontendRenderer {
AssetManager::enqueue_for($definition);
$classes = ['aksrt-widget', 'aksrt-widget--' . $definition->slug(), 'aksrt-widget--' . $definition->size()];
if (($instance['show_type'] ?? 'all') === 'only_pc') {
$classes[] = 'aksrt-widget--only-pc';
} elseif (($instance['show_type'] ?? 'all') === 'only_sm') {
$classes[] = 'aksrt-widget--only-mobile';
$device_class = WidgetVisibility::device_class($instance);
if ($device_class !== '') {
$classes[] = $device_class;
}
if (!empty($instance['sidebar_affix'])) {
$classes[] = 'aksrt-widget--affix';
@@ -49,17 +48,6 @@ final class FrontendRenderer {
echo (string) ($args['after_widget'] ?? '</section>'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
private static function is_visible(array $instance): bool {
$type = (string) ($instance['show_id_type'] ?? '');
$ids = RendererHelpers::ids((string) ($instance['show_ids'] ?? ''));
if ($type === '' || !$ids) {
return true;
}
$current = function_exists('is_singular') && is_singular() && function_exists('get_queried_object_id') ? (int) get_queried_object_id() : 0;
$matched = in_array($current, $ids, true);
return $type === 'show' ? $matched : !$matched;
}
private static function title(array $instance): string {
$title = trim((string) ($instance['title'] ?? ''));
if ($title === '') {