PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.3.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.3.0
1.6.1 1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / admin / admin.php

admin.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.3.0, at inc/admin/admin.php

624 lines 21.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Interface
4 *
5 * @package SureDonation
6 */
7
8 namespace SureDonation\Inc\Admin;
9
10 use SureDonation\Inc\Helper;
11 use SureDonation\Inc\Onboarding;
12 use SureDonation\Inc\Pdf\Pdf_Utils;
13 use SureDonation\Inc\Payments\Payment_Helper;
14 use SureDonation\Inc\Payments\PayPal\PayPal_Helper;
15 use SureDonation\Inc\Payments\Stripe\Stripe_Helper;
16 use SureDonation\Inc\Traits\Get_Instance;
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Admin class.
25 *
26 * @since 0.0.1
27 */
28 class Admin {
29 use Get_Instance;
30
31 /**
32 * Constructor.
33 *
34 * @since 0.0.1
35 */
36 public function __construct() {
37 add_action( 'admin_menu', [ $this, 'register_menu' ] );
38 add_action( 'admin_menu', [ $this, 'hide_forms_submenu' ], 999 );
39 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
40 add_action( 'admin_init', [ $this, 'redirect_cpt_listings' ] );
41 add_action( 'admin_init', [ $this, 'register_privacy_policy_content' ] );
42 add_action( 'admin_init', [ $this, 'register_react_notices' ], 5 );
43 }
44
45 /**
46 * Register the payment-gateway React admin notice.
47 *
48 * Bridges the payment/test-mode nudges into the React admin app via
49 * Notice_Manager. Runs on admin_init (priority 5) so the notice is
50 * registered before admin_enqueue_scripts localizes the data for React.
51 *
52 * Two mutually-exclusive states, mirroring the existing PHP/front-end
53 * notice chain:
54 * - No gateway connected -> prompt to configure a gateway.
55 * - Connected, but site in test mode -> prompt to switch to live mode.
56 * When a gateway is connected and the site is live, no notice shows.
57 *
58 * Capability-gated to manage_options; the data is only consumed on the
59 * SureDonation admin pages, where the React app is enqueued.
60 *
61 * Hooked - admin_init (priority 5)
62 *
63 * @since 1.3.0
64 * @return void
65 */
66 public function register_react_notices() {
67 if ( ! current_user_can( 'manage_options' ) ) {
68 return;
69 }
70
71 if ( ! Payment_Helper::is_any_gateway_connected() ) {
72 Notice_Manager::register_notice(
73 [
74 'id' => 'sd-configure-gateway',
75 'variant' => 'error',
76 // translators: the <a></a> tags wrap the inline link text and must be kept intact.
77 'message' => __( 'No payment gateway is connected, so your forms cannot accept donations yet. <a>Set up a payment gateway</a> to get started.', 'suredonation' ),
78 'link' => [
79 // Deep-link to the gateway connect screen, matching the dashboard Quick Access entry.
80 'url' => Payment_Helper::get_settings_url( 'stripe' ),
81 ],
82 'event' => Analytics::TRACKED_EVENTS['configure_gateway'],
83 'dismissible' => false,
84 ]
85 );
86 return;
87 }
88
89 if ( Stripe_Helper::is_stripe_connected() && ! Stripe_Helper::is_webhook_configured() ) {
90 Notice_Manager::register_notice(
91 [
92 'id' => 'sd-webhook-not-configured',
93 'variant' => 'error',
94 // translators: the <a></a> tags wrap the inline link text and must be kept intact.
95 'message' => __( 'Webhooks keep SureDonation in sync with Stripe by automatically updating donation and subscription data. Please <a>configure</a> the webhook.', 'suredonation' ),
96 'link' => [
97 'url' => Payment_Helper::get_settings_url( 'stripe' ),
98 ],
99 'event' => Analytics::TRACKED_EVENTS['webhook'],
100 'dismissible' => false,
101 ]
102 );
103 return;
104 }
105
106 if ( 'test' === Payment_Helper::get_payment_mode() ) {
107 $settings_url = Payment_Helper::get_settings_url();
108 Notice_Manager::register_notice(
109 [
110 'id' => 'sd-test-mode-react',
111 'variant' => 'error',
112 // translators: the <a></a> tags wrap the inline link text and must be kept intact.
113 'message' => __( 'SureDonation is in test mode, so no real donations are being processed. <a>Switch to live mode</a> to start accepting them.', 'suredonation' ),
114 'link' => [
115 'url' => $settings_url,
116 ],
117 'event' => Analytics::TRACKED_EVENTS['test_mode'],
118 'dismissible' => false,
119 ]
120 );
121 }
122 }
123
124 /**
125 * Register suggested privacy-policy text for the plugin's data transfers.
126 *
127 * Surfaces the Phone field's automatic country detection (which sends the
128 * visitor's IP to ipapi.co) in the WordPress Privacy Policy Guide
129 * (Settings → Privacy → Policy Guide) so site owners can disclose it in
130 * their own policy. This only suggests text to admins — it publishes
131 * nothing and is not shown to donors.
132 *
133 * @since 1.1.1
134 * @return void
135 */
136 public function register_privacy_policy_content() {
137 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
138 return;
139 }
140
141 $content = __( 'When a Phone field with automatic country detection is used, this site sends the visitor’s IP address to a third-party service (ipapi.co) to determine their country code. The IP address is not stored for this purpose; the resulting country code is cached temporarily. Automatic detection can be disabled per Phone field, or site-wide via the “suredonation_phone_geo_enabled” filter.', 'suredonation' );
142
143 wp_add_privacy_policy_content( 'SureDonation', wp_kses_post( wpautop( $content ) ) );
144 }
145
146 /**
147 * Redirect the default CPT list screens for suredonation_form and
148 * suredonation_cmpgn to their corresponding plugin pages.
149 *
150 * For the form listing, attempt to resolve the originating campaign
151 * from the referer (the "back" arrow on the form editor sends the
152 * user here) and redirect to that campaign's single view.
153 *
154 * @return void
155 * @since 1.0.0
156 */
157 public function redirect_cpt_listings() {
158 global $pagenow;
159
160 if ( 'edit.php' !== $pagenow ) {
161 return;
162 }
163
164 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading post_type from query, no state mutation.
165 $post_type = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : '';
166
167 if ( 'suredonation_form' === $post_type ) {
168 $campaign_id = $this->resolve_campaign_id_from_referer();
169 $target = $campaign_id
170 ? admin_url( 'admin.php?page=suredonation#/campaigns/' . $campaign_id )
171 : admin_url( 'admin.php?page=suredonation#/campaigns' );
172
173 wp_safe_redirect( $target );
174 exit;
175 }
176
177 if ( 'suredonation_cmpgn' === $post_type ) {
178 wp_safe_redirect( admin_url( 'admin.php?page=suredonation#/campaigns' ) );
179 exit;
180 }
181 }
182
183 /**
184 * Resolve the campaign ID from the referer when the form list page
185 * is reached from the form editor's "back" button.
186 *
187 * @return int Campaign ID, or 0 when it cannot be determined.
188 * @since 1.0.0
189 */
190 private function resolve_campaign_id_from_referer() {
191 $referer = wp_get_referer();
192 if ( ! $referer ) {
193 return 0;
194 }
195
196 $parts = wp_parse_url( $referer );
197 if ( empty( $parts['query'] ) ) {
198 return 0;
199 }
200
201 $query = [];
202 parse_str( $parts['query'], $query );
203
204 if ( empty( $query['post'] ) || ! is_numeric( $query['post'] ) ) {
205 return 0;
206 }
207
208 $form_id = absint( $query['post'] );
209 if ( 'suredonation_form' !== get_post_type( $form_id ) ) {
210 return 0;
211 }
212
213 $campaign_id = get_post_meta( $form_id, '_suredonation_campaign_id', true );
214 if ( ! is_numeric( $campaign_id ) ) {
215 return 0;
216 }
217 return absint( $campaign_id );
218 }
219
220 /**
221 * Enqueue admin scripts and styles.
222 *
223 * @param string $hook Current admin page hook.
224 * @return void
225 * @since 0.0.1
226 */
227 public function enqueue_admin_scripts( $hook ) {
228 // Only load on our plugin pages.
229 if ( strpos( $hook, 'suredonation' ) === false ) {
230 return;
231 }
232
233 // Onboarding gets its own lean bundle — bail before enqueuing the
234 // main admin app on that page.
235 if ( false !== strpos( $hook, Onboarding::PAGE_SLUG ) ) {
236 $this->enqueue_onboarding_assets();
237 return;
238 }
239
240 $asset_file = SUREDONATION_DIR . 'assets/build/admin.asset.php';
241
242 if ( ! file_exists( $asset_file ) ) {
243 return;
244 }
245
246 $asset = include $asset_file;
247
248 // Enqueue WordPress editor for TinyMCE support.
249 wp_enqueue_editor();
250
251 // Enqueue the media library so the campaign image picker can open it.
252 wp_enqueue_media();
253
254 // Enqueue editor buttons style (needed for TinyMCE icons).
255 wp_enqueue_style( 'editor-buttons' );
256
257 // Enqueue admin app script.
258 wp_enqueue_script(
259 'suredonation-admin',
260 SUREDONATION_URL . 'assets/build/admin.js',
261 $asset['dependencies'],
262 $asset['version'],
263 true
264 );
265
266 // Enqueue admin app styles.
267 wp_enqueue_style(
268 'suredonation-admin',
269 SUREDONATION_URL . 'assets/build/admin.css',
270 [],
271 $asset['version']
272 );
273
274 // The campaign drawer sits at a very high z-index. Lift the media library
275 // above it, and keep the media modal above its OWN backdrop so the picker
276 // is not dimmed by either overlay.
277 wp_add_inline_style(
278 'suredonation-admin',
279 '.media-modal-backdrop{z-index:2147483646 !important;}.media-modal{z-index:2147483647 !important;}'
280 );
281
282 // Load JS translations for the admin app.
283 wp_set_script_translations( 'suredonation-admin', 'suredonation' );
284
285 // Localize script with plugin data.
286 /**
287 * Filters the bootstrap data localized to the SureDonation admin React app
288 * (exposed as window.suredonation_admin). Lets features inject additional
289 * data before it reaches React.
290 *
291 * @since 1.3.0
292 * @param array<string, mixed> $localized_data The admin app bootstrap data.
293 */
294 $localized_data = apply_filters(
295 'suredonation_admin_app_data',
296 [
297 'version' => SUREDONATION_VER,
298 'apiUrl' => rest_url( 'suredonation/v1' ),
299 'nonce' => wp_create_nonce( 'wp_rest' ),
300 'docsURL' => 'https://suredonation.com/docs/',
301 'plugin_url' => SUREDONATION_URL,
302 'site_url' => site_url(),
303 'admin_url' => admin_url(),
304 'is_first_campaign_created' => $this->has_campaigns(),
305 'is_onboarding_completed' => Onboarding::get_instance()->is_completed(),
306 'rotating_plugin_banner' => $this->get_rotating_plugin_banner(),
307 'smart_tags' => Helper::get_smart_tags(),
308 'is_pro_active' => defined( 'SUREDONATION_PRO_VER' ),
309 'pro_plugin_version' => defined( 'SUREDONATION_PRO_VER' ) ? SUREDONATION_PRO_VER : '',
310 'pro_plugin_name' => defined( 'SUREDONATION_PRO_PRODUCT' ) ? SUREDONATION_PRO_PRODUCT : 'SureDonation Pro',
311 'is_license_active' => defined( 'SUREDONATION_PRO_VER' ) && class_exists( 'SureDonationPro\Inc\Licensing\Licensing' ) ? \SureDonationPro\Inc\Licensing\Licensing::is_license_active() : false,
312 'pdf_library_exists' => Pdf_Utils::check_if_library_exists(),
313 'php_version_compatible' => Pdf_Utils::is_php_compatible(),
314 'pdf_nonce' => wp_create_nonce( 'suredonation_pdf_nonce' ),
315 'ajax_url' => admin_url( 'admin-ajax.php' ),
316 'plugin_installer_nonce' => wp_create_nonce( 'updates' ),
317 'plugin_manager_nonce' => wp_create_nonce( 'suredonation_plugin_manager' ),
318 'has_abilities_api' => class_exists( 'WP_Ability' ),
319 'current_user_login' => wp_get_current_user()->user_login,
320 'integrations' => [
321 'sure_triggers' => Helper::get_ottokit_integration(),
322 ],
323 // Bootstrap settings data so the General currency list and the
324 // PayPal connection state render synchronously (no post-mount
325 // fetch flicker). PayPal data is the non-sensitive subset only.
326 'payments' => [
327 'currencies' => Payment_Helper::get_currencies_list(),
328 'paypal' => PayPal_Helper::get_connection_state(),
329 'currency_sign_position' => Payment_Helper::get_currency_sign_position(),
330 'is_any_gateway_connected' => Payment_Helper::is_any_gateway_connected(),
331 'gateway_config_url' => Payment_Helper::get_settings_url( 'stripe' ),
332 ],
333 ]
334 );
335
336 wp_localize_script( 'suredonation-admin', 'suredonation_admin', $localized_data );
337 }
338
339 /**
340 * Register admin menu.
341 *
342 * @return void
343 * @since 0.0.1
344 */
345 public function register_menu() {
346 $menu_slug = 'suredonation';
347
348 // SureDonation mark for the admin menu — single path with evenodd
349 // fill so the inner heart cuts a hole that reveals the sidebar
350 // background (mirrors the pattern used by SureForms).
351 $menu_icon_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><path fill-rule="evenodd" clip-rule="evenodd" d="M0 3.64405C0 1.6315 1.62712 0 3.63425 0H20.2517C22.2588 0 23.886 1.6315 23.886 3.64405V20.3063C23.886 22.3188 22.2588 23.9503 20.2517 23.9503H3.63425C1.62712 23.9503 0 22.3188 0 20.3063V3.64405ZM12.6516 5.79655C14.4525 3.99075 17.3723 3.99075 19.1734 5.79655C20.9742 7.60234 20.9742 10.5301 19.1734 12.3359L17.5686 13.9451C17.2776 14.2368 16.8057 14.2368 16.5147 13.9451C16.2237 13.6533 16.2237 13.1802 16.5147 12.8884L18.1196 11.2793C19.3385 10.0571 19.3385 8.07537 18.1196 6.85312C16.9007 5.6309 14.9243 5.63092 13.7054 6.85312L11.3607 9.20415C11.0701 9.49552 11.0701 9.96791 11.3607 10.2593C11.6513 10.5506 12.1224 10.5506 12.413 10.2593L13.4659 9.20346C13.7569 8.91169 14.2288 8.91169 14.5198 9.20346C14.8107 9.49523 14.8107 9.96828 14.5198 10.26L13.4667 11.3159C12.5942 12.1909 11.1794 12.1909 10.3069 11.3159C9.43429 10.441 9.43429 9.02249 10.3069 8.14757L10.8879 7.56486L10.1781 6.85312C8.95914 5.63089 6.98277 5.63089 5.76382 6.85312C4.54486 8.07537 4.54488 10.0571 5.76382 11.2793L12.6985 18.2326C12.9895 18.5244 12.9895 18.9974 12.6985 19.2892C12.4075 19.581 11.9358 19.581 11.6448 19.2892L4.71008 12.3359C2.90915 10.5301 2.90913 7.60233 4.71008 5.79655C6.51102 3.99075 9.43091 3.99075 11.2318 5.79655L11.9417 6.50827L12.6516 5.79655ZM11.8605 14.9781C12.1515 14.6863 12.6233 14.6863 12.9143 14.9781L14.5397 16.6079C14.8307 16.8996 14.8307 17.3727 14.5397 17.6645C14.2487 17.9562 13.7769 17.9562 13.4859 17.6645L11.8605 16.0347C11.5695 15.7429 11.5695 15.2699 11.8605 14.9781ZM13.6482 13.1856C13.9392 12.8939 14.4109 12.8939 14.7019 13.1856L16.3273 14.8154C16.6183 15.1072 16.6183 15.5802 16.3273 15.872C16.0363 16.1638 15.5645 16.1638 15.2735 15.872L13.6482 14.2422C13.3572 13.9504 13.3572 13.4774 13.6482 13.1856Z" fill="#D1D5DB"/></svg>';
352
353 // Main menu page.
354 add_menu_page(
355 __( 'SureDonation', 'suredonation' ),
356 __( 'SureDonation', 'suredonation' ),
357 'manage_options',
358 $menu_slug,
359 [ $this, 'render_dashboard' ],
360 'data:image/svg+xml;base64,' . base64_encode( $menu_icon_svg ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Building data URI for menu icon.
361 25
362 );
363
364 // Register submenus.
365 $this->register_submenus( $menu_slug );
366 }
367
368 /**
369 * Render dashboard page.
370 *
371 * @return void
372 * @since 0.0.1
373 */
374 public function render_dashboard() {
375 ?>
376 <div id="suredonation-admin-root"></div>
377 <?php
378 }
379
380 /**
381 * Hide the "All Forms" submenu item.
382 *
383 * WordPress automatically adds a submenu for the suredonation_form CPT.
384 * We hide it since forms are managed through campaigns.
385 *
386 * @return void
387 * @since 0.0.1
388 */
389 public function hide_forms_submenu() {
390 remove_submenu_page( 'suredonation', 'edit.php?post_type=suredonation_form' );
391 }
392
393 /**
394 * Check if any campaigns have been created.
395 *
396 * @return bool True if at least one campaign exists.
397 * @since 0.0.1
398 */
399 private function has_campaigns() {
400 $campaigns = get_posts(
401 [
402 'post_type' => 'suredonation_cmpgn',
403 'posts_per_page' => 1,
404 'post_status' => [ 'publish', 'draft', 'private' ],
405 'fields' => 'ids',
406 ]
407 );
408
409 return ! empty( $campaigns );
410 }
411
412 /**
413 * Get rotating plugin banner data.
414 *
415 * @return array<string,mixed>|null Plugin banner data, or null when the plugin is already active.
416 * @since 0.0.1
417 */
418 private function get_rotating_plugin_banner() {
419 // Match SureForms: never nudge a plugin that is already active, so the
420 // dashboard card is hidden once SureRank is activated.
421 $status = $this->get_plugin_status( 'surerank/surerank.php' );
422 if ( 'Activated' === $status ) {
423 return null;
424 }
425
426 // Get SVG logo as base64.
427 $logo_svg = file_get_contents( SUREDONATION_DIR . 'images/surerank.svg' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file read.
428 $logo_data = $logo_svg ? 'data:image/svg+xml;base64,' . base64_encode( $logo_svg ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
429
430 // SureRank plugin data.
431 return [
432 'slug' => 'surerank',
433 'path' => 'surerank/surerank.php',
434 'title' => 'SureRank',
435 'singleLineDescription' => __( 'SEO Made Easy for Your Website', 'suredonation' ),
436 'subtitle' => __( 'Beautiful pages, persuasive content, and custom code in seconds. The possibilities are endless!', 'suredonation' ),
437 'logo' => $logo_data,
438 'status' => $status,
439 ];
440 }
441
442 /**
443 * Get plugin installation status.
444 *
445 * @param string $plugin_file Plugin file path (e.g., 'plugin-folder/plugin-file.php').
446 * @return string Plugin status: 'Activated', 'Installed', or 'Install'.
447 * @since 0.0.1
448 */
449 private function get_plugin_status( $plugin_file ) {
450 if ( ! function_exists( 'is_plugin_active' ) ) {
451 include_once ABSPATH . 'wp-admin/includes/plugin.php';
452 }
453
454 if ( is_plugin_active( $plugin_file ) ) {
455 return 'Activated';
456 }
457
458 $all_plugins = get_plugins();
459 if ( isset( $all_plugins[ $plugin_file ] ) ) {
460 return 'Installed';
461 }
462
463 return 'Install';
464 }
465
466 /**
467 * Register submenus.
468 *
469 * @param string $menu_slug Menu slug.
470 * @return void
471 * @since 0.0.1
472 */
473 private function register_submenus( $menu_slug ) {
474 $capability = 'manage_options';
475
476 $submenus = [
477 [
478 'id' => $menu_slug,
479 'page_title' => __( 'Dashboard', 'suredonation' ),
480 ],
481 [
482 'id' => 'suredonation#/campaigns',
483 'page_title' => __( 'Campaigns', 'suredonation' ),
484 ],
485 [
486 'id' => 'suredonation#/donations',
487 'page_title' => __( 'Donations', 'suredonation' ),
488 ],
489 [
490 'id' => 'suredonation#/donors',
491 'page_title' => __( 'Donors', 'suredonation' ),
492 ],
493 [
494 'id' => 'suredonation#/reports',
495 'page_title' => __( 'Reports', 'suredonation' ),
496 ],
497 [
498 'id' => 'suredonation#/settings',
499 'page_title' => __( 'Settings', 'suredonation' ),
500 ],
501 ];
502
503 // Register the submenus.
504 foreach ( $submenus as $submenu ) {
505 add_submenu_page(
506 $menu_slug,
507 $submenu['page_title'],
508 $submenu['page_title'],
509 $capability,
510 $submenu['id'],
511 [ $this, 'render_dashboard' ]
512 );
513 }
514
515 // Hidden onboarding page (no menu parent so it never shows in
516 // the sidebar but is still routable via admin.php?page=...).
517 add_submenu_page(
518 '',
519 __( 'SureDonation Setup', 'suredonation' ),
520 __( 'SureDonation Setup', 'suredonation' ),
521 $capability,
522 Onboarding::PAGE_SLUG,
523 [ $this, 'render_onboarding' ]
524 );
525 }
526
527 /**
528 * Render onboarding root container.
529 *
530 * @return void
531 * @since 1.0.0
532 */
533 public function render_onboarding() {
534 ?>
535 <div id="suredonation-onboarding-root"></div>
536 <?php
537 }
538
539 /**
540 * Enqueue the dedicated onboarding bundle.
541 *
542 * Loaded only on the onboarding admin page so the main admin app
543 * doesn't pay the cost on activation redirects.
544 *
545 * @return void
546 * @since 1.0.0
547 */
548 private function enqueue_onboarding_assets() {
549 $asset_file = SUREDONATION_DIR . 'assets/build/admin/onboarding/index.asset.php';
550
551 if ( ! file_exists( $asset_file ) ) {
552 return;
553 }
554
555 $asset = include $asset_file;
556
557 wp_enqueue_script(
558 'suredonation-onboarding',
559 SUREDONATION_URL . 'assets/build/admin/onboarding/index.js',
560 $asset['dependencies'],
561 $asset['version'],
562 true
563 );
564
565 wp_enqueue_style(
566 'suredonation-onboarding',
567 SUREDONATION_URL . 'assets/build/admin/onboarding/index.css',
568 [],
569 $asset['version']
570 );
571
572 wp_set_script_translations( 'suredonation-onboarding', 'suredonation' );
573
574 $current_user = wp_get_current_user();
575 $is_pro = defined( 'SUREDONATION_PRO_VER' );
576
577 // Detect GiveWP rows once at enqueue time so the JS doesn't have to
578 // spin a loader (and won't ever flash an error) just to decide whether
579 // to render the optional migration step.
580 $has_givewp_data = false;
581 try {
582 $has_givewp_data = \SureDonation\Inc\Import\Givewp\Source::get_instance()->has_givewp_data();
583 } catch ( \Throwable $e ) {
584 $has_givewp_data = false;
585 }
586
587 wp_localize_script(
588 'suredonation-onboarding',
589 'suredonation_onboarding',
590 [
591 'apiUrl' => rest_url( 'suredonation/v1' ),
592 'nonce' => wp_create_nonce( 'wp_rest' ),
593 'pluginUrl' => SUREDONATION_URL,
594 'adminUrl' => admin_url(),
595 'dashboardUrl' => admin_url( 'admin.php?page=suredonation' ),
596 'paymentsUrl' => Payment_Helper::get_settings_url( 'stripe' ),
597 'campaignsUrl' => admin_url( 'admin.php?page=suredonation#/campaigns' ),
598 'docsUrl' => 'https://suredonation.com/docs/',
599 'isProActive' => $is_pro,
600 'hasGiveWPData' => $has_givewp_data,
601 'currentUser' => [
602 'firstName' => $current_user ? $current_user->first_name : '',
603 'lastName' => $current_user ? $current_user->last_name : '',
604 'email' => $current_user ? $current_user->user_email : '',
605 ],
606 'privacyUrl' => 'https://suredonation.com/privacy-policy/',
607 ]
608 );
609
610 // Shim suredonation_admin on the onboarding page too — shared API
611 // helpers (e.g. importApi.js) read apiUrl + nonce from that global,
612 // so without this the migration session fails the REST cookie check.
613 wp_localize_script(
614 'suredonation-onboarding',
615 'suredonation_admin',
616 [
617 'apiUrl' => rest_url( 'suredonation/v1' ),
618 'nonce' => wp_create_nonce( 'wp_rest' ),
619 'is_pro_active' => $is_pro,
620 ]
621 );
622 }
623 }
624