-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancel-subscription-for-give.php
68 lines (54 loc) · 2.67 KB
/
cancel-subscription-for-give.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
<?php
/**
* plugin name: Give - Cancel Subscription
* description: Ask reason before cancelling the Give Recurring Donation.
* Author: Mehul Gohil
* Version: 1.0.0
* text domain: cancel-subscription-for-give
*/
// denied Direct Access
if( !defined('ABSPATH') ) exit('Don\'t try to rob');
// Basic Plugin Constants
if ( ! defined( 'GIVE_RECURRING_CANCELLATION_VERSION' ) ) {
define( 'GIVE_RECURRING_CANCELLATION_VERSION', '0.0.3' );
}
if ( ! defined( 'GIVE_RECURRING_CANCELLATION_PLUGIN_FILE' ) ) {
define( 'GIVE_RECURRING_CANCELLATION_PLUGIN_FILE', __FILE__ );
}
if( ! defined( 'GIVE_RECURRING_CANCELLATION_DIR' ) ){
define('GIVE_RECURRING_CANCELLATION_DIR',plugin_dir_path( GIVE_RECURRING_CANCELLATION_PLUGIN_FILE ) );
}
if( ! defined( 'GIVE_RECURRING_CANCELLATION_URL' ) ){
define('GIVE_RECURRING_CANCELLATION_URL',plugin_dir_url( GIVE_RECURRING_CANCELLATION_PLUGIN_FILE ) );
}
if( !defined( 'GIVE_RECURRING_CANCELLATION_INCLUDE_DIR') ){
define('GIVE_RECURRING_CANCELLATION_INCLUDE_DIR', GIVE_RECURRING_CANCELLATION_DIR .'/includes' );
}
// Check If give-recurring is active
add_action( 'admin_notices', 'give_validate_recurring_activation' );
// Callback for give recurring validation
function give_validate_recurring_activation(){
if( ! class_exists ('Give_Recurring') ){
echo "<div class='error'><p>". sprintf('<strong>Activation Error:</strong> You must have <a href="%1$s"> Give - Recurring Donations</a> installed or active.', 'https://givewp.com/addons/recurring-donations/') . "</p></div>";
}
}
// Override Cancel Subscription Template
function csfg_override_shortcode_subscription_template( $paths ){
$paths[49] = GIVE_RECURRING_CANCELLATION_DIR . '/templates';
return $paths;
}
add_filter( 'give_template_paths', 'csfg_override_shortcode_subscription_template' );
// Enqueue Style and Subscriptions for the Confirmation Modal
function csfg_scripts(){
// Resgister Style
wp_register_style('give-cancel-subscription', GIVE_RECURRING_CANCELLATION_URL . '/assets/css/cancel-subscription-confirmation.css', array(), GIVE_RECURRING_CANCELLATION_VERSION );
// Load Style on Page
wp_enqueue_style('give-cancel-subscription');
// Register Script
wp_register_script('give-cancel-subscription', GIVE_RECURRING_CANCELLATION_URL . '/assets/js/cancel-subscription-confirmation.js', array(), GIVE_RECURRING_CANCELLATION_VERSION, true );
// Load JS on page
wp_enqueue_script('give-cancel-subscription');
}
add_action( 'wp_enqueue_scripts', 'csfg_scripts', 15 );
// Include Files
include_once GIVE_RECURRING_CANCELLATION_INCLUDE_DIR . '/process-cancel-subscription.php';