-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.php
More file actions
201 lines (173 loc) · 4.9 KB
/
plugin.php
File metadata and controls
201 lines (173 loc) · 4.9 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
<?php
namespace DropHtml;
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
/**
* Main class plugin
*/
class Plugin {
/**
* Current plugin object.
*
* @since 1.0.0
*
* @var object
*/
public static $instance = null;
public $data = array();
/** Magic Methods *********************************************************/
/**
* A dummy constructor to prevent Qazana from being loaded more than once.
*
* @since 1.0.0
* @see drophtml::instance()
* @see drophtml();
*/
private function __construct() {}
/**
* A dummy magic method to prevent Qazana from being cloned.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'drophtml' ), DROPHTML__VERSION);
}
/**
* A dummy magic method to prevent Qazana from being unserialized.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'drophtml' ), DROPHTML__VERSION);
}
/**
* Magic method for checking the existence of a certain custom field.
*
* @since 1.0.0
*/
public function __isset( $key ) {
return isset( $this->data[ $key ] );
}
/**
* Magic method for getting Qazana variables.
*
* @since 1.0.0
*/
public function __get( $key ) {
return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
}
/**
* Magic method for setting Qazana variables.
*
* @since 1.0.0
*/
public function __set( $key, $value ) {
$this->data[ $key ] = $value;
}
/**
* Magic method for unsetting Qazana variables.
*
* @since 1.0.0
*/
public function __unset( $key ) {
if ( isset( $this->data[ $key ] ) ) {
unset( $this->data[ $key ] );
}
}
/**
* Magic method to prevent notices and errors from invalid method calls.
*
* @since 1.0.0
*/
public function __call( $name = '', $args = [] ) {
unset( $name, $args );
}
/** Private Methods *******************************************************/
/**
* Set some smart defaults to class variables. Allow some of them to be
* filtered to allow for early overriding.
*
* @since 1.0.0
*
* @uses plugin_dir_path() To generate Qazana plugin path
* @uses plugin_dir_url() To generate Qazana plugin url
* @uses apply_filters() Calls various filters
*/
private function setup_globals() {
/* Versions **********************************************************/
$this->db_version = '102'; // Bumped up on api changes that need a db update for compatibility
/* Paths *************************************************************/
// Setup some base path and URL information
$this->file = DROPHTML__FILE__;
$this->slug = 'wp-drophtml';
$this->basename = apply_filters( 'drophtml_plugin_basename', plugin_basename( $this->file ) );
$this->plugin_dir = apply_filters( 'drophtml_plugin_dir_path', plugin_dir_path( $this->file ) );
$this->plugin_url = apply_filters( 'drophtml_plugin_dir_url', plugins_url( '/', $this->file ) );
// Includes
$this->includes_dir = apply_filters( 'drophtml_includes_dir', trailingslashit( $this->plugin_dir . 'includes' ) );
$this->includes_url = apply_filters( 'drophtml_includes_url', trailingslashit( $this->plugin_url . 'includes' ) );
}
private function includes() {
require_once $this->includes_dir . 'post-types/contentsView.php';
require_once $this->includes_dir . 'post-types/upload.php';
require_once $this->includes_dir . 'post-types/drop.php';
}
/**
* Activation Actions
*
* @since 1.0.0
*/
public function activation()
{
flush_rewrite_rules();
}
/**
* Deactivation Actions
*
* @since 1.0.0
*/
public function deactivation()
{
flush_rewrite_rules();
}
/**
* Constructor. Hooks all interactions into correct areas to start
* the class.
*
* @since 1.0.0
*/
public function setup_init_actions()
{
// Add actions to plugin activation and deactivation hooks
add_action('activate_' . $this->basename, [$this, 'activation']);
add_action('deactivate_' . $this->basename, [$this, 'deactivation']);
}
/**
* Getter method for retrieving the object instance.
*
* @since 1.0.0
*/
static public function instance() {
// Store the instance locally to avoid private static replication
static $instance = null;
// Only run these methods if they haven't been ran previously
if ( null === $instance ) {
$instance = new self();
$instance->setup_globals();
$instance->includes();
$instance->init_classes();
$instance->setup_init_actions();
}
// Always return the instance
return $instance;
}
/**
* Loads the plugin classes.
*
* @since 1.0.0
*/
public function init_classes() {
new Admin\Upload();
}
}