-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapison.php
More file actions
91 lines (75 loc) · 2.14 KB
/
apison.php
File metadata and controls
91 lines (75 loc) · 2.14 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Plugin Name: Apison
* Plugin URI: https://github.com/lambry/apison/
* Description: A little plugin to fetch, cache and access API data (JSON).
* Version: 0.2.1
* Author: Lambry
* Author URI: https://lambry.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: apison
* Domain Path: /languages
*/
namespace Lambry\Apison;
defined('ABSPATH') || exit;
require_once 'includes/helpers.php';
define('APISON_VERSION', '0.2.1');
define('APISON_KEY', 'apison');
define('APISON_URL', plugin_dir_url(__FILE__) . 'includes/');
define('APISON_PATH', plugin_dir_path(__FILE__) . 'includes/');
class Init
{
use Helpers;
/**
* Define constants, add get started
*/
public function __construct()
{
$this->bootstrap();
}
/**
* Include all autoloaded files and register actions
*
* @access public
* @return void
*/
public function bootstrap() : void
{
$includes = require_once 'autoload.php';
$this->include($includes['shared']);
if (is_admin()) {
$this->include($includes['admin']);
add_action('init', [$this->instantiate('Admin\Settings'), 'init']);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'links']);
} else {
$this->include($includes['frontend']);
add_action('rest_api_init', [$this->instantiate('Frontend\Endpoint'), 'init']);
}
add_action('plugins_loaded', [$this, 'languages']);
}
/**
* Load languages textdomain
*
* @access public
* @return void
*/
public function languages() : void
{
load_plugin_textdomain(APISON_KEY, false, basename(dirname(__FILE__)) . '/languages');
}
/**
* Add action links to plugins page
*
* @access public
* @param array $links
* @return array $links
*/
public function links(array $links) : array
{
return array_merge([
'<a href="' . admin_url('options-general.php?page=apison') . '">' . __('Settings', 'apison') . '</a>',
], $links);
}
}
new Init();