PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.1
1.8.13 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 All 211 releases
charitable / includes / admin / class-charitable-admin-notices.php

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

772 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Contains the class that is used to register and retrieve notices in the admin like errors, warnings, success messages, etc.
4 *
5 * @package Charitable/Classes/Charitable_Admin_Notices
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.4.6
10 * @version 1.6.24
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Admin_Notices' ) ) :
19
20 /**
21 * Charitable_Admin_Notices
22 *
23 * @since 1.4.6
24 */
25 class Charitable_Admin_Notices extends Charitable_Notices {
26
27 /**
28 * Whether the script has been enqueued.
29 *
30 * @since 1.4.6
31 *
32 * @var boolean
33 */
34 private $script_enqueued;
35
36 /**
37 * Returns and/or create the single instance of this class.
38 *
39 * @since 1.4.6
40 *
41 * @return Charitable_Admin_Notices
42 */
43 public static function get_instance() {
44 return charitable()->registry()->get( 'admin_notices' );
45 }
46
47 /**
48 * Create class object. A private constructor, so this is used in a singleton context.
49 *
50 * @since 1.4.6
51 * @version 1.5.4 Access changed to public.
52 * @version 1.8.0 Added the 'render_campaign_builder_notice' notice.
53 * @version 1.8.1 Added 'render_dashboard_reporting_notice' and 'dismiss_dashboard_reporting_notice'. Removed 'render_campaign_builder_notice' notice.
54 * @version 1.8.1.12 Added 'render_license_expiring_banner'.
55 *
56 * @return void
57 */
58 public function __construct() {
59 $this->load_notices();
60
61 add_action( 'admin_notices', array( $this, 'render_upgrade_banner' ) );
62 add_action( 'admin_notices', array( $this, 'render_license_expiring_banner' ) );
63 add_action( 'admin_notices', array( $this, 'render_license_expired_banner' ) );
64 add_action( 'admin_notices', array( $this, 'render_five_star_rating' ) );
65 add_action( 'admin_notices', array( $this, 'render_square_connection_error' ) );
66 add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_five_star_notice' ), 10, 1 );
67 add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_campaign_builder_notice' ), 10, 1 );
68 add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_dashboard_reporting_notice' ), 10, 1 );
69 add_action( 'charitable_dismiss_notice', array( $this, 'dismiss_square_connection_error_notice' ), 10, 1 );
70 add_filter( 'charitable_localized_javascript_vars', array( $this, 'render_campaign_upgrade_banner_html' ), 10, 1 );
71 }
72
73 /**
74 * Adds a notice message.
75 *
76 * @since 1.4.6
77 *
78 * @param string $message The message to display.
79 * @param string $type The type of notice. Accepts 'error', 'warning', 'success', 'info', 'version'.
80 * @param string $key Optional. If not set, next numeric key is used.
81 * @param boolean $dismissible Optional. Whether the notice can be dismissed. Defaults to false.
82 * @return void
83 */
84 public function add_notice( $message, $type, $key = false, $dismissible = false ) {
85 if ( false === $key ) {
86 $this->notices[ $type ][] = array(
87 'message' => $message,
88 'dismissible' => $dismissible,
89 );
90 } else {
91 $this->notices[ $type ][ $key ] = array(
92 'message' => $message,
93 'dismissible' => $dismissible,
94 );
95 }
96 }
97
98 /**
99 * Adds an error message.
100 *
101 * @since 1.4.6
102 *
103 * @param string $message The message to display.
104 * @param string $key Optional. If not set, next numeric key is used.
105 * @param boolean $dismissible Optional. Set to true by default.
106 * @return void
107 */
108 public function add_error( $message, $key = false, $dismissible = false ) {
109 $this->add_notice( $message, 'error', $key, $dismissible );
110 }
111
112 /**
113 * Adds a warning message.
114 *
115 * @since 1.4.6
116 *
117 * @param string $message The message to display.
118 * @param string $key Optional. If not set, next numeric key is used.
119 * @param boolean $dismissible Optional. Set to true by default.
120 * @return void
121 */
122 public function add_warning( $message, $key = false, $dismissible = false ) {
123 $this->add_notice( $message, 'warning', $key, $dismissible );
124 }
125
126 /**
127 * Adds a success message.
128 *
129 * @since 1.4.6
130 *
131 * @param string $message The message to display.
132 * @param string $key Optional. If not set, next numeric key is used.
133 * @param boolean $dismissible Optional. Set to true by default.
134 * @return void
135 */
136 public function add_success( $message, $key = false, $dismissible = false ) {
137 $this->add_notice( $message, 'success', $key, $dismissible );
138 }
139
140 /**
141 * Adds an info message.
142 *
143 * @since 1.4.6
144 *
145 * @param string $message The message to display.
146 * @param string $key Optional. If not set, next numeric key is used.
147 * @param boolean $dismissible Optional. Set to true by default.
148 * @return void
149 */
150 public function add_info( $message, $key = false, $dismissible = false ) {
151 $this->add_notice( $message, 'info', $key, $dismissible );
152 }
153
154 /**
155 * Adds a version update message.
156 *
157 * @since 1.4.6
158 *
159 * @param string $message The message to display.
160 * @param string $key Optional. If not set, next numeric key is used.
161 * @param boolean $dismissible Optional. Set to true by default.
162 * @return void
163 */
164 public function add_version_update( $message, $key = false, $dismissible = true ) {
165 $this->add_notice( $message, 'version', $key, $dismissible );
166 }
167
168 /**
169 * Adds a third party warning message.
170 *
171 * @since 1.7.0.8
172 *
173 * @param string $message The message to display.
174 * @param string $key Optional. If not set, next numeric key is used.
175 * @param boolean $dismissible Optional. Set to true by default.
176 * @return void
177 */
178 public function add_third_party_warning( $message, $key = false, $dismissible = true ) {
179 $this->add_notice( $message, 'warning', $key, $dismissible );
180 }
181
182 /**
183 * Render notices.
184 *
185 * @since 1.4.6
186 *
187 * @return void
188 */
189 public function render() {
190 foreach ( charitable_get_admin_notices()->get_notices() as $type => $notices ) {
191 foreach ( $notices as $key => $notice ) {
192 if ( ! empty( $notice['message'] ) ) {
193 $this->render_notice( $notice['message'], $type, $notice['dismissible'], $key );
194 }
195 }
196 }
197 }
198
199 /**
200 * Render a notice.
201 *
202 * @since 1.4.6
203 *
204 * @param string $notice The notice message.
205 * @param string $type The type of notice. Accepts 'error', 'warning', 'success', 'info', 'version'.
206 * @param boolean $dismissible Optional. Whether the notice can be dismissed. Defaults to false.
207 * @param string $notice_key Optional. If set, the notice will be dismissed when the user dismisses the notice.
208 * @param boolean $paragraph_tags Optional. Whether to wrap the notice in paragraph tags. Defaults to true.
209 * @return void
210 */
211 public function render_notice( $notice, $type, $dismissible = false, $notice_key = '', $paragraph_tags = true ) {
212 if ( ! isset( $this->script_enqueued ) ) {
213 if ( ! wp_script_is( 'charitable-admin-notice' ) ) {
214 wp_enqueue_script( 'charitable-admin-notice' );
215 }
216
217 $this->script_enqueued = true;
218 }
219
220 $class = 'notice charitable-notice';
221
222 switch ( $type ) {
223 case 'error':
224 $class .= ' notice-error';
225 break;
226
227 case 'warning':
228 $class .= ' notice-warning';
229 break;
230
231 case 'success':
232 $class .= ' updated';
233 break;
234
235 case 'info':
236 $class .= ' notice-info';
237 break;
238
239 case 'five-star-review':
240 $class .= ' notice-info notice-five-star-review';
241 break;
242
243 case 'version':
244 $class .= ' charitable-upgrade-notice';
245 break;
246 }
247
248 if ( $dismissible ) {
249 $class .= ' is-dismissible';
250 }
251
252 $body_text = ( $paragraph_tags ) ? '<p>%s</p>' : '%s';
253
254 printf(
255 '<div class="%s" %s>' . wp_kses_post( $body_text ) . '</div>',
256 esc_attr( $class ),
257 strlen( $notice_key ) ? 'data-notice="' . esc_attr( $notice_key ) . '"' : '',
258 wp_kses_post( $notice )
259 );
260
261 if ( strlen( $notice_key ) ) {
262 unset( $this->notices[ $type ][ $notice_key ] );
263 }
264 }
265
266 /**
267 * Render a lite to pro banner
268 *
269 * @since 1.7.0
270 */
271 public function render_upgrade_banner() {
272 if ( charitable_is_pro() ) {
273 return;
274 }
275 $screen = get_current_screen();
276 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens() ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
277 $banner = get_transient( 'charitable_charitablelitetopro_banner' );
278 if ( ! $banner ) {
279 $utm_link = charitable_pro_upgrade_url( 'Upgrade From Lite Top Banner Link', 'To unlock more features consider upgrading to Pro.' );
280 $this->render_banner(
281 'You\'re using Charitable Lite! To unlock more features consider <a href="' . $utm_link . '" target="_blank" rel="noopener noreferrer">upgrading to Pro</a>.
282 ',
283 'top-of-page',
284 true
285 );
286 }
287 }
288 }
289
290 /**
291 * Render a license soon-to-be-expired banner.
292 *
293 * @since 1.8.1.12
294 */
295 public function render_license_expiring_banner() {
296
297 if ( ! charitable_is_pro() || ! class_exists( 'Charitable_Licenses_Settings' ) || ! class_exists( 'Charitable_Addons_Directory' ) ) {
298 // This should only show if the user has a license already entered.
299 return;
300 }
301
302 $is_legacy = Charitable_Addons_Directory::is_current_plan_legacy();
303 if ( $is_legacy ) {
304 return;
305 }
306
307 // Is the license expiring within 14 days?
308 $is_license_expiring = Charitable_Licenses_Settings::get_instance()->is_license_expiring( 1209600 );
309
310 if ( $is_license_expiring ) {
311 $screen = get_current_screen();
312 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens(), true ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
313 $banner = get_transient( 'charitable_expiringlicense_banner' );
314 if ( ! $banner ) {
315 $this->render_banner(
316 'Your Charitable license may be expiring soon. <a href="' . admin_url( 'admin.php?page=charitable-settings&tab=general&warning=license-expire' ) . '" target="_blank" rel="noopener noreferrer">View license settings</a> to ensure support and updates are not interrupted.
317 ',
318 'top-of-page',
319 true,
320 'expiringlicense',
321 'expiringlicense',
322 false,
323 'charitable-license-expiring-banner'
324 );
325 }
326 }
327 }
328 }
329
330 /**
331 * Render a license soon-to-be-expired banner.
332 *
333 * @since 1.8.1.12
334 */
335 public function render_license_expired_banner() {
336 if ( ! charitable_is_pro() || ! class_exists( 'Charitable_Licenses_Settings' ) || ! class_exists( 'Charitable_Addons_Directory' ) ) {
337 // This should only show if the user has a license already entered.
338 return;
339 }
340
341 $is_legacy = Charitable_Addons_Directory::is_current_plan_legacy();
342 if ( $is_legacy ) {
343 return;
344 }
345
346 // Is the license expiring within 14 days?
347 $is_license_expired = Charitable_Licenses_Settings::get_instance()->is_license_expired();
348
349 if ( $is_license_expired ) {
350 $screen = get_current_screen();
351 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens(), true ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
352 $banner = get_transient( 'charitable_expiredlicense_banner' );
353 if ( ! $banner ) {
354 $this->render_banner(
355 'Your Charitable license may have expired. <a href="' . admin_url( 'admin.php?page=charitable-settings&tab=general&warning=license-expire' ) . '" target="_blank" rel="noopener noreferrer">View license settings</a> to ensure support and updates are not interrupted.
356 ',
357 'top-of-page',
358 true,
359 'expiredlicense',
360 'expiredlicense',
361 false,
362 'charitable-license-expiring-banner'
363 );
364 }
365 }
366 }
367 }
368
369 /**
370 * Render a lite to pro banner in campaign lists, add it to the charitable admin vars so it can be injected via JS.
371 *
372 * @param array $strings The localized strings.
373 *
374 * @since 1.8.0
375 */
376 public function render_campaign_upgrade_banner_html( $strings = false ) {
377 if ( charitable_is_pro() ) {
378 return $strings;
379 }
380 $screen = get_current_screen();
381 if ( ! is_null( $screen ) && isset( $screen->base ) && 'edit' === $screen->base && isset( $screen->id ) && 'edit-campaign' === $screen->id ) {
382 $banner = get_transient( 'charitable_charitable_ltp_lb_list_banner' );
383 if ( ! $banner ) {
384 $nonce = wp_create_nonce( 'charitable_dismiss_list_banner' );
385 $banner_text = '<p><strong>Unlock More Donations with Peer-to-Peer Fundraising!</strong><br/>Harness the power of supporter networks and friends to reach more people and raise more money for your cause.</p>';
386 $strings['banner'] = sprintf(
387 '<div data-id="charitable_ltp_lb" data-nonce="%1$s" class="charitable-campaign-list-banner">' .
388 '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>' .
389 '<div class="charitable-campaign-list-banner-icon-text">' .
390 '<div class="charitable-campaign-list-banner-icon"><img src="%2$s" /></div>' .
391 '<div class="charitable-campaign-list-banner-text">%3$s</div>' .
392 '</div>' .
393 '<div class="charitable-campaign-list-banner-button"><a class="button-link" href="#">Learn More</a></div>' .
394 '</div>',
395 $nonce,
396 charitable()->get_path( 'assets', false ) . 'images/icons/ambassador.png',
397 $banner_text
398 );
399 } else {
400 $strings['banner'] = '';
401 }
402 }
403
404 return $strings;
405 }
406
407 /**
408 * Render a prompt to ask for a five star rating.
409 *
410 * @since 1.7.0
411 */
412 public function render_five_star_rating() {
413
414 if ( ! function_exists( 'get_current_screen' ) ) {
415 return;
416 }
417
418 $screen = get_current_screen();
419
420 // determine if we are on the current screen.
421 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens() ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
422
423 $slug = 'five-star-review';
424
425 // determine when to display this message. for now, there should be some sensible boundaries before showing the notification: a minimum of 14 days of use, created one donation form and received at least one donation.
426 $activated_datetime = ( false !== get_option( 'wpcharitable_activated_datetime' ) ) ? get_option( 'wpcharitable_activated_datetime' ) : false;
427 $days = 0;
428 if ( $activated_datetime ) {
429 $diff = current_time( 'timestamp' ) - $activated_datetime; // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
430 $days = abs( round( $diff / 86400 ) );
431 }
432
433 $count_campaigns = wp_count_posts( 'campaign' );
434 $total_campaigns = isset( $count_campaigns->publish ) ? $count_campaigns->publish : 0;
435 $count_donations = wp_count_posts( 'donation' );
436 $total_donations = isset( $count_donations->{'charitable-completed'} ) ? $count_donations->{'charitable-completed'} : 0;
437
438 if ( $days >= apply_filters( 'charitable_days_since_activated', 14 ) && $total_campaigns >= 1 && $total_donations >= 1 ) {
439 // check transient.
440 $star_review = get_transient( 'charitable_' . $slug . '_banner' );
441
442 // render five star rating banner/notice.
443 if ( ! $star_review ) {
444 $message = charitable_admin_view( 'notices/admin-notice-five-star-review', array(), true );
445 $key = 'five-star-review';
446 $this->render_notice( $message, 'five-star-review', true, $key, false );
447 }
448 }
449 }
450 }
451
452 /**
453 * Render a notice when the Square connection fails.
454 *
455 * @since 1.8.7
456 */
457 public function render_square_connection_error() {
458
459 $admin_notice = get_option( 'charitable_square_connection_error_notice' );
460
461 if ( false === $admin_notice ) {
462 return;
463 }
464
465 $message = charitable_admin_view( 'notices/admin-notice-square-connection-error', array( 'message' => $admin_notice['message'], 'status_code' => $admin_notice['status_code'] ), true ); // phpcs:ignore
466 $key = 'square-connection-error';
467 $this->render_notice( $message, 'error', true, $key, false );
468 }
469
470 /**
471 * Render a banner to promote the new campaign builder in version 1.8.0.
472 * This was removed in 1.8.1 in favor of the updated notice render_dashboard_reporting_notice.
473 *
474 * @since 1.8.0
475 */
476 public function render_campaign_builder_notice() {
477
478 if ( ! function_exists( 'get_current_screen' ) ) {
479 return;
480 }
481
482 $screen = get_current_screen();
483
484 // determine if we are on the current screen.
485 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens() ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
486
487 $slug = 'campaign-builder';
488
489 // check transient.
490 $builder_notice = get_transient( 'charitable_' . $slug . '_banner' );
491
492 // render banner/notice.
493 if ( ! $builder_notice ) {
494 $message = charitable_admin_view( 'notices/admin-notice-campaign-builder', array(), true );
495 $key = 'campaign-builder';
496 $this->render_notice( $message, 'campaign-builder', true, $key, false );
497 }
498 }
499 }
500
501 /**
502 * Render a banner to promote
503 *
504 * @since 1.8.1
505 * @version 1.8.1.10
506 * @version 1.8.2 deprecated.
507 */
508 public function render_dashboard_reporting_notice() {
509
510 if ( ! function_exists( 'get_current_screen' ) ) {
511 return;
512 }
513
514 $screen = get_current_screen();
515
516 // determine if we are on the current screen.
517 if ( ! is_null( $screen ) && ( in_array( $screen->id, charitable_get_charitable_screens() ) || ( isset( $screen->taxonomy ) && 'campaign_category' === $screen->taxonomy ) || ( isset( $screen->taxonomy ) && 'campaign_tag' === $screen->taxonomy ) ) ) {
518
519 $slug = 'dashboard-reporting';
520
521 // determine when to display this message. for now, there should be some sensible boundaries before showing the notification: a minimum of 10 days of use.
522 $activated_datetime = ( false !== get_option( 'wpcharitable_activated_datetime' ) ) ? get_option( 'wpcharitable_activated_datetime' ) : false;
523 $days = 0;
524 if ( $activated_datetime ) {
525 $diff = current_time( 'timestamp' ) - $activated_datetime; // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
526 $days = abs( round( $diff / 86400 ) );
527 }
528
529 if ( $days >= apply_filters( 'charitable_days_since_activated', 10, $slug ) ) {
530 // check transient.
531 $builder_notice = get_transient( 'charitable_' . $slug . '_banner' );
532
533 // render banner/notice.
534 if ( ! $builder_notice ) {
535 $message = charitable_admin_view( 'notices/admin-notice-dashboard-reporting', array(), true );
536 $key = 'dashboard-reporting';
537 $this->render_notice( $message, 'dashboard-reporting', true, $key, false );
538 }
539 }
540 }
541 }
542
543 /**
544 * Dismiss review request.
545 *
546 * @since 1.8.0
547 * @param array $postdata $_POST data.
548 */
549 public function dismiss_five_star_notice( $postdata ) {
550
551 if ( empty( $postdata['notice'] ) || 'five-star-review' !== $postdata['notice'] ) {
552 return;
553 }
554
555 $slug = 'five-star-review';
556
557 set_transient( 'charitable_' . $slug . '_banner', 1, 0 );
558 }
559
560 /**
561 * Dismiss the new campaign builder notice. Deprecated in 1.8.1.
562 *
563 * @since 1.8.0
564 * @param array $postdata $_POST data.
565 */
566 public function dismiss_campaign_builder_notice( $postdata ) {
567
568 if ( empty( $postdata['notice'] ) || 'campaign-builder' !== $postdata['notice'] ) {
569 return;
570 }
571
572 $slug = 'campaign-builder';
573
574 set_transient( 'charitable_' . $slug . '_banner', 1, 0 );
575 }
576
577 /**
578 * Dismiss the new campaign builder notice.
579 *
580 * @since 1.8.1
581 * @param array $postdata $_POST data.
582 */
583 public function dismiss_dashboard_reporting_notice( $postdata ) {
584
585 if ( empty( $postdata['notice'] ) || 'dashboard-reporting' !== $postdata['notice'] ) {
586 return;
587 }
588
589 $slug = 'dashboard-reporting';
590
591 set_transient( 'charitable_' . $slug . '_banner', 1, 0 );
592 }
593
594 /**
595 * Dismiss the Square connection error notice.
596 *
597 * @since 1.8.7
598 * @param array $postdata $_POST data.
599 */
600 public function dismiss_square_connection_error_notice( $postdata ) {
601 if ( empty( $postdata['notice'] ) || 'square-connection-error' !== $postdata['notice'] ) {
602 return;
603 }
604
605 delete_option( 'charitable_square_connection_error_notice' );
606 wp_send_json_success();
607 exit;
608 }
609
610 /**
611 * Render a banner.
612 *
613 * @since 1.7.0
614 * @version 1.8.1.12 Added css_class.
615 *
616 * @param string $message The message to display.
617 * @param string $type The type of notice. Accepts 'top-of-page'.
618 * @param boolean $dismissible Optional. Whether the notice can be dismissed. Defaults to false.
619 * @param mixed $data_nonce Optional. The nonce to use for the notice.
620 * @param mixed $data_id Optional. The id to use for the notice.
621 * @param string $data_lifespan Optional. The lifespan of the notice.
622 * @param string $additional_css_class Optional. The CSS class to use for the notice.
623 *
624 * @return void
625 */
626 public function render_banner( $message, $type = 'top-of-page', $dismissible = false, $data_nonce = 'charitablelitetopro', $data_id = 'charitablelitetopro', $data_lifespan = false, $additional_css_class = '' ) {
627 if ( ! isset( $this->script_enqueued ) ) {
628 if ( ! wp_script_is( 'charitable-admin-notice' ) ) {
629 wp_enqueue_script( 'charitable-admin-notice' );
630 }
631
632 $this->script_enqueued = true;
633 }
634
635 $css_class = trim( 'charitable-banner ' . $additional_css_class );
636
637 switch ( $type ) {
638 case 'top-of-page':
639 $css_class .= ' charitable-admin-banner-top-of-page';
640 break;
641 }
642
643 if ( $dismissible ) { // phpcs:ignore
644 // $class .= ' is-dismissible';
645 }
646
647 printf(
648 '<div class="%s" %s %s %s>%s <button type="button" class="button-link charitable-banner-dismiss">x</button></div>',
649 esc_attr( $css_class ),
650 strlen( $data_nonce ) ? 'data-notice="' . esc_attr( $data_nonce ) . '"' : '',
651 strlen( $data_id ) ? 'data-id="' . esc_attr( $data_id ) . '"' : '',
652 strlen( $data_lifespan ) ? 'data-lifespan="' . esc_attr( $data_lifespan ) . '"' : '',
653 wp_kses_post( $message )
654 );
655 }
656
657
658 /**
659 * When PHP finishes executing, stash any notices that haven't been rendered yet.
660 *
661 * @since 1.4.13
662 *
663 * @return void
664 */
665 public function shutdown() {
666 if ( charitable_is_debug( 'square' ) ) {
667 // phpcs:disable
668 error_log( 'Saving admin notices to transient' );
669 error_log( 'Notices to save: ' . print_r( $this->notices, true ) );
670 // phpcs:enable
671 }
672
673 set_transient( 'charitable_notices', $this->notices );
674 }
675
676 /**
677 * Load the notices array.
678 *
679 * If there are any stuffed in a transient, pull those out. Otherwise, reset a clear array.
680 *
681 * @since 1.4.13
682 *
683 * @return void
684 */
685 public function load_notices() {
686 $this->notices = get_transient( 'charitable_notices' );
687
688 if ( ! is_array( $this->notices ) ) {
689 $this->clear();
690 }
691 }
692
693 /**
694 * Fill admin notices from the front-end notices array.
695 *
696 * @since 1.6.24
697 *
698 * @return void
699 */
700 public function fill_notices_from_frontend() {
701 $notices = charitable_get_notices();
702
703 foreach ( $notices->get_notices() as $type => $type_notices ) {
704 foreach ( $type_notices as $notice ) {
705 $this->add_notice( $notice, $type );
706 }
707 }
708
709 $notices->clear();
710 }
711
712 /**
713 * Clear out all existing notices.
714 *
715 * @since 1.4.6
716 *
717 * @return void
718 */
719 public function clear() {
720 $clear = array(
721 'error' => array(),
722 'warning' => array(),
723 'success' => array(),
724 'info' => array(),
725 'version' => array(),
726 );
727
728 $this->notices = $clear;
729 }
730
731 /**
732 * Returns an array of screen IDs where the Charitable notices should be displayed.
733 * (Deprecated in 1.8.1.15)
734 *
735 * @uses charitable_admin_screens
736 *
737 * @since 1.7.0
738 * @since 1.8.1 Added the Charitable reports page.
739 * @since 1.8.1.6 Added the Charitable tools and guide tools page.
740 * @since 1.8.5 Added the Charitable donors page.
741 * @return array
742 */
743 public function get_charitable_screens() {
744 /**
745 * Filter admin screens where Charitable styles & scripts should be loaded.
746 *
747 * @since 1.7.0
748 *
749 * @param string[] $screens List of screen ids.
750 */
751 return apply_filters(
752 'charitable_admin_notice_screens',
753 array(
754 'campaign',
755 'donation',
756 'charitable_page_charitable-settings',
757 'charitable_page_charitable-tools',
758 'charitable_page_charitable-growth-tools',
759 'charitable_page_charitable-reports',
760 'charitable_page_charitable-dashboard',
761 'edit-campaign',
762 'edit-donation',
763 'toplevel_page_charitable',
764 'charitable_page_charitable-addons',
765 'charitable_page_charitable-donors',
766 )
767 );
768 }
769 }
770
771 endif;
772