forked from imath/wp-statuses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-statuses.php
244 lines (211 loc) · 4.86 KB
/
wp-statuses.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/*
Plugin Name: WP Statuses
Plugin URI: https://imathi.eu/tag/wp-statuses/
Description: Suggestions to improve the WordPress Post statuses API.
Version: 2.1.9
Requires at least: 5.0
Tested up to: 6.6
License: GNU/GPL 2
Author: imath
Author URI: https://imathi.eu/
Text Domain: wp-statuses
Domain Path: /languages/
GitHub Plugin URI: https://github.com/imath/wp-statuses/
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WP_Statuses' ) ) :
/**
* Main plugin's class
*
* @package WP Statuses
*
* @since 1.0.0
*/
final class WP_Statuses {
/**
* Plugin's main instance
*
* @var object
*/
protected static $instance;
/**
* Used to store dynamic properties.
*
* @var array
*/
private $data = array();
/**
* Initialize the plugin
*
* @since 1.0.0
*/
private function __construct() {
$this->setup_globals();
$this->inc();
$this->setup_hooks();
}
/**
* Magic method for checking the existence of a plugin global variable.
*
* @since 2.1.6
*
* @param string $key Key to check the set status for.
* @return bool
*/
public function __isset( $key ) {
return isset( $this->data[ $key ] );
}
/**
* Magic method for getting a plugin global variable.
*
* @since 2.1.6
*
* @param string $key Key to return the value for.
* @return mixed
*/
public function __get( $key ) {
$retval = null;
if ( isset( $this->data[ $key ] ) ) {
$retval = $this->data[ $key ];
}
return $retval;
}
/**
* Magic method for setting a plugin global variable.
*
* @since 2.1.6
*
* @param string $key Key to set a value for.
* @param mixed $value Value to set.
*/
public function __set( $key, $value ) {
$this->data[ $key ] = $value;
}
/**
* Magic method for unsetting a plugin global variable.
*
* @since 2.1.6
*
* @param string $key Key to unset a value for.
*/
public function __unset( $key ) {
if ( isset( $this->data[ $key ] ) ) {
unset( $this->data[ $key ] );
}
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function start() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Setups plugin's globals
*
* @since 1.0.0
*/
private function setup_globals() {
// Version
$this->version = '2.1.9';
// Domain
$this->domain = 'wp-statuses';
// Base name
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
// Path and URL
$this->dir = plugin_dir_path( $this->file );
$this->url = plugin_dir_url ( $this->file );
$this->js_url = trailingslashit( $this->url . 'js' );
$this->inc_dir = trailingslashit( $this->dir . 'inc' );
}
/**
* Includes plugin's needed files
*
* @since 1.0.0
*/
private function inc() {
spl_autoload_register( array( $this, 'autoload' ) );
require $this->inc_dir . 'core/functions.php';
/**
* Filter here to have a preview about how custom statuses
* are managed by the plugin using:
* add_filter( 'wp_statuses_use_custom_status', '__return_true' );
*
* @since 1.0.0
*
* @param bool $value True to have a demo of the custom status.
* False otherwise.
*/
if ( apply_filters( 'wp_statuses_use_custom_status', false ) ) {
require $this->inc_dir . 'core/custom.php';
}
}
/**
* Setups hooks to register post statuses & load the Administration.
*
* @since 1.0.0
*/
private function setup_hooks() {
add_action( 'init', 'wp_statuses_register_password_protected', 10 );
add_action( 'init', 'wp_statuses_register', 1000 );
add_action( 'change_locale', 'wp_statuses_register', 10 );
// Boot the Admin
if ( is_admin() ) {
add_action( 'plugins_loaded', array( 'WP_Statuses_Admin', 'start' ), 10 );
}
// Load translations
add_action( 'init', array( $this, 'load_textdomain' ), 9 );
}
/**
* Loads the translation files
*
* @since 1.0.0
*/
public function load_textdomain() {
load_plugin_textdomain( $this->domain, false, trailingslashit( basename( $this->dir ) ) . 'languages' );
}
/**
* Class Autoload function
*
* @since 1.0.0
*
* @param string $class The class name.
*/
public function autoload( $class ) {
$name = str_replace( '_', '-', strtolower( $class ) );
if ( false === strpos( $name, $this->domain ) ) {
return;
}
$folder = null;
$parts = explode( '-', $name );
if ( isset( $parts[2] ) ) {
$folder = $parts[2];
}
$path = $this->inc_dir . "{$folder}/classes/class-{$name}.php";
// Sanity check.
if ( ! file_exists( $path ) ) {
return;
}
require $path;
}
}
endif;
/**
* Boot the plugin.
*
* @since 1.0.0
*/
function wp_statuses() {
return WP_Statuses::start();
}
add_action( 'plugins_loaded', 'wp_statuses', 5 );