forked from christianwach/bp-event-organiser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bp-event-organiser.php
279 lines (197 loc) · 5.83 KB
/
bp-event-organiser.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
<?php
/*
--------------------------------------------------------------------------------
Plugin Name: BuddyPress Event Organiser
Description: A WordPress plugin for assigning Event Organiser plugin Events to BuddyPress Groups and Group Hierarchies
Version: 0.2
Author: Christian Wach
Author URI: http://haystack.co.uk
Plugin URI: http://haystack.co.uk
--------------------------------------------------------------------------------
*/
// set our debug flag here
define( 'BUDDYPRESS_EVENT_ORGANISER_DEBUG', false );
// set our version here
define( 'BUDDYPRESS_EVENT_ORGANISER_VERSION', '0.2' );
// store reference to this file
if ( !defined( 'BUDDYPRESS_EVENT_ORGANISER_FILE' ) ) {
define( 'BUDDYPRESS_EVENT_ORGANISER_FILE', __FILE__ );
}
// store URL to this plugin's directory
if ( !defined( 'BUDDYPRESS_EVENT_ORGANISER_URL' ) ) {
define( 'BUDDYPRESS_EVENT_ORGANISER_URL', plugin_dir_url( BUDDYPRESS_EVENT_ORGANISER_FILE ) );
}
// store PATH to this plugin's directory
if ( !defined( 'BPEO_PATH' ) ) {
define( 'BPEO_PATH', plugin_dir_path( BUDDYPRESS_EVENT_ORGANISER_FILE ) );
}
// backward compatibility
define( 'BUDDYPRESS_EVENT_ORGANISER_PATH', constant( 'BPEO_PATH' ) );
// group events slug
if ( ! defined( 'BPEO_EVENTS_SLUG' ) ) {
define( 'BPEO_EVENTS_SLUG', 'events' );
}
// new events slug
if ( ! defined( 'BPEO_EVENTS_NEW_SLUG' ) ) {
define( 'BPEO_EVENTS_NEW_SLUG', 'new-event' );
}
/**
* Include BuddyPress-specific functionality.
*/
function bpeo_include() {
require( BPEO_PATH . 'includes/functions.php' );
require( BPEO_PATH . 'includes/component.php' );
require( BPEO_PATH . 'includes/user.php' );
if ( bp_is_active( 'activity' ) ) {
require( BPEO_PATH . 'includes/activity.php' );
}
if ( bp_is_active( 'groups' ) ) {
require( BPEO_PATH . 'includes/group.php' );
}
}
add_action( 'bp_include', 'bpeo_include' );
/*
--------------------------------------------------------------------------------
BuddyPress_Event_Organiser Class
--------------------------------------------------------------------------------
*/
class BuddyPress_Event_Organiser {
/**
* properties
*/
// Admin/DB class
public $db;
// Event Organiser utilities class
public $eo;
/**
* @description: initialises this object
* @return object
*/
function __construct() {
// initialise
$this->initialise();
// use translation files
$this->enable_translation();
// Register public assets. @todo Only load when needed.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'wp_print_styles', array( $this, 'enqueue_styles' ) );
// add action for CBOX theme compatibility
add_action( 'wp_head', array( $this, 'cbox_theme_compatibility' ) );
// --<
return $this;
}
/**
* @description: do stuff on plugin init
* @return nothing
*/
public function initialise() {
// load our BuddyPress Group class
require( BUDDYPRESS_EVENT_ORGANISER_PATH . 'bp-event-organiser-groups.php' );
// load our Event Organiser class
require( BUDDYPRESS_EVENT_ORGANISER_PATH . 'bp-event-organiser-eo.php' );
// initialise
$this->eo = new BuddyPress_Event_Organiser_EO;
// store references
$this->eo->set_references( $this );
}
/**
* @description: do stuff on plugin activation
* @return nothing
*/
public function activate() {
}
/**
* @description: do stuff on plugin deactivation
* @return nothing
*/
public function deactivate() {
}
//##########################################################################
/**
* @description: load translation files
* A good reference on how to implement translation in WordPress:
* http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/
* @return nothing
*/
public function enable_translation() {
// not used, as there are no translations as yet
load_plugin_textdomain(
// unique name
'bp-event-organiser',
// deprecated argument
false,
// relative path to directory containing translation files
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
);
}
/**
* Enqueues our scripts on both the frontend and admin.
*
* @param string $admin_hook Only applicable if in the admin area.
*/
public function enqueue_scripts( $admin_hook = '' ) {
$frontend = ! empty( $admin_hook ) ? false : true;
$enqueue = false;
// enqueue scripts only on event admin pages
if ( false === $frontend && 'post.php' === $admin_hook ) {
$post_type = ! empty( $_GET['post_type'] ) ? $_GET['post_type'] : '';
$post_id = ! empty( $_GET['post'] ) ? $_GET['post'] : 0;
if ( ! empty( $post_id ) ) {
$post_type = get_post( $post_id )->post_type;
}
if ( 'event' === $post_type ) {
$enqueue = true;
}
}
// enqneue scripts on frontend event pages
if ( bpeo_is_component() ) {
$enqueue = true;
}
// bail!
if ( false === $enqueue ) {
return;
}
bpeo_enqueue_assets();
}
/**
* Enqueue styles.
*/
public function enqueue_styles() {
wp_enqueue_style(
'bp_event_organiser_css',
BUDDYPRESS_EVENT_ORGANISER_URL . 'assets/css/bp-event-organiser.css'
);
}
/**
* @description: adds icon to menu in CBOX theme
*/
function cbox_theme_compatibility() {
// is CBOX theme active?
if ( function_exists( 'cbox_theme_register_widgets' ) ) {
// output style in head
?>
<style type="text/css">
/* <![CDATA[ */
#nav-<?php echo apply_filters( 'bpeo_extension_slug', 'events' ) ?>:before
{
content: "R";
}
/* ]]> */
</style>
<?php
}
}
} // class ends
/**
* @description: init plugin
* @return nothing
*/
function buddypress_event_organiser_init() {
// declare as global
global $buddypress_event_organiser;
// init plugin
$buddypress_event_organiser = new BuddyPress_Event_Organiser;
}
// init
add_action( 'bp_include', 'buddypress_event_organiser_init' );