PluginProbe
Church Content – Sermons, Events and More / 2.4
Church Content – Sermons, Events and More v2.4
1.5 1.6 1.6.1 1.7 1.7.1 1.7.2 1.8 2.0 2.0.1 2.1 2.1.2 2.2 2.2.1 2.3 2.3.1 2.4 2.4.1 2.5 2.6 2.6.1 2.6.2 2.7 trunk 1.0.1 1.0.2 All 42 releases
church-theme-content / church-theme-content.php

church-theme-content.php in Church Content – Sermons, Events and More 2.4, at church-theme-content.php

359 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Church Content
4 * Plugin URI: https://churchthemes.com/plugins/church-content/
5 * 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.
6 * Version: 2.4
7 * Author: ChurchThemes.com
8 * Author URI: https://churchthemes.com
9 * License: GPLv2 or later
10 * Text Domain: church-theme-content
11 * Domain Path: /languages
12 *
13 * @package Church_Theme_Content
14 * @copyright Copyright (c) 2013 - 2020, ChurchThemes.com, LLC
15 * @link https://github.com/churchthemes/church-theme-content
16 * @license GPLv2 or later
17 */
18
19 // No direct access
20 if ( ! defined( 'ABSPATH' ) ) exit;
21
22 /**
23 * Main class
24 *
25 * @since 0.9
26 */
27 class Church_Theme_Content {
28
29 /**
30 * Plugin data from get_plugins()
31 *
32 * @since 0.9
33 * @var object
34 */
35 public $plugin_data;
36
37 /**
38 * Includes to load
39 *
40 * @since 0.9
41 * @var array
42 */
43 public $includes;
44
45 /**
46 * Constructor
47 *
48 * Add actions for methods that define constants and load includes.
49 *
50 * @since 0.9
51 * @access public
52 */
53 public function __construct() {
54
55 // Set plugin data.
56 add_action( 'plugins_loaded', array( $this, 'set_plugin_data' ), 1 );
57
58 // Define constants.
59 add_action( 'plugins_loaded', array( $this, 'define_constants' ), 1 );
60
61 // Load language file for old versions of WordPress.
62 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 1 );
63
64 // Set includes.
65 add_action( 'plugins_loaded', array( $this, 'set_includes' ), 1 );
66
67 // Load includes.
68 add_action( 'plugins_loaded', array( $this, 'load_includes' ), 1 );
69
70 // Trigger flushing of rewrite rules on plugin activation.
71 // This must be done early (not on plugins_loaded or init).
72 register_activation_hook( __FILE__, array( &$this, 'trigger_flush_rewrite_rules' ) );
73
74 // Check if rewrite rules should be flushed.
75 add_action( 'init', array( $this, 'ctc_check_flush_rewrite_rules' ), 1 );
76
77 }
78
79 /**
80 * Set plugin data
81 *
82 * This data is used by constants.
83 *
84 * @since 0.9
85 * @access public
86 */
87 public function set_plugin_data() {
88
89 // Load plugin.php if get_plugins() not available
90 if ( ! function_exists( 'get_plugins' ) ) {
91 require_once ABSPATH . 'wp-admin/includes/plugin.php';
92 }
93
94 // Get path to plugin's directory
95 $plugin_dir = plugin_basename( dirname( __FILE__ ) );
96
97 // Get plugin data
98 $plugin_data = current( get_plugins( '/' . $plugin_dir ) );
99
100 // Set plugin data
101 $this->plugin_data = apply_filters( 'ctc_plugin_data', $plugin_data );
102
103 }
104
105 /**
106 * Define constants
107 *
108 * @since 0.9
109 * @access public
110 */
111 public function define_constants() {
112
113 // Plugin details
114 define( 'CTC_VERSION', $this->plugin_data['Version'] ); // plugin version
115 define( 'CTC_NAME', $this->plugin_data['Name'] ); // plugin name
116 define( 'CTC_AUTHOR', strip_tags( $this->plugin_data['Author'] ) ); // plugin author
117 define( 'CTC_INFO_URL', $this->plugin_data['PluginURI'] ); // plugin's info page URL
118 define( 'CTC_FILE', __FILE__ ); // plugin's main file absolute path
119 define( 'CTC_FILE_BASE', plugin_basename( CTC_FILE ) ); // plugin's main file path relative to plugin directory
120 define( 'CTC_DIR', dirname( CTC_FILE_BASE ) ); // plugin's directory
121 define( 'CTC_PATH', untrailingslashit( plugin_dir_path( CTC_FILE ) ) ); // plugin's absolute path
122 define( 'CTC_URL', untrailingslashit( plugin_dir_url( CTC_FILE ) ) ); // plugin's directory URL
123
124 // Directories
125 define( 'CTC_INC_DIR', 'includes' ); // includes directory
126 define( 'CTC_ADMIN_DIR', CTC_INC_DIR . '/admin' ); // admin directory
127 define( 'CTC_CLASS_DIR', CTC_INC_DIR . '/classes' ); // classes directory
128 define( 'CTC_LIB_DIR', CTC_INC_DIR . '/libraries' ); // libraries directory
129 define( 'CTC_CSS_DIR', 'css' ); // stylesheets directory
130 define( 'CTC_JS_DIR', 'js' ); // JavaScript directory
131 define( 'CTC_IMG_DIR', 'images' ); // images directory
132 define( 'CTC_LANG_DIR', 'languages' ); // languages directory
133
134 // CT Meta Box
135 if ( ! defined( 'CTMB_URL' ) ) { // in case also used in theme or other plugin
136 define( 'CTMB_URL', CTC_URL . '/' . CTC_LIB_DIR . '/ct-meta-box' ); // for enqueueing JS/CSS
137 }
138
139 }
140
141 /**
142 * Load language file
143 *
144 * For WordPress versions under 4.6 only. https://make.wordpress.org/core/2016/07/06/i18n-improvements-in-4-6/
145 *
146 * This will load the MO file for the current locale.
147 * The translation file must be named church-theme-content-$locale.mo.
148 *
149 * First it will check to see if the MO file exists in wp-content/languages/plugins.
150 * If not, then the 'languages' directory inside the plugin will be used.
151 * It is ideal to keep translation files outside of the plugin to avoid loss during updates.
152 *
153 * @since 0.9
154 * @access public
155 */
156 public function load_textdomain() {
157
158 // Get version of WordPress in use.
159 $wp_version = get_bloginfo( 'version' );
160
161 // Textdomain.
162 $domain = 'church-theme-content';
163
164 // WordPress core locale filter.
165 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
166
167 // 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.
168 $external_mofile = WP_LANG_DIR . '/plugins/'. $domain . '-' . $locale . '.mo';
169 if ( version_compare( $wp_version, '3.6', '<=' ) && file_exists( $external_mofile ) ) { // external translation exists.
170 load_textdomain( $domain, $external_mofile );
171 }
172
173 // Load normally.
174 // Either using WordPress 3.7+ or older version with external translation.
175 else {
176 $languages_dir = CTC_DIR . '/' . trailingslashit( CTC_LANG_DIR ); // ensure trailing slash.
177 load_plugin_textdomain( $domain, false, $languages_dir );
178 }
179
180 }
181
182 /**
183 * Set includes
184 *
185 * @since 0.9
186 * @access public
187 */
188 public function set_includes() {
189
190 $this->includes = apply_filters( 'ctc_includes', array(
191
192 // Frontend or admin
193 'always' => array(
194
195 // Functions.
196 CTC_INC_DIR . '/add-ons.php',
197 CTC_INC_DIR . '/event-fields.php',
198 CTC_INC_DIR . '/helpers.php',
199 CTC_INC_DIR . '/mime-types.php',
200 CTC_INC_DIR . '/podcast.php',
201 CTC_INC_DIR . '/post-types.php',
202 CTC_INC_DIR . '/schedule.php',
203 CTC_INC_DIR . '/settings.php',
204 CTC_INC_DIR . '/support.php',
205 CTC_INC_DIR . '/taxonomies.php',
206
207 // Libraries.
208 CTC_LIB_DIR . '/ct-plugin-settings/ct-plugin-settings.php', // see CTPS_URL constant defined above.
209 CTC_LIB_DIR . '/ct-recurrence/ct-recurrence-load.php', // don't load ct-recurrence.php directly.
210
211 // Classes.
212
213 ),
214
215 // Admin only.
216 'admin' => array(
217
218 // Functions
219 CTC_ADMIN_DIR . '/admin-add-ons.php',
220 CTC_ADMIN_DIR . '/admin-enqueue-scripts.php',
221 CTC_ADMIN_DIR . '/admin-enqueue-styles.php',
222 CTC_ADMIN_DIR . '/admin-event-fields.php',
223 CTC_ADMIN_DIR . '/admin-helpers.php',
224 CTC_ADMIN_DIR . '/admin-location-fields.php',
225 CTC_ADMIN_DIR . '/admin-maps.php',
226 CTC_ADMIN_DIR . '/admin-menu.php',
227 CTC_ADMIN_DIR . '/admin-person-fields.php',
228 CTC_ADMIN_DIR . '/admin-posts.php',
229 CTC_ADMIN_DIR . '/admin-sermon-fields.php',
230 CTC_ADMIN_DIR . '/admin-support.php',
231 CTC_ADMIN_DIR . '/dashboard.php',
232 CTC_ADMIN_DIR . '/edd-license.php',
233 CTC_ADMIN_DIR . '/editor.php',
234 CTC_ADMIN_DIR . '/import.php',
235 CTC_ADMIN_DIR . '/migrate-risen.php',
236 CTC_ADMIN_DIR . '/notices.php',
237 CTC_ADMIN_DIR . '/upgrade.php',
238
239 // Libraries.
240 CTC_LIB_DIR . '/ct-meta-box/ct-meta-box.php', // see CTMB_URL constant defined above
241
242 // Classes.
243 CTC_CLASS_DIR . '/CTC_Dashboard_News.php', // see CTMB_URL constant defined above
244
245 ),
246
247 // Frontend only
248 /*
249 'frontend' => array (
250
251 ),
252 */
253
254 ) );
255
256 }
257
258 /**
259 * Load includes
260 *
261 * Include files based on whether or not condition is met.
262 *
263 * @since 0.9
264 * @access public
265 */
266 public function load_includes() {
267
268 // Get includes
269 $includes = $this->includes;
270
271 // Loop conditions
272 foreach ( $includes as $condition => $files ) {
273
274 $do_includes = false;
275
276 // Check condition
277 switch( $condition ) {
278
279 // Admin Only
280 case 'admin':
281
282 if ( is_admin() ) {
283 $do_includes = true;
284 }
285
286 break;
287
288 // Frontend Only
289 case 'frontend':
290
291 if ( ! is_admin() ) {
292 $do_includes = true;
293 }
294
295 break;
296
297 // Admin or Frontend (always)
298 default:
299
300 $do_includes = true;
301
302 break;
303
304 }
305
306 // Loop files if condition met
307 if ( $do_includes ) {
308
309 foreach ( $files as $file ) {
310 require_once trailingslashit( CTC_PATH ) . $file;
311 }
312
313 }
314
315 }
316
317 }
318
319 /**
320 * Trigger flushing of rewrite rules.
321 *
322 * Doing this on activation makes post type rewrite slugs take effect.
323 *
324 * @since 1.0
325 * @access public
326 */
327 public static function trigger_flush_rewrite_rules() {
328
329 // Tell to flush rules after post types registered.
330 update_option( 'ctc_flush_rewrite_rules', '1' );
331
332 }
333
334 /**
335 * Check if rewrite rules should be flushed.
336 *
337 * This checks if ctc_flush_rewrite_rules option has been set earlier
338 * so that the rewrite rules can be flushed later.
339 */
340 public function ctc_check_flush_rewrite_rules() {
341
342 // Check if option was set.
343 if ( get_option( 'ctc_flush_rewrite_rules' ) ) {
344
345 // Flush rewrite rules.
346 flush_rewrite_rules();
347
348 // Delete option so this doesn't run again.
349 delete_option( 'ctc_flush_rewrite_rules' );
350
351 }
352
353 }
354
355 }
356
357 // Instantiate the main class.
358 new Church_Theme_Content();
359