-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-organiser-apple-cal.php
239 lines (197 loc) · 5.21 KB
/
event-organiser-apple-cal.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
<?php
/**
* Plugin Name: Event Organiser ICS Feed for Apple Calendar
* Description: Provides a Feed for Event Organiser Events that is compatible with Apple Calendar.
* Version: 0.1.1
* Author: Christian Wach
* Author URI: https://haystack.co.uk
* Plugin URI: https://github.com/christianwach/event-organiser-apple-cal
* GitHub Plugin URI: https://github.com/christianwach/event-organiser-apple-cal
* Text Domain: event-organiser-apple-cal
* Domain Path: /languages
*
* @package Event_Organiser_Apple_Cal
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
// Set our version here.
define( 'EVENT_ORGANISER_APPLE_CAL_VERSION', '0.1.1' );
// Store reference to this file.
if ( ! defined( 'EVENT_ORGANISER_APPLE_CAL_FILE' ) ) {
define( 'EVENT_ORGANISER_APPLE_CAL_FILE', __FILE__ );
}
// Store URL to this plugin's directory.
if ( ! defined( 'EVENT_ORGANISER_APPLE_CAL_URL' ) ) {
define( 'EVENT_ORGANISER_APPLE_CAL_URL', plugin_dir_url( EVENT_ORGANISER_APPLE_CAL_FILE ) );
}
// Store PATH to this plugin's directory.
if ( ! defined( 'EVENT_ORGANISER_APPLE_CAL_PATH' ) ) {
define( 'EVENT_ORGANISER_APPLE_CAL_PATH', plugin_dir_path( EVENT_ORGANISER_APPLE_CAL_FILE ) );
}
/**
* Event Organiser ICS Feed for Apple Calendar Class.
*
* A class that encapsulates this plugin's functionality.
*
* @since 0.1
*/
class Event_Organiser_Apple_Cal {
/**
* Instance.
*
* @since 0.1
* @access private
* @var Event_Organiser_Apple_Cal $instance The plugin instance.
*/
private static $instance;
/**
* The Apple iCal Feed class.
*
* @since 0.1
* @access public
* @var object $ical The Apple iCal Feed class.
*/
public $ical;
/**
* The Shortcode class.
*
* @since 0.1
* @access public
* @var object $ical The Shortcode class.
*/
public $shortcode;
/**
* Return the instance and optionally create one if it doesn't already exist.
*
* @since 0.1
*
* @return Event_Organiser_Apple_Cal The plugin instance.
*/
public static function instance_get() {
// If it doesn't already exist.
if ( ! isset( self::$instance ) ) {
// Create it.
self::$instance = new Event_Organiser_Apple_Cal();
self::$instance->instance_setup();
}
// Return instance.
return self::$instance;
}
/**
* Sets up this object.
*
* @since 0.1
*/
public function instance_setup() {
// Always use translation files.
add_action( 'plugins_loaded', [ $this, 'enable_translation' ] );
// Initialise.
add_action( 'plugins_loaded', [ $this, 'initialise' ] );
}
/**
* Perform tasks on plugin activation.
*
* @since 0.1
*/
public function activate() {
flush_rewrite_rules();
}
/**
* Perform tasks on plugin deactivation.
*
* @since 0.1
*/
public function deactivate() {
flush_rewrite_rules();
}
/**
* Initialises this object.
*
* @since 0.1
*/
public function initialise() {
// Bail quietly if Event Organiser plugin is not present.
if ( ! defined( 'EVENT_ORGANISER_VER' ) ) {
return;
}
// Include files.
$this->include_files();
// Set up objects and references.
$this->setup_objects();
/**
* Broadcast that this plugin is now loaded.
*
* This action is used internally by this plugin to initialise its objects
* and ensures that all includes and setup has occurred beforehand.
*
* @since 0.1
*/
do_action( 'event_organiser_apple_cal_loaded' );
}
/**
* Include files.
*
* @since 0.1
*/
public function include_files() {
// Load our class files.
require EVENT_ORGANISER_APPLE_CAL_PATH . 'includes/class-eo-apple-cal-feed.php';
require EVENT_ORGANISER_APPLE_CAL_PATH . 'includes/class-eo-apple-cal-shortcode.php';
}
/**
* Set up this plugin's objects.
*
* @since 0.1
*/
public function setup_objects() {
// Only ever do this once.
static $done;
if ( isset( $done ) && $done === true ) {
return;
}
// Instantiate objects.
$this->ical = new Event_Organiser_Apple_Cal_Feed();
$this->shortcode = new Event_Organiser_Apple_Cal_Shortcode();
// We're done.
$done = true;
}
/**
* Load translation files.
*
* A good reference on how to implement translation in WordPress:
*
* @see http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/
*
* @since 0.1
*/
public function enable_translation() {
// Load translations.
// phpcs:ignore WordPress.WP.DeprecatedParameters.Load_plugin_textdomainParam2Found
load_plugin_textdomain(
'event-organiser-apple-cal', // Unique name.
false, // Deprecated argument.
dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Relative path to translation files.
);
}
}
/**
* Returns the Event_Organiser_Apple_Cal instance.
*
* Use this function like you would a global variable, except without needing to
* declare the global.
*
* Example: $eoa = event_organiser_apple_cal();
*
* @since 0.1
*
* @return Event_Organiser_Apple_Cal The plugin instance.
*/
function event_organiser_apple_cal() {
return Event_Organiser_Apple_Cal::instance_get();
}
// Boot Event_Organiser_Apple_Cal immediately.
event_organiser_apple_cal();
// Activation.
register_activation_hook( __FILE__, [ event_organiser_apple_cal(), 'activate' ] );
// Deactivation.
register_deactivation_hook( __FILE__, [ event_organiser_apple_cal(), 'deactivate' ] );