forked from wc-donation/wc-donation-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wc-donation-platform.php
executable file
·187 lines (160 loc) · 6.77 KB
/
wc-donation-platform.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
<?php
/*
* Plugin Name: Donation Platform for WooCommerce: Fundraising & Donation Management
* Plugin URI: https://wcdp.jonh.eu/
* Description: Donation Platform for WooCommerce unlocks the power of WooCommerce for your online fundraising & crowdfunding.
* Author: Jonas Höbenreich
* Version: 1.3.2
* Author URI: https://www.jonh.eu/
* Plugin URI: https://wcdp.jonh.eu/
* License: GNU General Public License v2.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: wc-donation-platform
* Domain Path: /languages
* WC requires at least: 4.0.0
* WC tested up to: 8.5.2
* Requires at least: 5.8
*/
if(!defined('ABSPATH')) exit;
define( 'WCDP_DIR', dirname(__FILE__).'/' );
define( 'WCDP_DIR_URL', plugin_dir_url( __FILE__ ) );
const WCDP_VERSION = '1.3.2';
/**
* Check if WooCommerce is active
*/
if (!function_exists('is_woocommerce_active')){
function is_woocommerce_active(): bool
{
$active_plugins = (array) get_option('active_plugins', array());
if(is_multisite()){
$active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
}
return in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins) || class_exists('WooCommerce');
}
}
if ( !class_exists( 'WCDP' ) ) {
/**
* Class WCDP
*/
class WCDP {
public static $wc_minimum_supported_version = '4.0.0';
/**
* WCDP constructor.
*/
public function __construct() {
$this->includes();
new WCDP_Hooks();
new WCDP_Product_Settings();
new WCDP_Form();
new WCDP_Progress();
new WCDP_Fee_Recovery();
new WCDP_Leaderboard();
new WCDP_Feedback();
WCDP_Integrator::init();
//Load textdomain
add_action( 'init', function() {
load_plugin_textdomain( 'wc-donation-platform', false, WCDP_DIR . '/languages' );
} );
//Add plugin action links
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array(__CLASS__, 'plugin_action_links') );
add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_row_meta' ), 10, 2 );
}
/**
* Include required files
*/
private function includes() {
//WCDP Donation Form
include_once 'includes/class-wcdp-form.php';
//WC Hooks
include_once 'includes/class-wcdp-hooks.php';
//Adapt products to be donable
include_once 'includes/class-wcdp-product-settings.php';
//WooCommerce settings tab
include_once 'includes/class-wcdp-general-settings.php';
//Fundraising Progress
include_once 'includes/class-wcdp-progress.php';
//Fee Recovery
include_once 'includes/class-wcdp-fee-recovery.php';
//Integration with other Extensions
include_once 'includes/integrations/class-wcdp-integrator.php';
//Deactivation survey & Feedback survey
include_once 'includes/class-wcdp_feedback.php';
//Leaderboard
include_once 'includes/class-wcdp_leaderboard.php';
}
/**
* Called when WooCommerce is inactive or running an unsupported version to display an inactive notice
*
* @since 1.0
*/
public static function wcdp_inactive_notice() {
if ( current_user_can( 'activate_plugins' ) ) {
$admin_notice_content = '';
if ( ! is_woocommerce_active() ) {
$admin_notice_content = esc_html__( 'Donation Platform for WooCommerce requires WooCommerce to be installed & activated.', 'wc-donation-platform' );
} elseif ( version_compare( get_option( 'woocommerce_db_version' ), self::$wc_minimum_supported_version, '<' ) ) {
// translators: %s required WC version
$admin_notice_content = sprintf( esc_html__( 'Donation Platform for WooCommerce is inactive. This version of Donation Platform for WooCommerce requires WooCommerce %s or newer. Please update WooCommerce and run all database migrations.', 'wc-donation-platform' ), self::$wc_minimum_supported_version );
}
if ( $admin_notice_content ) {
printf( '<div class="notice notice-error"><p>%s</p></div>', $admin_notice_content );
}
}
}
/**
* Adds plugin action links
* @param $links array plugin action links before filtering.
* @return array Filtered links.
*/
public static function plugin_action_links(array $links): array
{
$plugin_links = array(
'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=wc-donation-platform' ) . '" aria-label="' . esc_attr__( 'View WCDP settings', 'wc-donation-platform' ) . '">' . esc_html__( 'Settings', 'wc-donation-platform' ) . '</a>',
);
return array_merge( $plugin_links, $links );
}
/**
* Show row meta on the plugin screen.
*
* @param mixed $links Plugin Row Meta.
* @param mixed $file Plugin Base file.
*
* @return array
*/
public static function plugin_row_meta( $links, $file ): array
{
if (strpos( $file, basename(__FILE__) )) {
$row_meta = array(
'docs' => '<a href="' . esc_url( 'https://wcdp.jonh.eu/documentation/' ) . '" aria-label="' . esc_attr__( 'View Documentation of Donation Platform for WooCommerce', 'wc-donation-platform' ) . '">' . esc_html__( 'Documentation', 'wc-donation-platform' ) . '</a>',
);
return array_merge( $links, $row_meta );
} else {
return $links;
}
}
}
}
/**
* Check if WooCommerce is active and at the required minimum version, and if it isn't, disable WCDP.
*
* @since 1.0
*/
if( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_db_version' ), WCDP::$wc_minimum_supported_version, '<' )) {
add_action( 'admin_notices', 'WCDP::wcdp_inactive_notice' );
return;
} else {
add_action('plugins_loaded', function () {
new WCDP();
});
}
/**
* declare
* - compatibility with High performance order storage
* - incompatibility with new WooCommerce Checkout Block
*/
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, false );
}
} );