revert 8cad3c2d3d
revert Merge pull request 'feat(widgets): add phase 4 validation and accessibility' (#6) from worktree/widgets-phase-4 into main Reviewed-on: #6
This commit is contained in:
@@ -9,7 +9,7 @@ defined('ABSPATH') || exit;
|
||||
*/
|
||||
final class FrontendRenderer {
|
||||
public static function render(WidgetDefinition $definition, array $args, array $instance, SchemaWidget $widget): void {
|
||||
if (!WidgetVisibility::should_render($instance)) {
|
||||
if (!self::is_visible($instance)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ final class FrontendRenderer {
|
||||
|
||||
AssetManager::enqueue_for($definition);
|
||||
$classes = ['aksrt-widget', 'aksrt-widget--' . $definition->slug(), 'aksrt-widget--' . $definition->size()];
|
||||
$device_class = WidgetVisibility::device_class($instance);
|
||||
if ($device_class !== '') {
|
||||
$classes[] = $device_class;
|
||||
if (($instance['show_type'] ?? 'all') === 'only_pc') {
|
||||
$classes[] = 'aksrt-widget--only-pc';
|
||||
} elseif (($instance['show_type'] ?? 'all') === 'only_sm') {
|
||||
$classes[] = 'aksrt-widget--only-mobile';
|
||||
}
|
||||
if (!empty($instance['sidebar_affix'])) {
|
||||
$classes[] = 'aksrt-widget--affix';
|
||||
@@ -48,6 +49,17 @@ 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 === '') {
|
||||
|
||||
Reference in New Issue
Block a user