-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
215 lines (174 loc) · 4.78 KB
/
plugin.php
File metadata and controls
215 lines (174 loc) · 4.78 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/*
Plugin Name: Github Users Info
Plugin URI:
Description: Search Github User Name
Version: 0.1
Author: Tanbir Ahmed
Author URI: http://tanbirahmed.unaux.com/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: github-users-info
Domain Path: /languages
*/
// don't call the file directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Github_Users_Info class
* @class Github_Users_Info The class that holds the entire Github_Users_Info plugin
*/
final class Github_Users_Info {
/**
* Plugin version
* @var string
*/
public $version = '1.0.0';
/**
* Holds various class instances
* @var array
*/
private $container = array();
/**
* Constructor for the Github_Users_Info class
* Sets up all the appropriate hooks and actions
* within our plugin.
*/
public function __construct() {
$this->define_constants();
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
}
/**
* Initializes the Github_Users_Info() class
*
* Checks for an existing Github_Users_Info() instance
* and if it doesn't find one, creates it.
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new Github_Users_Info();
}
return $instance;
}
/**
* Magic getter to bypass referencing plugin.
*
* @param $prop
*
* @return mixed
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
return $this->{$prop};
}
/**
* Magic isset to bypass referencing plugin.
*
* @param $prop
*
* @return mixed
*/
public function __isset( $prop ) {
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
}
/**
* Define the constants
*
* @return void
*/
public function define_constants() {
define( 'GTUI_VERSION', $this->version );
define( 'GTUI_FILE', __FILE__ );
define( 'GTUI_PATH', dirname( GTUI_FILE ) );
define( 'GTUI_INCLUDES', GTUI_PATH . '/includes' );
define( 'GTUI_URL', plugins_url( '', GTUI_FILE ) );
define( 'GTUI_ASSETS', GTUI_URL . '/assets' );
}
/**
* Load the plugin after all plugins are loaded
*
* @return void
*/
public function init_plugin() {
$this->includes();
$this->init_hooks();
}
/**
* Placeholder for activation function
*
* Nothing being called here yet.
*/
public function activate() {
$installed = get_option( 'gtui_installed' );
if ( ! $installed ) {
update_option( 'gtui_installed', time() );
}
update_option( 'gtui_version', GTUI_VERSION );
}
/**
* Placeholder for deactivation function
*
* Nothing being called here yet.
*/
public function deactivate() {
}
/**
* Include the required files
*
* @return void
*/
public function includes() {
require_once GTUI_INCLUDES . '/Assets.php';
if ( $this->is_request( 'admin' ) ) {
require_once GTUI_INCLUDES . '/Admin.php';
}
if ( $this->is_request( 'ajax' ) ) {}
}
/**
* Initialize the hooks
*
* @return void
*/
public function init_hooks() {
add_action( 'init', array( $this, 'init_classes' ) );
// Localize our plugin
add_action( 'init', array( $this, 'localization_setup' ) );
}
/**
* Instantiate the required classes
*
* @return void
*/
public function init_classes() {
if ( $this->is_request( 'admin' ) ) {
$this->container['admin'] = new App\GTUI_Admin();
}
if ( $this->is_request( 'ajax' ) ) {}
$this->container['assets'] = new App\GTUI_Assets();
}
/**
* Initialize plugin for localization
*
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'github-users-info', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
private function is_request( $type ) {
switch ( $type ) {
case 'admin' :
return is_admin();
case 'ajax' :
return defined( 'DOING_AJAX' );
case 'rest' :
return defined( 'REST_REQUEST' );
case 'cron' :
return defined( 'DOING_CRON' );
}
}
} // Github_Users_Info
$github_users_info = Github_Users_Info::init();