Repository navigation
Expand file tree
/
Copy pathgiftflow.php
More file actions
382 lines (339 loc) · 12.4 KB
/
Copy pathgiftflow.php
File metadata and controls
382 lines (339 loc) · 12.4 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* Plugin Name: GiftFlow – Donation & Fundraising
* Plugin URI: https://giftflow.beplus-agency.cloud/
* Description: The all-in-one fundraising and donation management solution for WordPress. GiftFlow empowers nonprofits and organizations to easily accept donations, run unlimited campaigns, and manage donor relationships—all with a modern interface, robust analytics, and seamless payment integrations (Stripe, PayPal, bank transfer). Designed for growth, security, and extensibility, GiftFlow offers powerful tools—even no coding required—to launch, track, and optimize your giving programs.
* Version: 1.1.11
* Author: Beplus
* Author URI: https://beplusthemes.com/
* Text Domain: giftflow
* Domain Path: /languages
* Requires at least: 6.0
* Requires PHP: 7.4
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @package GiftFlow
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Plugin version and path constants.
*/
define( 'GIFTFLOW_VERSION', '1.1.11' );
define( 'GIFTFLOW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'GIFTFLOW_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'GIFTFLOW_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
/*
* Load Composer autoloaders.
*
* 1. vendor/autoload.php — PSR-4 for src/ classes (development).
* 2. vendor-prefixed/autoload.php — Strauss-prefixed Stripe SDK (production).
*
* In production builds, vendor/ is excluded. A fallback autoloader
* mirrors the PSR-4 mapping from composer.json for the src/ directory.
*/
$vendor_autoload = GIFTFLOW_PLUGIN_DIR . 'vendor/autoload.php';
if ( file_exists( $vendor_autoload ) ) {
require_once $vendor_autoload;
} else {
spl_autoload_register(
function ( string $class_name ) {
$mappings = array(
'GiftFlow\\Patterns\\' => 'includes/patterns/',
'GiftFlow\\' => 'src/',
);
foreach ( $mappings as $prefix => $dir ) {
$prefix_len = strlen( $prefix );
if ( strncmp( $class_name, $prefix, $prefix_len ) !== 0 ) {
continue;
}
$relative = substr( $class_name, $prefix_len );
$file = GIFTFLOW_PLUGIN_DIR . $dir . str_replace( '\\', '/', $relative ) . '.php';
if ( file_exists( $file ) ) {
require_once $file;
return;
}
}
}
);
}
$prefixed_autoload = GIFTFLOW_PLUGIN_DIR . 'vendor-prefixed/autoload.php';
if ( ! file_exists( $prefixed_autoload ) ) {
add_action(
'admin_notices',
function () {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'GiftFlow requires Composer dependencies to be installed. Please run "composer run build" in the plugin directory.', 'giftflow' )
);
}
);
return;
}
require_once $prefixed_autoload;
/**
* Remove legacy block registration actions to prevent duplicate
* "Block type is already registered" notices. BlockRegistry in
* src/Blocks/BlockRegistry.php handles actual registration at priority 9.
*
* @return void
*/
function giftflow_unhook_legacy_block_registrations(): void {
$legacy_block_funcs = array(
'giftflow_donation_button_block',
'giftflow_campaign_status_bar_block',
'giftflow_campaign_single_content_block',
'giftflow_campaign_single_images_block',
'giftflow_campaigns_grid_block',
'giftflow_donor_account_block',
'giftflow_share_block',
'giftflow_thank_donor_block',
);
foreach ( $legacy_block_funcs as $func ) {
remove_action( 'init', $func );
}
}
/**
* Legacy file loader (backward compatibility).
*
* Loads all classes under includes/ and admin/ that have not yet been
* migrated to src/ PSR-4 autoloading.
*/
function giftflow_load_files() {
// Core files.
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-base.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-loader.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-field.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-role.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-ajax.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-donations.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-campaigns.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-block-template.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-logger.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-donation-event-history.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/core/class-wp-block-custom-hooks.php';
// Blocks are now registered via GiftFlow\Blocks\BlockRegistry (src/Blocks/BlockRegistry.php)
// which auto-discovers blocks/*/block.json. The legacy block loader is kept for
// helper functions defined in block.php files (templates depend on these).
// Block registration from legacy files is removed to prevent duplicates.
require_once GIFTFLOW_PLUGIN_DIR . 'blocks/index.php';
giftflow_unhook_legacy_block_registrations();
require_once GIFTFLOW_PLUGIN_DIR . 'includes/common.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/hooks.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/mail.php';
// Payment gateways.
require_once GIFTFLOW_PLUGIN_DIR . 'includes/gateways/class-gateway-base.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/gateways/class-stripe.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/gateways/class-paypal.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/gateways/class-direct-bank-transfer.php';
// Admin files.
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/dashboard.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/class-export.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/post-types/class-base-post-type.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/post-types/class-donation.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/post-types/class-donor.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/post-types/class-campaign.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/settings.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/api.php';
// Meta boxes.
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/meta-boxes/class-base-meta-box.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/meta-boxes/class-donation-transaction-meta.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/meta-boxes/class-donor-contact-meta.php';
require_once GIFTFLOW_PLUGIN_DIR . 'admin/includes/meta-boxes/class-campaign-details-meta.php';
// Frontend files.
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/class-shortcodes.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/class-forms.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/class-template.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/campaign-single-template-hooks.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/campaign-taxonomy-archive-template-hooks.php';
require_once GIFTFLOW_PLUGIN_DIR . 'includes/frontend/campaigns-page-template-hooks.php';
$additional_files = apply_filters( 'giftflow_load_files', array() );
if ( ! empty( $additional_files ) && is_array( $additional_files ) ) {
foreach ( $additional_files as $file ) {
if ( file_exists( $file ) ) {
require_once $file;
}
}
}
}
// Preload legacy files so classes are available for activation/deactivation.
giftflow_load_files();
/**
* Boot the plugin via the new container-based architecture.
*
* The Plugin class internally calls giftflow_load_files() for
* backward compatibility.
*
* @return \GiftFlow\Core\Plugin
*/
function giftflow_boot() {
static $plugin = null;
if ( null === $plugin ) {
$plugin = new \GiftFlow\Core\Plugin();
$plugin->boot();
}
return $plugin;
}
/**
* Initialize the plugin on plugins_loaded.
*
* @return void
*/
function giftflow_init() {
giftflow_boot();
}
add_action( 'plugins_loaded', 'giftflow_init' );
/**
* Activation / Deactivation hooks.
*/
register_activation_hook( __FILE__, 'giftflow_activate' );
/**
* Plugin activation handler.
*
* @return void
*/
function giftflow_activate() {
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die(
esc_html__( 'GiftFlow requires PHP 7.4 or higher.', 'giftflow' ),
'Plugin Activation Error',
array( 'back_link' => true )
);
}
$plugin = new \GiftFlow\Core\Plugin();
$plugin->activate();
}
register_deactivation_hook( __FILE__, 'giftflow_deactivate' );
/**
* Plugin deactivation handler.
*
* @return void
*/
function giftflow_deactivate() {
delete_option( 'giftflow_first_activation_notice_dismissed' );
flush_rewrite_rules();
$plugin = new \GiftFlow\Core\Plugin();
$plugin->deactivate();
}
/**
* Add admin bar item.
*/
add_action( 'admin_bar_menu', 'giftflow_admin_bar_item', 100 );
/**
* Add admin bar items.
*
* @param \WP_Admin_Bar $wp_admin_bar The admin bar object.
* @return void
*/
function giftflow_admin_bar_item( $wp_admin_bar ) {
if ( ! current_user_can( 'manage_options' ) ) {
// Do not add admin bar items if user is not allowed.
return;
}
// Add parent item.
$args = array(
'id' => 'giftflow_admin_bar_item',
'title' => esc_html__( 'Gift Flow Dashboard', 'giftflow' ),
'href' => admin_url( 'admin.php?page=giftflow-dashboard' ), // or any URL.
'meta' => array(
'class' => 'giftflow_admin_bar_item',
'title' => esc_html__( 'Go to Gift Flow Dashboard', 'giftflow' ), // Tooltip.
),
);
$wp_admin_bar->add_node( $args );
$wp_admin_bar->add_node(
array(
'id' => 'giftflow_admin_bar_item_donations',
'title' => esc_html__( 'Donations', 'giftflow' ),
'href' => admin_url( 'edit.php?post_type=donation' ),
'parent' => 'giftflow_admin_bar_item',
)
);
$wp_admin_bar->add_node(
array(
'id' => 'giftflow_admin_bar_item_donors',
'title' => esc_html__( 'Donors', 'giftflow' ),
'href' => admin_url( 'edit.php?post_type=donor' ),
'parent' => 'giftflow_admin_bar_item',
)
);
$wp_admin_bar->add_node(
array(
'id' => 'giftflow_admin_bar_item_campaigns',
'title' => esc_html__( 'Campaigns', 'giftflow' ),
'href' => admin_url( 'edit.php?post_type=campaign' ),
'parent' => 'giftflow_admin_bar_item',
)
);
// Add child item.
$wp_admin_bar->add_node(
array(
'id' => 'giftflow_admin_bar_item_settings',
'title' => esc_html__( 'Settings', 'giftflow' ),
'href' => admin_url( 'admin.php?page=giftflow-settings' ),
'parent' => 'giftflow_admin_bar_item',
)
);
}
/**
* Add admin notice on first activation to suggest viewing documentation.
*/
add_action( 'admin_init', 'giftflow_add_first_activation_notice' );
/**
* Add admin notice on first activation to suggest viewing documentation.
*/
function giftflow_add_first_activation_notice() {
$is_giftflow_help_page = false;
if (
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
isset( $_GET['page'], $_GET['tab'] )
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.PHP.YodaConditions.NotYoda
&& sanitize_text_field( wp_unslash( $_GET['page'] ) ) === 'giftflow-dashboard'
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.PHP.YodaConditions.NotYoda
&& sanitize_text_field( wp_unslash( $_GET['tab'] ) ) === 'help'
) {
$is_giftflow_help_page = true;
}
// Show admin notice on first activation to suggest viewing documentation.
if ( is_admin()
&& ! get_option( 'giftflow_first_activation_notice_dismissed', false )
&& ! $is_giftflow_help_page
) {
add_action(
'admin_notices',
function () {
// Only show to users who can manage options.
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// Prepare URL to documentation. You may want to change this as needed.
$docs_url = esc_url( admin_url( 'admin.php?page=giftflow-dashboard&tab=help' ) );
?>
<div
class="notice notice-info is-dismissible giftflow-first-activation-notice"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'giftflow_dismiss_notice' ) ); ?>">
<p>
<?php esc_html_e( 'It looks like you\'re using GiftFlow for the first time. We highly recommend visiting the documentation page to quickly get started and make the most out of your donation campaigns.', 'giftflow' ); ?>
<a
href="<?php echo esc_url( $docs_url ); ?>"
target="_blank" >
<?php esc_html_e( 'View documentation here.', 'giftflow' ); ?>
</a>
</p>
</div>
<?php
}
);
add_action(
'wp_ajax_giftflow_dismiss_first_activation_notice',
function () {
check_ajax_referer( 'giftflow_dismiss_notice', '_giftflow_nonce' );
update_option( 'giftflow_first_activation_notice_dismissed', true );
wp_send_json_success();
}
);
}
}