forked from claudionhangapc/wp-general-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
48 lines (39 loc) · 1.26 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require __DIR__ . '/vendor/autoload.php';
/**
* Plugin Name: WP General Rest API
* Plugin URI: https://example.com/plugins/the-basics/
* Description: Este é um plugin que gera as rotas para obter os dados do site wordpress, permitindo requisições autencticadas usando jwt
* Version: 1.0.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: claudionhangapc
* Author URI: https://author.example.com/
* License: GPL v2 or later
* License URI: https://claudionhangapc/gpl-2.0.html
* Update URI: https://oimark.com.br/
* Text Domain: https://oimark.com.br/
*/
define('GENERAL_REST_API_PLUGIN', __FILE__);
use Plugins\JWT\JWTPlugin;
use Routes\Route;
use Database\DatabaseInstaller;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
/**
* Init api.
*/
function wp_general_rest_api_init()
{
$name_space = $_ENV['API_NAME_SPACE'];
(new Route($name_space) )->init();
add_filter('rest_pre_dispatch', [new JWTPlugin, 'validateTokenRestPreDispatch'], 10, 3);
}
/**
* Add actions
*/
add_action('rest_api_init', 'wp_general_rest_api_init');
/**
* Register hooks.
*/
register_activation_hook(GENERAL_REST_API_PLUGIN, [new DatabaseInstaller, 'install']);