-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp-timetable.php
executable file
·296 lines (243 loc) · 6.44 KB
/
mp-timetable.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/**
* Plugin Name: Timetable and Event Schedule
* Plugin URI: https://motopress.com/products/timetable-event-schedule/
* Description: Smart time-management tool with a clean minimalist design for featuring your timetables and upcoming events.
* Version: 2.4.14
* Author: MotoPress
* Author URI: https://motopress.com
* License: GPLv2 or later
* Text Domain: mp-timetable
* Domain Path: /languages
*/
/*
* This plugin contains hooks that allow you to edit, add and move content without the need to edit template files.
* This method protects against upgrade issues. There are several actions and filters you can use to modify content output.
* You can check \mp-timetable\classes\class-hooks.php for the list of hooks.
*
* Alternatively in "Developer Mode", you can copy template files from '/mp-timetable/templates/' folder to '/your-theme/mp-timetable/' to override them.
*
* The Timetable plugin also supports default WordPress templates hierarchy:
* https://developer.wordpress.org/themes/basics/template-hierarchy/#visual-overview
*/
defined( 'ABSPATH' ) || exit;
use mp_timetable\plugin_core\classes\Core;
if ( ! defined( 'MP_TT_DEBUG' ) ) {
define( 'MP_TT_DEBUG', false );
}
if ( ! defined( 'MP_TT_PLUGIN_FILE' ) ) {
define( 'MP_TT_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'MP_TT_PLUGIN_BASENAME' ) ) {
define( 'MP_TT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}
register_activation_hook( __FILE__, array( Mp_Time_Table::init(), 'on_activation' ) );
register_deactivation_hook( __FILE__, array( 'Mp_Time_Table', 'on_deactivation' ) );
register_uninstall_hook( __FILE__, array( 'Mp_Time_Table', 'on_uninstall' ) );
add_action( 'plugins_loaded', array( 'Mp_Time_Table', 'init' ) );
if ( version_compare( get_bloginfo( 'version' ), '5.1', '>=' ) ) {
add_action( 'wp_insert_site', array( 'Mp_Time_Table', 'on_create_blog' ) );
} else {
add_action( 'wpmu_new_blog', array( 'Mp_Time_Table', 'on_create_blog' ) );
}
add_filter( 'wpmu_drop_tables', array( 'Mp_Time_Table', 'on_delete_blog' ) );
/**
* Class Mp_Time_Table
*/
class Mp_Time_Table {
protected static $instance;
/**
* Mp_Time_Table constructor.
*/
public function __construct() {
$this->include_all();
Core::get_instance()->init_plugin( 'mp_timetable' );
}
/**
* Include all files
*/
public function include_all() {
/**
* Include Gump
*/
require_once self::get_plugin_path() . 'classes/libs/class-gump.php';
/**
* Install Parsers
*/
require_once self::get_plugin_path() . 'classes/libs/parsers.php';
/**
* Include Permalinks
*/
require_once self::get_plugin_path() . 'classes/class-permalinks.php';
/**
* Include Core
*/
require_once self::get_plugin_path() . 'classes/class-core.php';
/**
* Include module
*/
require_once self::get_plugin_path() . 'classes/class-module.php';
/**
* Include Model
*/
require_once self::get_plugin_path() . 'classes/class-model.php';
/**
* Include Controller
*/
require_once self::get_plugin_path() . 'classes/class-controller.php';
/**
* Include State factory
*/
require_once self::get_plugin_path() . 'classes/class-state-factory.php';
/**
* Include Preprocessor
*/
require_once self::get_plugin_path() . 'classes/class-preprocessor.php';
/**
* include shortcodes
*/
require_once( self::get_plugin_path() . 'classes/class-shortcode.php' );
/**
* include Widgets
*/
require_once self::get_plugin_path() . 'classes/widgets/class-mp-timetable-widget.php';
/**
* Include view
*/
require_once self::get_plugin_path() . 'classes/class-view.php';
/**
* Include hooks
*/
require_once self::get_plugin_path() . 'classes/class-hooks.php';
/**
* Include blocks
*/
require_once self::get_plugin_path() . 'classes/blocks/class-timetable-block.php';
/**
* Include Widgets Managers
*/
require_once self::get_plugin_path() . 'classes/class-widgets-manager.php';
}
/**
* Get plugin path
*/
public static function get_plugin_path() {
return plugin_dir_path( __FILE__ );
}
/**
* @return Mp_Time_Table
*/
public static function init() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Retrieve relative to theme root path to templates.
*
* @return string
*/
public static function get_template_path() {
return apply_filters( 'mptt_template_path', 'mp-timetable/' );
}
/**
* Retrieve relative to plugin root path to templates.
*
* @return string
*/
public static function get_templates_path() {
return self::get_plugin_path() . 'templates/';
}
/**
* Get plugin part path
*
* @param string $part
*
* @return string
*/
public static function get_plugin_part_path( $part = '' ) {
return self::get_plugin_path() . $part;
}
/**
* On activation
*/
public static function on_activation( $network_wide = false ) {
if ( $network_wide && is_multisite() ) {
$sites = get_sites();
foreach( $sites as $site ) {
$blog_id = $site->blog_id;
switch_to_blog( $blog_id );
Mp_Time_Table::install();
restore_current_blog();
}
} else {
Mp_Time_Table::install();
}
}
/**
* Install
*/
public static function install() {
// Register post type
Core::get_instance()->register_all_post_type();
// Register taxonomy all
Core::get_instance()->register_all_taxonomies();
flush_rewrite_rules( false );
//Create table in not exists
Core::get_instance()->create_table();
}
/**
* On deactivation
*/
public static function on_deactivation() {
flush_rewrite_rules( false );
}
/**
* On uninstall
*/
public static function on_uninstall() {
do_action( 'mptt_on_uninstall' );
}
/**
* On create blog
*
* @param int|WP_Site $blog
*/
public static function on_create_blog( $blog ) {
if ( is_plugin_active_for_network( MP_TT_PLUGIN_BASENAME ) ) {
if ( ! is_int( $blog ) ) {
$blog = $blog->id;
}
switch_to_blog( $blog );
Mp_Time_Table::install();
restore_current_blog();
}
}
/**
* On blog creation
*/
public static function on_delete_blog( $tables ) {
$tables[] = self::get_datatable();
return $tables;
}
/**
* Get data table name
*
* @return string
*/
public static function get_datatable() {
global $wpdb;
return $wpdb->prefix . "mp_timetable_data";
}
/**
* Get plugin url
*
* @param string $path
*
* @return string
*/
static function get_plugin_url( $path = '' ) {
return plugin_dir_url( __FILE__ ) . $path;
}
}