-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdisciple-tools-prayer-campaigns.php
More file actions
executable file
·364 lines (324 loc) · 13.7 KB
/
disciple-tools-prayer-campaigns.php
File metadata and controls
executable file
·364 lines (324 loc) · 13.7 KB
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
359
360
361
362
363
364
<?php
/**
* Plugin Name: Disciple.Tools - Prayer Campaigns
* Plugin URI: https://github.com/DiscipleTools/disciple-tools-prayer-campaigns
* Description: Add a prayer subscriptions module to Disciple.Tools that allows for non-users to subscribe to pray for specific locations at specific times, supporting both time and geographic prayer saturation for your project.
* Text Domain: disciple-tools-prayer-campaigns
* Domain Path: /languages
* Version: 4.19.0
* Author URI: https://github.com/DiscipleTools
* GitHub Plugin URI: https://github.com/DiscipleTools/disciple-tools-prayer-campaigns
* Requires at least: 4.7.0
* (Requires 4.7+ because of the integration of the REST API at 4.7 and the security requirements of this milestone version.)
* Tested up to: 5.6.1
*
* @package Disciple_Tools
* @link https://github.com/DiscipleTools
* @license GPL-2.0 or later
* https://www.gnu.org/licenses/gpl-2.0.html
*
* @version 0.1 Initializing plugin
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
add_filter( 'dt_plugins', function ( $plugins ){
$plugin_data = get_file_data( __FILE__, [ 'Version' => 'Version', 'Plugin Name' => 'Plugin Name' ], false );
$plugins['disciple-tools-prayer-campaigns'] = [
'plugin_url' => trailingslashit( plugin_dir_url( __FILE__ ) ),
'version' => $plugin_data['Version'] ?? null,
'name' => $plugin_data['Plugin Name'] ?? null,
];
return $plugins;
});
/**
* Gets the instance of the `DT_Prayer_Campaigns` class.
*
* @since 0.1
* @access public
* @return object|bool
*/
function dt_prayer_campaigns() {
$dt_prayer_campaigns_required_dt_theme_version = '1.43.0';
$wp_theme = wp_get_theme();
$version = $wp_theme->version;
/*
* Check if the Disciple.Tools theme is loaded and is the latest required version
*/
$is_theme_dt = class_exists( 'Disciple_Tools' );
if ( $is_theme_dt && version_compare( $version, $dt_prayer_campaigns_required_dt_theme_version, '<' ) ) {
add_action( 'admin_notices', 'dt_prayer_campaigns_hook_admin_notice' );
add_action( 'wp_ajax_dismissed_notice_handler', 'dt_hook_ajax_notice_handler' );
return false;
}
if ( !$is_theme_dt ){
return false;
}
/**
* Load useful function from the theme
*/
if ( !defined( 'DT_FUNCTIONS_READY' ) ){
require_once get_template_directory() . '/dt-core/global-functions.php';
}
return DT_Prayer_Campaigns::instance();
}
add_action( 'after_setup_theme', 'dt_prayer_campaigns', 20 );
require_once( 'campaign-functions/setup-functions.php' );
/**
* Fires after WordPress has finished loading but before any headers are sent.
*
*/
add_action( 'after_setup_theme', function() : void {
require_once __DIR__ . '/porches/interfaces/dt-porch-loader-interface.php';
require_once __DIR__ . '/porches/generic/dt-generic-porch-loader.php';
require_once __DIR__ . '/porches/ramadan/dt-ramadan-porch-loader.php';
require_once( 'campaign-functions/utils.php' );
} );
/**
* Singleton class for setting up the plugin.
*
* @since 0.1
* @access public
*/
class DT_Prayer_Campaigns {
public $plugin_dir_path = null;
public $plugin_dir_url = null;
private static $instance = null;
public static function instance() {
if ( is_null( self::$instance ) ) {
$i = new DT_Prayer_Campaigns();
self::$instance = $i;
}
return self::$instance;
}
public static function get_url_path(){
return trailingslashit( plugin_dir_url( __FILE__ ) );
}
public static function get_dir_path(){
return trailingslashit( plugin_dir_path( __FILE__ ) );
}
private function __construct() {
require_once( __DIR__ . '/admin/dt-porch-admin-tab-endpoints.php' );
$this->plugin_dir_path = trailingslashit( plugin_dir_path( __FILE__ ) );
$this->plugin_dir_url = trailingslashit( plugin_dir_url( __FILE__ ) );
$this->define_porch_constants();
require_once( 'campaign-functions/time-utilities.php' );
require_once( 'campaign-functions/send-email-utility.php' );
require_once( 'campaign-functions/cron-schedule.php' );
require_once( 'post-type/loader.php' );
require_once( 'classes/dt-campaign-fuel.php' );
require_once( 'classes/dt-campaign-global-settings.php' );
require_once( 'classes/dt-porch-settings.php' );
require_once( 'classes/dt-campaign-languages.php' );
require_once( 'classes/dt-porch-theme.php' );
require_once( 'admin/dt-porch-admin-tab-base.php' );
require_once( 'classes/dt-porch-selector.php' );
require_once( 'porches/loader.php' );
require_once( 'classes/dt-campaign-landing-settings.php' );
require_once( 'magic-links/campaign-magic-link.php' );
require_once( 'magic-links/ongoing/ongoing.php' );
require_once( 'magic-links/subscription-management/subscription-management.php' );
require_once( 'magic-links/campaign-resend-email/magic-link-post-type.php' );
require_once( 'magic-links/prayer-fuel/magic-prayer-fuel.php' );
if ( is_admin() ) {
require_once( __DIR__ . '/admin/config-required-plugins.php' );
require_once __DIR__ . '/admin/dt-porch-admin-tab-general-settings.php';
require_once __DIR__ . '/admin/admin-menu-and-tabs.php'; // adds starter admin page and section for plugin
require_once __DIR__ . '/admin/admin-media-tab.php';
DT_Prayer_Campaigns_Menu::instance();
}
// $lang = dt_campaign_get_current_lang( '' );
// if ( !empty( $lang ) ){
// dt_campaign_add_lang_to_cookie( $lang );
// dt_campaign_set_translation( $lang );
// }
if ( is_admin() ) { // adds links to the plugin description area in the plugin admin list.
add_filter( 'plugin_row_meta', [ $this, 'plugin_description_links' ], 10, 4 );
}
if ( !is_admin() ) {
require_once( plugin_dir_path( __FILE__ ) . '/parts/components.php' );
}
}
private function define_porch_constants() {
if ( ! defined( 'CAMPAIGN_LANDING_ROOT' ) ) {
define( 'CAMPAIGN_LANDING_ROOT', 'prayer' ); // Alphanumeric key. Use underscores not hyphens. No special characters.
}
if ( ! defined( 'CAMPAIGN_LANDING_TYPE' ) ) {
define( 'CAMPAIGN_LANDING_TYPE', 'fuel' ); // Alphanumeric key. Use underscores not hyphens. No special characters. Must be less than 20 characters
}
if ( ! defined( 'CAMPAIGN_LANDING_META_KEY' ) ) {
define( 'CAMPAIGN_LANDING_META_KEY', CAMPAIGN_LANDING_ROOT . '_' . CAMPAIGN_LANDING_TYPE . '_magic_key' ); // Alphanumeric key. Use underscores not hyphens. No special characters. Must be less than 20 characters
}
if ( ! defined( 'CAMPAIGN_LANDING_POST_TYPE' ) ) {
define( 'CAMPAIGN_LANDING_POST_TYPE', 'landing' ); // Alphanumeric key. Use underscores not hyphens. No special characters. Must be less than 20 characters
}
if ( ! defined( 'CAMPAIGN_LANDING_POST_TYPE_SINGLE' ) ) {
define( 'CAMPAIGN_LANDING_POST_TYPE_SINGLE', 'Prayer Fuel' ); // Alphanumeric key. Use underscores not hyphens. No special characters. Must be less than 20 characters
}
if ( ! defined( 'CAMPAIGN_LANDING_POST_TYPE_PLURAL' ) ) {
define( 'CAMPAIGN_LANDING_POST_TYPE_PLURAL', 'Prayer Fuel' ); // Alphanumeric key. Use underscores not hyphens. No special characters. Must be less than 20 characters
}
}
/**
* Filters the array of row meta for each/specific plugin in the Plugins list table.
* Appends additional links below each/specific plugin on the plugins page.
*/
public function plugin_description_links( $links_array, $plugin_file_name, $plugin_data, $status ) {
if ( strpos( $plugin_file_name, basename( __FILE__ ) ) ) {
$links_array[] = '<a href="https://disciple.tools/plugins/prayer-campaigns/">Disciple.Tools Prayer Campaigns</a>';
}
return $links_array;
}
/**
* Method that runs only when the plugin is activated.
*
* @since 0.1
* @access public
* @return void
*/
public static function activation() {
// add elements here that need to fire on activation
}
/**
* Method that runs only when the plugin is deactivated.
*
* @since 0.1
* @access public
* @return void
*/
public static function deactivation() {
// add functions here that need to happen on deactivation
delete_option( 'dismissed-disciple-tools-prayer-campaigns' );
}
/**
* Loads the translation files.
*
* @since 0.1
* @access public
* @return void
*/
public function i18n() {
$domain = 'disciple-tools-prayer-campaigns';
load_plugin_textdomain( $domain, false, trailingslashit( dirname( plugin_basename( __FILE__ ) ) ). 'languages' );
}
/**
* Magic method to output a string if trying to use the object as a string.
*
* @since 0.1
* @access public
* @return string
*/
public function __toString() {
return 'disciple-tools-prayer-campaigns';
}
/**
* Magic method to keep the object from being cloned.
*
* @since 0.1
* @access public
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, 'Whoah, partner!', '0.1' );
}
/**
* Magic method to keep the object from being unserialized.
*
* @since 0.1
* @access public
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, 'Whoah, partner!', '0.1' );
}
/**
* Magic method to prevent a fatal error when calling a method that doesn't exist.
*
* @param string $method
* @param array $args
* @return null
* @since 0.1
* @access public
*/
public function __call( $method = '', $args = array() ) {
_doing_it_wrong( 'dt_prayer_campaigns::' . esc_html( $method ), 'Method does not exist.', '0.1' );
unset( $method, $args );
return null;
}
}
/**
* Run migrations after theme is loaded
*/
add_action( 'init', function (){
try {
require_once( plugin_dir_path( __FILE__ ) . '/admin/class-migration-engine.php' );
DT_Prayer_Campaigns_Migration_Engine::migrate( DT_Prayer_Campaigns_Migration_Engine::$migration_number );
} catch ( Throwable $e ) {
new WP_Error( 'migration_error', 'Migration engine failed to migrate.' );
}
DT_Prayer_Campaigns_Migration_Engine::display_migration_and_lock();
} );
// Register activation hook.
register_activation_hook( __FILE__, [ 'DT_Prayer_Campaigns', 'activation' ] );
register_deactivation_hook( __FILE__, [ 'DT_Prayer_Campaigns', 'deactivation' ] );
if ( ! function_exists( 'dt_prayer_campaigns_hook_admin_notice' ) ) {
function dt_prayer_campaigns_hook_admin_notice() {
global $dt_prayer_campaigns_required_dt_theme_version;
$wp_theme = wp_get_theme();
$current_version = $wp_theme->version;
$message = "'Disciple.Tools - Subscriptions' plugin requires 'Disciple.Tools' theme to work. Please activate 'Disciple.Tools' theme or make sure it is latest version.";
if ( $wp_theme->get_template() === 'disciple-tools-theme' ){
$message .= ' ' . sprintf( esc_html( 'Current Disciple.Tools version: %1$s, required version: %2$s' ), esc_html( $current_version ), esc_html( $dt_prayer_campaigns_required_dt_theme_version ) );
}
// Check if it's been dismissed...
if ( ! get_option( 'dismissed-disciple-tools-prayer-campaigns', false ) ) { ?>
<div class="notice notice-error notice-disciple-tools-prayer-campaigns is-dismissible" data-notice="disciple-tools-prayer-campaigns">
<p><?php echo esc_html( $message );?></p>
</div>
<script>
jQuery(function($) {
$( document ).on( 'click', '.notice-disciple-tools-prayer-campaigns .notice-dismiss', function () {
$.ajax( ajaxurl, {
type: 'POST',
data: {
action: 'dismissed_notice_handler',
type: 'disciple-tools-prayer-campaigns',
security: '<?php echo esc_html( wp_create_nonce( 'wp_rest_dismiss' ) ) ?>'
}
})
});
});
</script>
<?php }
}
}
add_action( 'plugins_loaded', function (){
/**
* Plugin Releases and updates
*/
$disable = isset( $_POST['wppusher'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( !$disable && is_admin() ){
require_once( __DIR__ . '/admin/plugin-update-checker/plugin-update-checker.php' );
if ( class_exists( '\YahnisElsts\PluginUpdateChecker\v5\PucFactory' ) ) {
$hosted_json = 'https://raw.githubusercontent.com/DiscipleTools/disciple-tools-prayer-campaigns/master/version-control.json';
PucFactory::buildUpdateChecker(
$hosted_json,
__FILE__,
'disciple-tools-prayer-campaigns' // change this token
);
}
}
});
/**
* AJAX handler to store the state of dismissible notices.
*/
if ( ! function_exists( 'dt_hook_ajax_notice_handler' ) ){
function dt_hook_ajax_notice_handler(){
check_ajax_referer( 'wp_rest_dismiss', 'security' );
if ( isset( $_POST['type'] ) ){
$type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
update_option( 'dismissed-' . $type, true );
}
}
}