PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.0
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / admin / class-charitable-admin.php

class-charitable-admin.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.0, at includes/admin/class-charitable-admin.php

909 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that sets up the Charitable Admin functionality.
4 *
5 * @package Charitable/Classes/Charitable_Admin
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.8.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Admin' ) ) :
19
20 /**
21 * Charitable_Admin
22 *
23 * @final
24 * @since 1.0.0
25 */
26 final class Charitable_Admin {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Admin|null
32 */
33 private static $instance = null;
34
35 /**
36 * Donation actions class.
37 *
38 * @var Charitable_Donation_Admin_Actions
39 */
40 private $donation_actions;
41
42 /**
43 * Set up the class.
44 *
45 * Note that the only way to instantiate an object is with the charitable_start method,
46 * which can only be called during the start phase. In other words, don't try
47 * to instantiate this object.
48 *
49 * @since 1.0.0
50 */
51 protected function __construct() {
52 $this->load_dependencies();
53
54 $this->donation_actions = new Charitable_Donation_Admin_Actions();
55
56 do_action( 'charitable_admin_loaded' );
57
58 add_action( 'wp_ajax_charitable_lite_settings_upgrade', array( $this, 'dismiss_lite_cta' ) );
59
60 add_filter( 'post_row_actions', array( $this, 'campaign_action_row' ), 10, 2 );
61 add_filter( 'get_edit_post_link', array( $this, 'campaign_link' ), 99, 3 );
62 add_filter( 'preview_post_link', array( $this, 'campaign_preview_link' ), 10, 2 );
63 }
64
65 /**
66 * Returns and/or create the single instance of this class.
67 *
68 * @since 1.2.0
69 *
70 * @return Charitable_Admin
71 */
72 public static function get_instance() {
73 if ( is_null( self::$instance ) ) {
74 self::$instance = new self();
75 }
76
77 return self::$instance;
78 }
79
80 /**
81 * Include admin-only files.
82 *
83 * @since 1.0.0
84 *
85 * @return void
86 */
87 private function load_dependencies() {
88 $admin_dir = charitable()->get_path( 'includes' ) . 'admin/';
89
90 require_once $admin_dir . 'charitable-core-admin-functions.php';
91 require_once $admin_dir . 'campaigns/charitable-admin-campaign-hooks.php';
92 require_once $admin_dir . 'dashboard-widgets/charitable-dashboard-widgets-hooks.php';
93 require_once $admin_dir . 'donations/charitable-admin-donation-hooks.php';
94 require_once $admin_dir . 'settings/charitable-settings-admin-hooks.php';
95 }
96
97 /**
98 * Get Charitable_Donation_Admin_Actions class.
99 *
100 * @since 1.5.0
101 *
102 * @return Charitable_Donation_Admin_Actions
103 */
104 public function get_donation_actions() {
105 return $this->donation_actions;
106 }
107
108 /**
109 * Do an admin action.
110 *
111 * @since 1.5.0
112 *
113 * @return boolean|WP_Error WP_Error in case of error. Mixed results if the action was performed.
114 */
115 public function maybe_do_admin_action() {
116 if ( ! array_key_exists( 'charitable_admin_action', $_GET ) ) {
117 return false;
118 }
119
120 if ( count( array_diff( array( 'action_type', '_nonce', 'object_id' ), array_keys( $_GET ) ) ) ) {
121 return new WP_Error( __( 'Action could not be executed.', 'charitable' ) );
122 }
123
124 if ( ! isset( $_GET['_nonce'] ) || ! wp_verify_nonce( $_GET['_nonce'], 'donation_action' ) ) { // phpcs:ignore.
125 return new WP_Error( __( 'Action could not be executed. Nonce check failed.', 'charitable' ) );
126 }
127
128 if ( ! isset( $_GET['action_type'] ) || 'donation' !== $_GET['action_type'] ) {
129 return new WP_Error( __( 'Action from an unknown action type executed.', 'charitable' ) );
130 }
131
132 return $this->donation_actions->do_action( $_GET['charitable_admin_action'], $_GET['object_id'] );
133 }
134
135 /**
136 * Loads admin-only scripts and stylesheets.
137 *
138 * @since 1.0.0
139 *
140 * @return void
141 */
142 public function admin_enqueue_scripts() {
143
144 $min = ''; // charitable_get_min_suffix(); // todo: undo this.
145 $version = charitable()->get_version();
146
147 $assets_dir = charitable()->get_path( 'assets', false );
148
149 /* Menu styles are loaded everywhere in the WordPress dashboard. */
150 wp_register_style(
151 'charitable-admin-menu',
152 $assets_dir . 'css/charitable-admin-menu' . $min . '.css',
153 array(),
154 $version
155 );
156
157 wp_enqueue_style( 'charitable-admin-menu' );
158
159 wp_register_script(
160 'charitable-admin-pages-all',
161 $assets_dir . 'js/charitable-admin-pages' . $min . '.js',
162 array( 'jquery' ),
163 $version,
164 false
165 );
166
167 wp_enqueue_script( 'charitable-admin-pages-all' );
168
169 /* Admin page styles are registered but only enqueued when necessary. */
170 wp_register_style(
171 'charitable-admin-pages',
172 $assets_dir . 'css/charitable-admin-pages' . $min . '.css',
173 array(),
174 $version
175 );
176
177 /* The following styles are only loaded on Charitable screens. */
178 $screen = get_current_screen();
179
180 /* This check covers the category and tags pages, only load the main admin css (upgrade banner, etc.) */
181 if ( ! is_null( $screen ) && in_array( $screen->base, array( 'edit-tags', 'edit-categories' ) ) ) {
182
183 wp_register_style(
184 'charitable-admin',
185 $assets_dir . 'css/charitable-admin' . $min . '.css',
186 array(),
187 $version
188 );
189
190 wp_enqueue_style( 'charitable-admin' );
191
192 wp_register_script(
193 'charitable-admin-notice',
194 $assets_dir . 'js/charitable-admin-notice' . $min . '.js',
195 array( 'jquery' ),
196 $version,
197 false
198 );
199
200 }
201
202 // v 1.8.0.
203 wp_register_style(
204 'charitable-admin-2.0',
205 $assets_dir . 'css/charitable-admin-2.0' . $min . '.css',
206 array(),
207 $version
208 );
209
210 wp_enqueue_style( 'charitable-admin-2.0' );
211
212 if ( ! is_null( $screen ) && in_array( $screen->id, $this->get_charitable_screens() ) ) {
213
214 wp_register_style(
215 'charitable-admin',
216 $assets_dir . 'css/charitable-admin' . $min . '.css',
217 array(),
218 $version
219 );
220
221 wp_enqueue_style( 'charitable-admin' );
222
223 $dependencies = array( 'jquery-ui-datepicker', 'jquery-ui-tabs', 'jquery-ui-sortable' );
224 $localized_vars = array(
225 'suggested_amount_placeholder' => __( 'Amount', 'charitable' ),
226 'suggested_amount_description_placeholder' => __( 'Optional Description', 'charitable' ),
227 );
228
229 if ( 'donation' === $screen->id ) {
230 wp_register_script(
231 'accounting',
232 $assets_dir . 'js/libraries/accounting' . $min . '.js',
233 array( 'jquery' ),
234 $version,
235 true
236 );
237
238 $dependencies[] = 'accounting';
239 $localized_vars = array_merge(
240 $localized_vars,
241 array(
242 'currency_format_num_decimals' => esc_attr( charitable_get_currency_helper()->get_decimals() ),
243 'currency_format_decimal_sep' => esc_attr( charitable_get_currency_helper()->get_decimal_separator() ),
244 'currency_format_thousand_sep' => esc_attr( charitable_get_currency_helper()->get_thousands_separator() ),
245 'currency_format' => esc_attr( charitable_get_currency_helper()->get_accounting_js_format() ),
246 )
247 );
248 }
249
250 wp_register_script(
251 'charitable-admin',
252 $assets_dir . 'js/charitable-admin' . $min . '.js',
253 $dependencies,
254 $version,
255 false
256 );
257
258 wp_enqueue_script( 'charitable-admin' );
259
260 // v 1.8.0.
261
262 wp_enqueue_style(
263 'jquery-confirm',
264 charitable()->get_path( 'directory', false ) . 'assets/lib/jquery.confirm/jquery-confirm.min.css',
265 null,
266 '3.3.4'
267 );
268
269 wp_enqueue_style(
270 'charitable-font-awesome',
271 charitable()->get_path( 'directory', false ) . 'assets/lib/font-awesome/font-awesome.min.css',
272 null,
273 '4.7.0'
274 );
275
276 wp_enqueue_script(
277 'jquery-confirm',
278 charitable()->get_path( 'directory', false ) . 'assets/lib/jquery.confirm/jquery-confirm.min.js',
279 [ 'jquery' ],
280 '3.3.4',
281 false
282 );
283
284 wp_register_script(
285 'charitable-admin-2.0',
286 $assets_dir . 'js/charitable-admin-2.0' . $min . '.js',
287 $dependencies,
288 $version,
289 false
290 );
291
292 wp_enqueue_script( 'charitable-admin-2.0' );
293
294 /**
295 * Filter the admin Javascript vars.
296 *
297 * @since 1.0.0
298 *
299 * @param array $localized_vars The vars.
300 */
301 $localized_vars = apply_filters( 'charitable_localized_javascript_vars', $localized_vars );
302
303 if ( ! empty( $localized_vars ) ) {
304 wp_localize_script( 'charitable-admin', 'CHARITABLE', $localized_vars );
305 }
306
307 /* color picker for admin settings */
308 wp_enqueue_script( 'wp-color-picker', false, false, false, true ); // phpcs:ignore.
309 wp_enqueue_style( 'wp-color-picker' );
310
311 } // end if
312
313 wp_register_script(
314 'charitable-admin-notice',
315 $assets_dir . 'js/charitable-admin-notice' . $min . '.js',
316 array( 'jquery' ),
317 $version,
318 false
319 );
320
321 wp_register_script(
322 'charitable-admin-media',
323 $assets_dir . 'js/charitable-admin-media' . $min . '.js',
324 array( 'jquery' ),
325 $version,
326 false
327 );
328
329 wp_register_script(
330 'lean-modal',
331 $assets_dir . 'js/libraries/leanModal' . $min . '.js',
332 array( 'jquery' ),
333 $version,
334 true
335 );
336
337 wp_register_style(
338 'lean-modal-css',
339 $assets_dir . 'css/modal' . $min . '.css',
340 array(),
341 $version
342 );
343
344 wp_register_script(
345 'charitable-admin-tables',
346 $assets_dir . 'js/charitable-admin-tables' . $min . '.js',
347 array( 'jquery', 'lean-modal' ),
348 $version,
349 true
350 );
351
352 wp_register_script(
353 'select2',
354 $assets_dir . 'js/libraries/select2' . $min . '.js',
355 array( 'jquery' ),
356 '4.0.12',
357 true
358 );
359
360 wp_register_style(
361 'select2-css',
362 $assets_dir . 'css/libraries/select2' . $min . '.css',
363 array(),
364 '4.0.12'
365 );
366
367 do_action( 'after_charitable_admin_enqueue_scripts', $min, $version, $assets_dir );
368 }
369
370 /**
371 * Set admin body classes.
372 *
373 * @since 1.5.0
374 *
375 * @param string $classes Existing list of classes.
376 * @return string
377 */
378 public function set_body_class( $classes ) {
379 $screen = get_current_screen();
380
381 if ( 'donation' === $screen->post_type && ( 'add' === $screen->action || isset( $_GET['show_form'] ) ) ) { // phpcs:ignore.
382 $classes .= ' charitable-admin-donation-form';
383 }
384
385 if ( isset( $_GET['page'] ) && 'charitable-settings' === $_GET['page'] ) { // phpcs:ignore.
386 $classes .= ' charitable-admin-settings';
387 }
388
389 if ( isset( $_GET['page'] ) && 'charitable-settings' === $_GET['page'] && isset( $_GET['tab'] ) && '' !== $_GET['tab'] ) { // phpcs:ignore.
390 $classes .= ' charitable-admin-settings-' . esc_attr( $_GET['tab'] ); // phpcs:ignore.
391 }
392
393 return $classes;
394 }
395
396 /**
397 * Add notices to the dashboard.
398 *
399 * @since 1.4.0
400 *
401 * @return void
402 */
403 public function add_notices() {
404 /*
405 Get any version update notices first.
406 */
407 // $this->add_version_update_notices(); // depreciated
408
409 $this->add_third_party_notices();
410
411 /* Render notices. */
412 charitable_get_admin_notices()->render();
413 }
414
415 /**
416 * Add notices for potential third party warnings.
417 *
418 * @since 1.7.0.8
419 */
420 public function add_third_party_notices() {
421 if ( ! current_user_can( 'manage_options' ) ) {
422 return;
423 }
424
425 // Allow this feature to be disabled in case unforeseen problems come up.
426 if ( false === apply_filters( 'charitable_donations_export_args', true ) ) {
427 return;
428 }
429
430 $notices = array(
431 /* translators: %s: link */
432 'code-snippets/code-snippets.php' => sprintf(
433 __( "You appear to be using a code snippet plugin. Please <a href='%s' target='_blank'>review best practices</a> when using snippets to avoid problems when upgrading or deactivating Charitable.", 'charitable' ),
434 'https://wpcharitable.com/code-snippet-best-practices/'
435 ),
436 );
437
438 // Allow this list to be altered by a third party or charitable addon.
439 $notices = apply_filters( 'charitable_admin_third_party_notices', $notices );
440
441 $helper = charitable_get_admin_notices();
442
443 foreach ( $notices as $notice => $message ) {
444 if ( false === charitable_get_third_party_warning_option( 'code-snippets/code-snippets.php' ) || 'dismissed' === charitable_get_third_party_warning_option( 'code-snippets/code-snippets.php' ) ) {
445 continue;
446 }
447
448 $helper->add_third_party_warning( $message, $notice );
449 }
450 }
451
452 /**
453 * Add version update notices to the dashboard.
454 *
455 * @since 1.4.6
456 *
457 * @return void
458 */
459 public function add_version_update_notices() {
460 if ( ! current_user_can( 'manage_options' ) ) {
461 return;
462 }
463
464 $notices = array(
465 /* translators: %s: link */
466 'release-150' => sprintf(
467 __( "Charitable 1.5 is packed with new features and improvements. <a href='%s' target='_blank'>Find out what's new</a>.", 'charitable' ),
468 'https://wpcharitable.com/charitable-1-5-release-notes/?utm_source=WordPress&utm_campaign=WP+Charitable&utm_medium=Admin+Notice&utm_content=Version+One+Five+Whats+New'
469 ),
470 /* translators: %s: link */
471 'release-160' => sprintf(
472 __( 'Charitable 1.6 introduces important new user privacy features and other improvements. <a href="%s" target="_blank">Find out what\'s new</a>.', 'charitable' ),
473 'https://www.wpcharitable.com/charitable-1-6-user-privacy-gdpr-better-refunds-and-a-new-shortcode/?utm_source=WordPress&utm_campaign=WP+Charitable&utm_medium=Admin+Notice&utm_content=Version+One+Six+Whats+New'
474 ),
475 );
476
477 $helper = charitable_get_admin_notices();
478
479 foreach ( $notices as $notice => $message ) {
480 if ( ! get_transient( 'charitable_' . $notice . '_notice' ) ) {
481 continue;
482 }
483
484 $helper->add_version_update( $message, $notice );
485 }
486 }
487
488 /**
489 * Dismiss a notice.
490 *
491 * @since 1.4.0
492 *
493 * @return void
494 */
495 public function dismiss_notice() {
496 if ( ! isset( $_POST['notice'] ) ) { // phpcs:ignore.
497 wp_send_json_error();
498 }
499
500 $ret = ( 'noted' === charitable_get_third_party_warning_option( 'code-snippets/code-snippets.php' ) ) ? charitable_set_third_party_warning_option( 'code-snippets/code-snippets.php', 'dismissed' ) : delete_transient( 'charitable_' . filter_input( INPUT_POST, 'notice', FILTER_SANITIZE_STRING ) . '_notice', true );
501
502 do_action( 'charitable_dismiss_notice', $_POST ); // phpcs:ignore.
503
504 if ( ! $ret ) {
505 wp_send_json_error( $ret );
506 }
507
508 wp_send_json_success();
509 }
510
511 /**
512 * Dismiss a banner.
513 *
514 * @since 1.7.0
515 *
516 * @return void
517 */
518 public function dismiss_banner() {
519 if ( ! isset( $_POST['banner_id'] ) ) { // phpcs:ignore.
520 wp_send_json_error();
521 }
522
523 $ret = set_transient( 'charitable_' . esc_attr( $_POST['banner_id'] ) . '_banner', 1, WEEK_IN_SECONDS ); // phpcs:ignore.
524
525 if ( ! $ret ) {
526 wp_send_json_error( $ret );
527 }
528
529 wp_send_json_success();
530 }
531
532 /**
533 * Dismiss a banner.
534 *
535 * @since 1.8.0
536 *
537 * @return void
538 */
539 public function dismiss_list_banner() {
540 if ( ! isset( $_POST['banner_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
541 wp_send_json_error();
542 }
543
544 $ret = set_transient( 'charitable_' . esc_attr( $_POST['banner_id'] ) . '_list_banner', 1, WEEK_IN_SECONDS ); // phpcs:ignore.
545
546 if ( ! $ret ) {
547 wp_send_json_error( $ret );
548 }
549
550 wp_send_json_success();
551 }
552
553 /**
554 * Dismiss a five star rating.
555 *
556 * @since 1.7.0
557 *
558 * @return void
559 */
560 public function dismiss_five_star_rating() {
561 if ( ! isset( $_POST['banner_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
562 wp_send_json_error();
563 }
564
565 $check = get_transient( 'charitable_' . esc_attr( $_POST['banner_id'] ) . '_banner' ); // phpcs:ignore.
566
567 if ( ! $check ) {
568 $ret = set_transient( 'charitable_' . esc_attr( $_POST['banner_id'] ) . '_banner', true ); // phpcs:ignore.
569 if ( ! $ret ) {
570 wp_send_json_error( $ret );
571 }
572 }
573
574 wp_send_json_success();
575 }
576
577 /**
578 * Dismiss a five star rating.
579 *
580 * @since 1.7.0
581 *
582 * @return void
583 */
584 public function dismiss_lite_cta() {
585 if ( ! isset( $_POST['chartiable_action'] ) ) { // phpcs:ignore.
586 wp_send_json_error();
587 }
588
589 $updated = update_option( 'charitable_lite_settings_upgrade', true );
590
591 if ( $updated ) {
592 wp_send_json_success();
593 } else {
594 wp_send_json_error();
595 }
596 }
597
598 /**
599 * Adds one or more classes to the body tag in the dashboard.
600 *
601 * @since 1.0.0
602 *
603 * @param string $classes Current body classes.
604 * @return string Altered body classes.
605 */
606 public function add_admin_body_class( $classes ) {
607 $screen = get_current_screen();
608
609 if ( in_array( $screen->post_type, array( Charitable::DONATION_POST_TYPE, Charitable::CAMPAIGN_POST_TYPE ) ) ) {
610 $classes .= ' post-type-charitable';
611 }
612
613 return $classes;
614 }
615
616 /**
617 * Add custom links to the plugin actions.
618 *
619 * @since 1.0.0
620 *
621 * @param string[] $links Plugin action links.
622 * @return string[]
623 */
624 public function add_plugin_action_links( $links ) {
625 $links[] = '<a href="' . admin_url( 'admin.php?page=charitable-settings' ) . '">' . __( 'Settings', 'charitable' ) . '</a>';
626 return $links;
627 }
628
629 /**
630 * Add Extensions link to the plugin row meta.
631 *
632 * @since 1.2.0
633 *
634 * @param string[] $links Plugin action links.
635 * @param string $file The plugin file.
636 * @return string[] $links
637 */
638 public function add_plugin_row_meta( $links, $file ) {
639 if ( plugin_basename( charitable()->get_path() ) != $file ) {
640 return $links;
641 }
642
643 // Use an updated UTM.
644 $extensions_link = charitable_ga_url(
645 'https://wpcharitable.com/extensions/',
646 urlencode( 'Admin Plugin Page' ),
647 urlencode( 'Extensions' )
648 );
649
650 $links[] = '<a href="' . $extensions_link . '" target="_blank" rel="noopener">' . __( 'Extensions', 'charitable' ) . '</a>';
651
652 return $links;
653 }
654
655 /**
656 * Remove the jQuery UI styles added by Ninja Forms.
657 *
658 * @since 1.2.0
659 *
660 * @param string $context Media buttons context.
661 * @return string
662 */
663 public function remove_jquery_ui_styles_nf( $context ) {
664 wp_dequeue_style( 'jquery-smoothness' );
665 return $context;
666 }
667
668 /**
669 * Export donations.
670 *
671 * @since 1.3.0
672 *
673 * @return false|void Returns false if the export failed. Exits otherwise.
674 */
675 public function export_donations() {
676
677 if ( ! wp_verify_nonce( $_GET['_charitable_export_nonce'], 'charitable_export_donations' ) ) {
678 return false;
679 }
680
681 /**
682 * Filter the donation export arguments.
683 *
684 * @since 1.3.0
685 *
686 * @param array $args Export arguments.
687 */
688 $export_args = apply_filters(
689 'charitable_donations_export_args',
690 array(
691 'start_date' => isset( $_GET['start_date'] ) ? sanitize_text_field( wp_unslash( $_GET['start_date'] ) ) : '',
692 'end_date' => isset( $_GET['end_date'] ) ? sanitize_text_field( wp_unslash( $_GET['end_date'] ) ) : '',
693 'status' => isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '',
694 'campaign_id' => isset( $_GET['campaign_id'] ) ? sanitize_text_field( wp_unslash( $_GET['campaign_id'] ) ) : '',
695 'report_type' => isset( $_GET['report_type'] ) ? sanitize_text_field( wp_unslash( $_GET['report_type'] ) ) : '',
696 )
697 );
698
699 /**
700 * Filter the export class name.
701 *
702 * @since 1.3.0
703 *
704 * @param string $report_type The type of report.
705 * @param array $args Export arguments.
706 */
707 $export_class = apply_filters( 'charitable_donations_export_class', 'Charitable_Export_Donations', $_GET['report_type'], $export_args );
708
709 new $export_class( $export_args );
710
711 die();
712 }
713
714 /**
715 * Export campaigns.
716 *
717 * @since 1.6.0
718 *
719 * @return false|void Returns false if the export failed. Exits otherwise.
720 */
721 public function export_campaigns() {
722
723 if ( ! isset( $_GET['_charitable_export_nonce'] ) || ! wp_verify_nonce( $_GET['_charitable_export_nonce'], 'charitable_export_campaigns' ) ) {
724 return false;
725 }
726
727 /**
728 * Filter the campaign export arguments.
729 *
730 * @since 1.6.0
731 *
732 * @param array $args Export arguments.
733 */
734 $export_args = apply_filters(
735 'charitable_campaigns_export_args',
736 array(
737 'start_date_to' => isset( $_GET['start_date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['start_date_to'] ) ) : '',
738 'end_date_from' => isset( $_GET['end_date_from'] ) ? sanitize_text_field( wp_unslash( $_GET['end_date_from'] ) ) : '',
739 'end_date_to' => isset( $_GET['end_date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['end_date_to'] ) ) : '',
740 'status' => isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '',
741 'report_type' => isset( $_GET['report_type'] ) ? sanitize_text_field( wp_unslash( $_GET['report_type'] ) ) : '',
742 )
743 );
744
745 /**
746 * Filter the export class name.
747 *
748 * @since 1.6.0
749 *
750 * @param string $report_type The type of report.
751 * @param array $args Export arguments.
752 */
753 $export_class = apply_filters( 'charitable_campaigns_export_class', 'Charitable_Export_Campaigns', $_GET['report_type'], $export_args );
754
755 new $export_class( $export_args );
756
757 die();
758 }
759
760 /**
761 * Returns an array of screen IDs where the Charitable scripts should be loaded.
762 *
763 * @uses charitable_admin_screens
764 *
765 * @since 1.0.0
766 *
767 * @return array
768 */
769 public function get_charitable_screens() {
770 /**
771 * Filter admin screens where Charitable styles & scripts should be loaded.
772 *
773 * @since 1.8.0
774 *
775 * @param string[] $screens List of screen ids.
776 */
777 return apply_filters(
778 'charitable_admin_screens',
779 array(
780 'campaign',
781 'donation',
782 'charitable_page_charitable-settings',
783 'edit-campaign',
784 'edit-donation',
785 'dashboard',
786 'toplevel_page_charitable',
787 'charitable_page_charitable-addons',
788 )
789 );
790 }
791
792 /**
793 * Updates the "action row" of campaigns to add the ability to edit with builder.
794 *
795 * @since 1.8.0
796 *
797 * @param array $actions Actions.
798 * @param array $post Post data.
799 *
800 * @return array
801 */
802 public function campaign_action_row( $actions, $post ) {
803
804 $actions_first = array();
805
806 $suffix = ( charitable_is_debug() || charitable_is_script_debug() ) ? '#charitabledebug' : false;
807
808 // Check for the post type.
809
810 if ( is_object( $post ) && isset( $post->post_type ) && 'campaign' === $post->post_type && ( ! isset( $_GET['post_status'] ) || ( isset( $_GET['post_status'] ) && 'trash' !== strtolower( $_GET['post_status'] ) ) ) ) {
811
812 $post_id = intval( $post->ID );
813
814 // Determine if this is a "legacy" campaign.
815 $is_legacy_campaign = charitable_is_campaign_legacy( $post_id );
816
817 if ( isset( $actions['edit'] ) && 0 !== $post_id ) {
818
819 $actions_show_id = array( 'id' => esc_html__( 'ID: ', 'charitable' ) . $post_id );
820 $actions_edit_legacy = array( 'edit' => $actions['edit'] );
821
822 unset( $actions['edit'] );
823
824 }
825
826 // if ( defined( 'CHARITABLE_BUILDER_SHOW_LEGACY_EDIT_LINKS' ) && CHARITABLE_BUILDER_SHOW_LEGACY_EDIT_LINKS === true ) {
827
828 // Add "edit" link that goes to the builder. The campaign can still be edited w/ legacy via direct link (example https://website.test/wp-admin/post.php?post=246&action=edit).
829 $actions_edit_legacy = array( 'Edit' => '<a href="' . admin_url( 'post.php?post=' . $post_id . '&action=edit' ) . '">' . esc_html__( 'Legacy Edit', 'charitable' ) . '</a>' );
830
831 $actions = ( false === $is_legacy_campaign )
832 ? $actions_show_id + $actions_edit_legacy + array( 'charitable_builder' => '<a href="' . admin_url( 'admin.php?page=charitable-campaign-builder&campaign_id=' . $post_id ) . $suffix . '">' . esc_html__( 'Edit With Builder', 'charitable' ) . '</a>' ) + $actions
833 : $actions_show_id + $actions_edit_legacy + $actions;
834
835 // } else {
836
837 // $actions = ( false === $is_legacy_campaign )
838 // ? $actions_show_id + array( 'charitable_builder' => '<a href="' . admin_url( 'admin.php?page=charitable-campaign-builder&campaign_id=' . $post_id ) . $suffix . '">' . esc_html__( 'Edit', 'charitable' ) . '</a>' ) + $actions
839 // : $actions_show_id + $actions_edit_legacy + $actions;
840
841 // }
842
843 }
844
845 return $actions;
846 }
847
848 /**
849 * Updates the "post link" of campaigns to add the ability to edit with builder.
850 *
851 * @since 1.8.0
852 *
853 * @param string $link The current link URL.
854 * @param integer $post_id Post ID.
855 * @param array $context Context.
856 *
857 * @return array
858 */
859 public function campaign_link( $link, $post_id, $context ) { // phpcs:ignore
860
861 $screen = get_current_screen();
862 $post_id = intval( $post_id );
863
864 if ( 0 === $post_id || ! isset( $screen->id ) || $screen->id !== 'edit-campaign' ) {
865 return $link;
866 }
867
868 // Determine if this is a "legacy" campaign.
869 $is_legacy_campaign = charitable_is_campaign_legacy( $post_id );
870
871 $suffix = ( charitable_is_debug() || charitable_is_script_debug() ) ? '#charitabledebug' : false;
872
873 $new_link = ( false === $is_legacy_campaign )
874 ? admin_url( 'admin.php?page=charitable-campaign-builder&campaign_id=' . $post_id ) . $suffix
875 : esc_url( $link );
876
877 return $new_link;
878 }
879
880 /**
881 * Filters the URL used for a campaign preview.
882 *
883 * @since 1.8.0
884 *
885 * @param string $preview_link URL used for the post preview.
886 * @param WP_Post $post Post object.
887 */
888 public function campaign_preview_link( $preview_link, $post ) {
889
890 if ( ! empty( $post ) && 'campaign' === $post->post_type ) {
891
892 $preview_link = add_query_arg(
893 array(
894 'charitable_campaign_preview' => $post->ID,
895 ),
896 $preview_link
897 );
898
899 }
900
901 return $preview_link;
902 }
903 }
904
905
906
907
908 endif;
909