# yatra/3.0.15/app/Ajax/DirectAttributeQuery.php

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.15. 90 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.15/code/app/Ajax/DirectAttributeQuery.php
- Raw: https://pluginprobe.com/plugins/yatra/3.0.15/raw/app/Ajax/DirectAttributeQuery.php
- Modified: 2026-04-14T03:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.15/code/app/Ajax/DirectAttributeQuery.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Yatra\Ajax;

use Yatra\Repositories\AttributeRepository;

/**
 * Attribute Query AJAX Handler (admin fallback when REST cache shape differs).
 */
class DirectAttributeQuery
{
    private AttributeRepository $attributeRepository;

    public function __construct()
    {
        $this->attributeRepository = new AttributeRepository();
        add_action('wp_ajax_yatra_get_attribute_direct', [$this, 'handle']);
    }

    /**
     * Handle AJAX request for attribute data
     */
    public function handle(): void
    {
        if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_admin_nonce')) {
            wp_send_json_error(__('Your session has expired. Please refresh the page and try again.', 'yatra'));
        }

        $attributeId = (int) ($_POST['attribute_id'] ?? 0);

        if ($attributeId <= 0) {
            wp_send_json_error('Invalid attribute ID');
        }

        try {
            $attribute = $this->attributeRepository->find($attributeId);

            if (!$attribute) {
                wp_send_json_error('Attribute not found');
            }

            $row = [
                'id' => (int) $attribute->id,
                'name' => (string) $attribute->name,
                'slug' => (string) $attribute->slug,
                'description' => (string) ($attribute->description ?? ''),
                'status' => (string) ($attribute->status ?? 'draft'),
                'icon' => null,
                'created_at' => $attribute->created_at ?? null,
                'updated_at' => $attribute->updated_at ?? null,
            ];

            if (!empty($attribute->icon)) {
                $iconData = maybe_unserialize($attribute->icon);
                if (is_array($iconData)) {
                    $row['icon'] = $iconData;
                } else {
                    $row['icon'] = [
                        'type' => 'icon',
                        'value' => (string) $attribute->icon,
                    ];
                }
            }

            if (!empty($attribute->metadata)) {
                $metadata = json_decode((string) $attribute->metadata, true);
                if (is_array($metadata)) {
                    $row['field_type'] = $metadata['field_type'] ?? 'text_field';
                    $row['field_options'] = $metadata['field_options'] ?? '';
                    $row['default_value'] = $metadata['default_value'] ?? '';
                    $row['placeholder'] = $metadata['placeholder'] ?? '';
                    $row['required'] = $metadata['required'] ?? false;
                    $row['validation_rules'] = $metadata['validation_rules'] ?? '';
                    $row['display_order'] = isset($metadata['display_order']) ? (int) $metadata['display_order'] : 0;
                    $row['show_on_frontend'] = $metadata['show_on_frontend'] ?? false;
                    $row['show_in_filters'] = $metadata['show_in_filters'] ?? false;
                    $row['filter_type'] = $metadata['filter_type'] ?? 'exact';
                    $row['searchable'] = $metadata['searchable'] ?? false;
                }
            }

            wp_send_json_success($row);
        } catch (\Exception $e) {
            wp_send_json_error('Database query failed: ' . $e->getMessage());
        }
    }
}

```
