feat(widgets): add phase 4 validation and accessibility
This commit is contained in:
1 parent
8da6439675
commit
be1979d378
23 files changed
+8078
-53
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace AKSRT\WidgetSystem;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/** Pure visibility rules shared by rendering and contract tests. */
|
||||
final class WidgetVisibility {
|
||||
public static function should_render(array $instance, ?int $current_id = null, ?bool $singular = null): bool {
|
||||
$type = (string) ($instance['show_id_type'] ?? '');
|
||||
$ids = RendererHelpers::ids((string) ($instance['show_ids'] ?? ''));
|
||||
if ($type === '' || !$ids) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($singular === null) {
|
||||
$singular = function_exists('is_singular') && is_singular();
|
||||
}
|
||||
if ($current_id === null) {
|
||||
$current_id = $singular && function_exists('get_queried_object_id') ? (int) get_queried_object_id() : 0;
|
||||
}
|
||||
$matched = $singular && in_array($current_id, $ids, true);
|
||||
return $type === 'show' ? $matched : !$matched;
|
||||
}
|
||||
|
||||
public static function device_class(array $instance): string {
|
||||
$type = (string) ($instance['show_type'] ?? 'all');
|
||||
if ($type === 'only_pc') {
|
||||
return 'aksrt-widget--only-pc';
|
||||
}
|
||||
return $type === 'only_sm' ? 'aksrt-widget--only-mobile' : '';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user