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