|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Main Class |
|
4
|
|
|
* |
|
5
|
|
|
* @package SimpleCalendar |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace SimpleCalendar; |
|
8
|
|
|
|
|
9
|
|
|
use SimpleCalendar\Admin\License_Manager; |
|
10
|
|
|
|
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
12
|
|
|
exit; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Simple Calendar plugin. |
|
17
|
|
|
*/ |
|
18
|
|
|
final class Plugin { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Plugin name. |
|
22
|
|
|
* |
|
23
|
|
|
* @access public |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
public static $name = 'Simple Calendar'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Plugin version. |
|
30
|
|
|
* |
|
31
|
|
|
* @access public |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
public static $version = SIMPLE_CALENDAR_VERSION; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Plugin homepage. |
|
38
|
|
|
* |
|
39
|
|
|
* @access public |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected static $homepage = 'https://simplecalendar.io'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Locale. |
|
46
|
|
|
* |
|
47
|
|
|
* @access public |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
public $locale = 'en_US'; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Objects factory. |
|
54
|
|
|
* |
|
55
|
|
|
* @access public |
|
56
|
|
|
* @var Objects |
|
57
|
|
|
*/ |
|
58
|
|
|
public $objects = null; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* The single instance of this class. |
|
62
|
|
|
* |
|
63
|
|
|
* @access protected |
|
64
|
|
|
* @var Plugin |
|
65
|
|
|
*/ |
|
66
|
|
|
protected static $_instance = null; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the plugin instance. |
|
70
|
|
|
* |
|
71
|
|
|
* @return Plugin |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function get_instance() { |
|
74
|
|
|
if ( is_null( self::$_instance ) ) { |
|
75
|
|
|
self::$_instance = new self(); |
|
76
|
|
|
} |
|
77
|
|
|
return self::$_instance; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Cloning is forbidden. |
|
82
|
|
|
*/ |
|
83
|
|
|
public function __clone() { |
|
84
|
|
|
_doing_it_wrong( __FUNCTION__, 'Cloning the main instance of this plugin is forbidden.', '1.0.0' ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Unserializing instances of this class is forbidden. |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __wakeup() { |
|
91
|
|
|
_doing_it_wrong( __FUNCTION__, 'Unserializing instances of this plugin is forbidden.', '1.0.0' ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Plugin constructor. |
|
96
|
|
|
* |
|
97
|
|
|
* @final |
|
98
|
|
|
*/ |
|
99
|
|
|
public function __construct() { |
|
100
|
|
|
|
|
101
|
|
|
// Load plugin. |
|
102
|
|
|
require_once 'autoload.php'; |
|
103
|
|
|
$this->locale = apply_filters( 'plugin_locale', get_locale(), 'google-calendar-events' ); |
|
104
|
|
|
$this->load(); |
|
105
|
|
|
|
|
106
|
|
|
// Installation hooks. |
|
107
|
|
|
register_activation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'activate' ) ); |
|
108
|
|
|
register_deactivation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'deactivate' ) ); |
|
109
|
|
|
|
|
110
|
|
|
// Do update call here. |
|
111
|
|
|
add_action( 'admin_init', array( $this, 'update' ), 999 ); |
|
112
|
|
|
|
|
113
|
|
|
// Init hooks. |
|
114
|
|
|
add_action( 'init', array( $this, 'init' ), 5 ); |
|
115
|
|
|
add_action( 'admin_init', array( $this, 'register_settings' ), 5 ); |
|
116
|
|
|
|
|
117
|
|
|
// Upon plugin loaded action hook. |
|
118
|
|
|
do_action( 'simcal_loaded' ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Load plugin. |
|
123
|
|
|
* |
|
124
|
|
|
* @since 3.0.0 |
|
125
|
|
|
*/ |
|
126
|
|
|
public function load() { |
|
127
|
|
|
|
|
128
|
|
|
// Functions shared in both back end and front end. |
|
129
|
|
|
include_once 'functions/shared.php'; |
|
130
|
|
|
|
|
131
|
|
|
// Init custom post types and taxonomies. |
|
132
|
|
|
new Post_Types(); |
|
133
|
|
|
|
|
134
|
|
|
// Load back end. |
|
135
|
|
|
if ( is_admin() ) { |
|
136
|
|
|
$this->load_admin(); |
|
137
|
|
|
} else { |
|
138
|
|
|
// Load front end scripts and styles. |
|
139
|
|
|
new Assets(); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
// Front facing ajax callbacks. |
|
143
|
|
|
new Ajax(); |
|
144
|
|
|
|
|
145
|
|
|
// Add Shortcodes. |
|
146
|
|
|
new Shortcodes(); |
|
147
|
|
|
|
|
148
|
|
|
// Add Widgets. |
|
149
|
|
|
new Widgets(); |
|
150
|
|
|
|
|
151
|
|
|
// Deprecated functions for backwards compatibility. |
|
152
|
|
|
include_once 'functions/deprecated.php'; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Load plugin admin. |
|
157
|
|
|
* |
|
158
|
|
|
* @since 3.0.0 |
|
159
|
|
|
*/ |
|
160
|
|
|
public function load_admin() { |
|
161
|
|
|
|
|
162
|
|
|
// Back end only functions. |
|
163
|
|
|
include_once 'functions/admin.php'; |
|
164
|
|
|
|
|
165
|
|
|
// Display admin notices. |
|
166
|
|
|
new Admin\Notices(); |
|
167
|
|
|
|
|
168
|
|
|
// Load back end scripts and styles. |
|
169
|
|
|
new Admin\Assets(); |
|
170
|
|
|
|
|
171
|
|
|
// Custom content handling. |
|
172
|
|
|
new Admin\Post_Types(); |
|
173
|
|
|
|
|
174
|
|
|
// Init menus and settings. |
|
175
|
|
|
new Admin\Menus(); |
|
176
|
|
|
|
|
177
|
|
|
if ( defined( 'DOING_AJAX' ) ) { |
|
178
|
|
|
// Admin ajax callbacks. |
|
179
|
|
|
new Admin\Ajax(); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Init plugin when WordPress initializes. |
|
185
|
|
|
* |
|
186
|
|
|
* @since 3.0.0 |
|
187
|
|
|
*/ |
|
188
|
|
|
public function init() { |
|
189
|
|
|
|
|
190
|
|
|
// Before init action hook. |
|
191
|
|
|
do_action( 'before_simcal_init' ); |
|
192
|
|
|
|
|
193
|
|
|
// Set up localization. |
|
194
|
|
|
load_plugin_textdomain( 'google-calendar-events', false, dirname( plugin_basename( SIMPLE_CALENDAR_MAIN_FILE ) ) . '/i18n/' ); |
|
195
|
|
|
|
|
196
|
|
|
// Init objects factory. |
|
197
|
|
|
$this->objects = new Objects(); |
|
198
|
|
|
|
|
199
|
|
|
// Upon init action hook. |
|
200
|
|
|
do_action( 'simcal_init' ); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Register plugin settings. |
|
205
|
|
|
* |
|
206
|
|
|
* @since 3.0.0 |
|
207
|
|
|
*/ |
|
208
|
|
|
public function register_settings() { |
|
209
|
|
|
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
210
|
|
|
$settings = new Admin\Pages(); |
|
211
|
|
|
$settings->register_settings( $settings->get_settings() ); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Get Ajax URL. |
|
217
|
|
|
* |
|
218
|
|
|
* @since 3.0.0 |
|
219
|
|
|
* |
|
220
|
|
|
* @return string |
|
221
|
|
|
*/ |
|
222
|
|
|
public function ajax_url() { |
|
223
|
|
|
return admin_url( 'admin-ajax.php', 'relative' ); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Get URL. |
|
228
|
|
|
* |
|
229
|
|
|
* @since 3.0.0 |
|
230
|
|
|
* |
|
231
|
|
|
* @param string $case Requested url. |
|
232
|
|
|
* |
|
233
|
|
|
* @return string |
|
234
|
|
|
*/ |
|
235
|
|
|
public function get_url( $case ) { |
|
236
|
|
|
switch ( $case ) { |
|
237
|
|
|
case 'codex' : |
|
238
|
|
|
case 'apidocs' : |
|
239
|
|
|
return 'http://codex.simplecalendar.io'; |
|
240
|
|
|
case 'add-ons' : |
|
241
|
|
|
return self::$homepage . '/addons/'; |
|
242
|
|
|
case 'gcal-pro' : |
|
243
|
|
|
return self::$homepage . '/addons/google-calendar-pro/'; |
|
244
|
|
|
case 'docs' : |
|
245
|
|
|
return 'http://docs.simplecalendar.io'; |
|
246
|
|
|
case 'github' : |
|
247
|
|
|
return 'https://github.com/moonstonemedia/Simple-Calendar'; |
|
248
|
|
|
case 'support' : |
|
249
|
|
|
return 'https://wordpress.org/support/plugin/google-calendar-events'; |
|
250
|
|
|
case 'gdev-console': |
|
251
|
|
|
return 'https://console.developers.google.com'; |
|
252
|
|
|
case 'home' : |
|
253
|
|
|
default : |
|
254
|
|
|
return self::$homepage; |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Run upgrade scripts. |
|
260
|
|
|
* |
|
261
|
|
|
* @since 3.0.0 |
|
262
|
|
|
*/ |
|
263
|
|
|
public static function update() { |
|
264
|
|
|
$update = new Update( SIMPLE_CALENDAR_VERSION ); |
|
|
|
|
|
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Simple Calendar. |
|
271
|
|
|
* |
|
272
|
|
|
* @return Plugin |
|
273
|
|
|
*/ |
|
274
|
|
|
function plugin() { |
|
275
|
|
|
return Plugin::get_instance(); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
plugin(); |
|
279
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.