%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/atv-api/wp-content/themes/atv/inc/
Upload File :
Create Path :
Current File : /var/www/html/atv-api/wp-content/themes/atv/inc/routes.php

<?php

class Routes
{

    public function __construct()
    {
        $this->routes();
    }

    public function response($data)
    {
        wp_reset_postdata();
        header('Content-Type: application/json');
        if (!$data) {
            $data = [];
        }
        wp_send_json($data, 200);
        die();
    }

    public function addAction($name, $cb, $method = "GET")
    {
        add_action('rest_api_init', function () use ($cb, $name, $method) {
            register_rest_route('api/v1', $name, [
                'methods' => $method,
                'callback' => $cb,
            ]);
        });
    }

    public function routes()
    {
        $this->addAction("/sendMail", function (WP_REST_Request $request) {
            $this->response(Mail::index($request));
        }, 'POST');
        $this->addAction("/homepage", function (WP_REST_Request $request) {
            $this->response(Homepage::index($request));
        });
        $this->addAction("/global", function (WP_REST_Request $request) {
            $this->response(GlobalSettings::index($request));
        });
        $this->addAction("/news", function (WP_REST_Request $request) {
            $this->response(News::index($request));
        });
        $this->addAction("/contact", function (WP_REST_Request $request) {
            $this->response(ContactPage::index($request));
        });
    }
}

Zerion Mini Shell 1.0