-
Notifications
You must be signed in to change notification settings - Fork 27
/
church-theme-content.php
executable file
·358 lines (280 loc) · 9.7 KB
/
church-theme-content.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* Plugin Name: Church Content
* Plugin URI: https://churchthemes.com/plugins/church-content/
* Description: Provides an interface for managing sermons, events, people and locations. A <strong>compatible theme is required</strong> for presenting content from these church-centric post types in a tightly-integrated manner.
* Version: 2.6.2
* Author: ChurchThemes.com
* Author URI: https://churchthemes.com
* License: GPLv2 or later
* Text Domain: church-theme-content
* Domain Path: /languages
*
* @package Church_Theme_Content
* @copyright Copyright (c) 2013 - 2024, ChurchThemes.com, LLC
* @link https://github.com/churchthemes/church-theme-content
* @license GPLv2 or later
*/
// No direct access
if (! defined( 'ABSPATH' )) exit;
/**
* Main class
*
* @since 0.9
*/
class Church_Theme_Content {
/**
* Plugin data from get_plugins()
*
* @since 0.9
* @var object
*/
public $plugin_data;
/**
* Includes to load
*
* @since 0.9
* @var array
*/
public $includes;
/**
* Constructor
*
* Add actions for methods that define constants and load includes.
*
* @since 0.9
* @access public
*/
public function __construct() {
// Set plugin data.
add_action( 'plugins_loaded', array( $this, 'set_plugin_data' ), 1 );
// Define constants.
add_action( 'plugins_loaded', array( $this, 'define_constants' ), 1 );
// Load language file for old versions of WordPress.
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 1 );
// Set includes.
add_action( 'plugins_loaded', array( $this, 'set_includes' ), 1 );
// Load includes.
add_action( 'plugins_loaded', array( $this, 'load_includes' ), 1 );
// Trigger flushing of rewrite rules on plugin activation.
// This must be done early (not on plugins_loaded or init).
register_activation_hook( __FILE__, array( &$this, 'trigger_flush_rewrite_rules' ) );
// Check if rewrite rules should be flushed.
add_action( 'init', array( $this, 'ctc_check_flush_rewrite_rules' ), 1 );
}
/**
* Set plugin data
*
* This data is used by constants.
*
* @since 0.9
* @access public
*/
public function set_plugin_data() {
// Load plugin.php if get_plugins() not available
if (! function_exists( 'get_plugins' )) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Get path to plugin's directory
$plugin_dir = plugin_basename( dirname( __FILE__ ) );
// Get plugin data
$plugin_data = current( get_plugins( '/' . $plugin_dir ) );
// Set plugin data
$this->plugin_data = apply_filters( 'ctc_plugin_data', $plugin_data );
}
/**
* Define constants
*
* @since 0.9
* @access public
*/
public function define_constants() {
// Plugin details
define( 'CTC_VERSION', $this->plugin_data['Version'] ); // plugin version
define( 'CTC_NAME', $this->plugin_data['Name'] ); // plugin name
define( 'CTC_AUTHOR', strip_tags( $this->plugin_data['Author'] ) ); // plugin author
define( 'CTC_INFO_URL', $this->plugin_data['PluginURI'] ); // plugin's info page URL
define( 'CTC_FILE', __FILE__ ); // plugin's main file absolute path
define( 'CTC_FILE_BASE', plugin_basename( CTC_FILE ) ); // plugin's main file path relative to plugin directory
define( 'CTC_DIR', dirname( CTC_FILE_BASE ) ); // plugin's directory
define( 'CTC_PATH', untrailingslashit( plugin_dir_path( CTC_FILE ) ) ); // plugin's absolute path
define( 'CTC_URL', untrailingslashit( plugin_dir_url( CTC_FILE ) ) ); // plugin's directory URL
// Directories
define( 'CTC_INC_DIR', 'includes' ); // includes directory
define( 'CTC_ADMIN_DIR', CTC_INC_DIR . '/admin' ); // admin directory
define( 'CTC_CLASS_DIR', CTC_INC_DIR . '/classes' ); // classes directory
define( 'CTC_LIB_DIR', CTC_INC_DIR . '/libraries' ); // libraries directory
define( 'CTC_CSS_DIR', 'css' ); // stylesheets directory
define( 'CTC_JS_DIR', 'js' ); // JavaScript directory
define( 'CTC_IMG_DIR', 'images' ); // images directory
define( 'CTC_LANG_DIR', 'languages' ); // languages directory
// CT Meta Box
if (! defined( 'CTMB_URL' )) { // in case also used in theme or other plugin
define( 'CTMB_URL', CTC_URL . '/' . CTC_LIB_DIR . '/ct-meta-box' ); // for enqueueing JS/CSS
}
}
/**
* Load language file
*
* For WordPress versions under 4.6 only. https://make.wordpress.org/core/2016/07/06/i18n-improvements-in-4-6/
*
* This will load the MO file for the current locale.
* The translation file must be named church-theme-content-$locale.mo.
*
* First it will check to see if the MO file exists in wp-content/languages/plugins.
* If not, then the 'languages' directory inside the plugin will be used.
* It is ideal to keep translation files outside of the plugin to avoid loss during updates.
*
* @since 0.9
* @access public
*/
public function load_textdomain() {
// Get version of WordPress in use.
$wp_version = get_bloginfo( 'version' );
// Textdomain.
$domain = 'church-theme-content';
// WordPress core locale filter.
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
// WordPress 3.6 and earlier don't auto-load from wp-content/languages, so check and load manually: http://core.trac.wordpress.org/changeset/22346.
$external_mofile = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo';
if (version_compare( $wp_version, '3.6', '<=' ) && file_exists( $external_mofile )) { // external translation exists.
load_textdomain( $domain, $external_mofile );
}
// Load normally.
// Either using WordPress 3.7+ or older version with external translation.
else {
$languages_dir = CTC_DIR . '/' . trailingslashit( CTC_LANG_DIR ); // ensure trailing slash.
load_plugin_textdomain( $domain, false, $languages_dir );
}
}
/**
* Set includes
*
* @since 0.9
* @access public
*/
public function set_includes() {
$this->includes = apply_filters( 'ctc_includes', array(
// Frontend or admin
'always' => array(
// Functions.
CTC_INC_DIR . '/add-ons.php',
CTC_INC_DIR . '/event-fields.php',
CTC_INC_DIR . '/helpers.php',
CTC_INC_DIR . '/mime-types.php',
CTC_INC_DIR . '/podcast.php',
CTC_INC_DIR . '/post-types.php',
CTC_INC_DIR . '/schedule.php',
CTC_INC_DIR . '/settings.php',
CTC_INC_DIR . '/support.php',
CTC_INC_DIR . '/taxonomies.php',
// Libraries.
CTC_LIB_DIR . '/ct-plugin-settings/ct-plugin-settings.php', // see CTPS_URL constant defined above.
CTC_LIB_DIR . '/ct-recurrence/ct-recurrence-load.php', // don't load ct-recurrence.php directly.
// Classes.
),
// Admin only.
'admin' => array(
// Functions
CTC_ADMIN_DIR . '/admin-add-ons.php',
CTC_ADMIN_DIR . '/admin-enqueue-scripts.php',
CTC_ADMIN_DIR . '/admin-enqueue-styles.php',
CTC_ADMIN_DIR . '/admin-event-fields.php',
CTC_ADMIN_DIR . '/admin-helpers.php',
CTC_ADMIN_DIR . '/admin-location-fields.php',
CTC_ADMIN_DIR . '/admin-maps.php',
CTC_ADMIN_DIR . '/admin-menu.php',
CTC_ADMIN_DIR . '/admin-person-fields.php',
CTC_ADMIN_DIR . '/admin-posts.php',
CTC_ADMIN_DIR . '/admin-sermon-fields.php',
CTC_ADMIN_DIR . '/admin-support.php',
CTC_ADMIN_DIR . '/dashboard.php',
CTC_ADMIN_DIR . '/edd-license.php',
CTC_ADMIN_DIR . '/editor.php',
CTC_ADMIN_DIR . '/import.php',
CTC_ADMIN_DIR . '/migrate-risen.php',
CTC_ADMIN_DIR . '/notices.php',
CTC_ADMIN_DIR . '/upgrade.php',
// Libraries.
CTC_LIB_DIR . '/ct-meta-box/ct-meta-box.php', // see CTMB_URL constant defined above
// Classes.
CTC_CLASS_DIR . '/CTC_Dashboard_News.php', // see CTMB_URL constant defined above
),
// Frontend only
/*
'frontend' => array (
),
*/
) );
}
/**
* Load includes
*
* Include files based on whether or not condition is met.
*
* @since 0.9
* @access public
*/
public function load_includes() {
// Get includes
$includes = $this->includes;
// Loop conditions
foreach ($includes as $condition => $files) {
$do_includes = false;
// Check condition
switch($condition) {
// Admin Only
case 'admin':
if (is_admin()) {
$do_includes = true;
}
break;
// Frontend Only
case 'frontend':
if (! is_admin()) {
$do_includes = true;
}
break;
// Admin or Frontend (always)
default:
$do_includes = true;
break;
}
// Loop files if condition met
if ($do_includes) {
foreach ($files as $file) {
require_once trailingslashit( CTC_PATH ) . $file;
}
}
}
}
/**
* Trigger flushing of rewrite rules.
*
* Doing this on activation makes post type rewrite slugs take effect.
*
* @since 1.0
* @access public
*/
public static function trigger_flush_rewrite_rules() {
// Tell to flush rules after post types registered.
update_option( 'ctc_flush_rewrite_rules', '1' );
}
/**
* Check if rewrite rules should be flushed.
*
* This checks if ctc_flush_rewrite_rules option has been set earlier
* so that the rewrite rules can be flushed later.
*/
public function ctc_check_flush_rewrite_rules() {
// Check if option was set.
if (get_option( 'ctc_flush_rewrite_rules' )) {
// Flush rewrite rules.
flush_rewrite_rules();
// Delete option so this doesn't run again.
delete_option( 'ctc_flush_rewrite_rules' );
}
}
}
// Instantiate the main class.
new Church_Theme_Content();