-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccbpress-core.php
317 lines (271 loc) · 9.24 KB
/
ccbpress-core.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
<?php
/**
* Plugin Name: Church Data Connect for Church Community Builder
* Plugin URI: https://churchdataconnect.com/
* Description: Display information from Church Community Builder on your WordPress site.
* Version: 1.5.1
* Author: FireTree Design, LLC <info@firetreedesign.com>
* Author URI: https://firetreedesign.com/
* Text Domain: ccbpress-core
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* @package CCBPress_Core
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'CCBPress_Core' ) ) :
register_activation_hook( __FILE__, array( 'CCBPress_Core', 'schedule_cron' ) );
register_deactivation_hook( __FILE__, array( 'CCBPress_Core', 'unschedule_cron' ) );
/**
* CCBPress Core class
*/
class CCBPress_Core {
/**
* Instance
*
* @var CCBPress_Core The one true CCBPress_Core
* @since 1.0.0
*/
private static $instance;
/**
* CCBPress Transients Object
*
* @var object
* @since 1.0.0
*/
public $transients;
/**
* CCBPress CCB Object
*
* @var object
* @since 1.0.0
*/
public $ccb;
/**
* CCBPress Background Get
*
* @var function
* @since 1.0.0
*/
public $get;
/**
* CCBPress Sync Object
*
* @var object
* @since 1.0.0
*/
public $sync;
/**
* CCBPress Version
*
* @var string
* @since 1.0.0
*/
public $version = '1.5.1';
/**
* Main CCBPress_Core Instance
*
* Insures that only one instance of CCBPress_Core exists in memory at any
* one time.
*
* @since 1.0
* @static
* @staticvar array $instance
* @uses CCBPress_Core::includes() Include the required files
* @see CCBPress_Core()
* @return The one true CCBPress_Core
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof CCBPress_Core ) ) {
self::$instance = new CCBPress_Core();
self::$instance->setup_constants();
self::$instance->includes();
self::$instance->transients = new CCBPress_Transients();
self::$instance->ccb = new CCBPress_Connection();
self::$instance->get = new CCBPress_Background_Get();
self::$instance->init();
self::$instance->transients->init();
self::$instance->ccb->init();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin Database Version.
if ( ! defined( 'CCBPRESS_CORE_DB_VERSION' ) ) {
define( 'CCBPRESS_CORE_DB_VERSION', CCBPress()->version );
}
// Plugin File.
if ( ! defined( 'CCBPRESS_CORE_PLUGIN_FILE' ) ) {
define( 'CCBPRESS_CORE_PLUGIN_FILE', __FILE__ );
}
// Plugin Folder Path.
if ( ! defined( 'CCBPRESS_CORE_PLUGIN_DIR' ) ) {
define( 'CCBPRESS_CORE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'CCBPRESS_CORE_PLUGIN_URL' ) ) {
define( 'CCBPRESS_CORE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
}
/**
* Include required files
*
* @access private
* @since 1.0
* @return void
*/
private function includes() {
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-transients.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-connection.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-licenses.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-addon.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-options.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-template.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-customizer.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/ccb-services.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/schedule-get.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/styles.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/helpers.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-settings.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/settings/settings-ccb.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/settings/settings-import.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/settings/settings-ccbpress.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/settings/settings-licenses.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/tools/tools-cache.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/tools/class-ccbpress-tools-cron.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-purge-cache.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/widgets/widget-login.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/widgets/widget-online-giving.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/widgets/widget-group-info.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'lib/wp-background-processing/wp-async-request.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'lib/wp-background-processing/wp-background-process.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-background-get.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/import.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/upgrades.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-rest-api.php';
// Blocks.
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/class-ccbpress-core-blocks.php';
if ( is_admin() ) {
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-page-tabs.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-pages.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-scripts.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-styles.php';
require_once CCBPRESS_CORE_PLUGIN_DIR . 'includes/admin/admin-dashboard.php';
}
}
/**
* Initialize the class
*
* @since 1.1.15
*
* @return void
*/
public static function init() {
// Load plugin text domain.
add_action( 'plugins_loaded', array( 'CCBPress_Core', 'plugin_textdomain' ) );
if ( false === get_option( 'ccbpress_import_in_progress', false ) ) {
add_action( 'ccbpress_maintenance', array( 'CCBPress_Core', 'schedule_cron' ) );
}
if ( defined( 'DISABLE_WP_CRON' ) && true === DISABLE_WP_CRON ) {
add_action( 'admin_notices', array( 'CCBPress_Core', 'cron_disabled' ) );
}
if ( defined( 'ALTERNATE_WP_CRON' ) && true === ALTERNATE_WP_CRON ) {
add_action( 'admin_notices', array( 'CCBPress_Core', 'cron_alternate' ) );
}
}
/**
* Schedule daily mantenance tasks
*
* @since 1.0.0
*
* @return void
*/
public static function schedule_cron() {
if ( false === wp_next_scheduled( 'ccbpress_maintenance' ) ) {
wp_schedule_event( time() + 1800, 'hourly', 'ccbpress_maintenance' );
}
if ( false === wp_next_scheduled( 'ccbpress_import' ) && false === get_option( 'ccbpress_import_in_progress', false ) && CCBPress_Import::is_queue_empty() ) {
wp_schedule_single_event( time(), 'ccbpress_import' );
}
}
/**
* Unschedule daily mantenance tasks
*
* @since 1.0.0
*
* @return void
*/
public static function unschedule_cron() {
wp_clear_scheduled_hook( 'ccbpress_maintenance' );
wp_clear_scheduled_hook( 'ccbpress_import' );
wp_clear_scheduled_hook( 'ccbpress_transient_cache_cleanup' );
}
/**
* Display a warning that cron is disabled
*
* @since 1.3.0
*
* @return void
*/
public static function cron_disabled() {
global $pagenow;
if ( 'admin.php' !== $pagenow ) {
return;
}
if ( ! isset( $_GET['page'] ) ) {
return;
}
if ( 'ccbpress-settings' !== $_GET['page'] ) {
return;
}
printf( '<div class="notice notice-warning"><p>%s %s</p></div>', esc_html__( 'Church Data Connect for Church Community Builder may not work properly because the DISABLE_WP_CRON constant is set to true.', 'ccbpress-core' ), sprintf( '<a href="#" class="ccbpress-cron-help">%s</a>', esc_html__( 'Get more info.', 'ccbpress-core' ) ) );
}
/**
* Display a warning that alternative cron is enabled
*
* @since 1.3.2
*
* @return void
*/
public static function cron_alternate() {
global $pagenow;
if ( 'admin.php' !== $pagenow ) {
return;
}
if ( ! isset( $_GET['page'] ) ) {
return;
}
if ( 'ccbpress-settings' !== $_GET['page'] ) {
return;
}
printf( '<div class="notice notice-warning"><p>%s %s</p></div>', esc_html__( 'Church Data Connect for Church Community Builder may not work properly because the ALTERNATE_WP_CRON constant is set to true.', 'ccbpress-core' ), sprintf( '<a href="#" class="ccbpress-cron-help">%s</a>', esc_html__( 'Get more info.', 'ccbpress-core' ) ) );
}
/**
* Loads the plugin text domain for translation
*
* @since 1.1.15
*
* @return void
*/
public static function plugin_textdomain() {
load_plugin_textdomain( 'ccbpress-core', false, dirname( plugin_basename( CCBPRESS_CORE_PLUGIN_FILE ) ) . '/languages' );
}
}
endif; // End if class_exists check.
/**
* Initialize the CCBPress_Core class
*/
function ccbpress() {
return CCBPress_Core::instance();
}
ccbpress();