PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.3.0
GiveWP – Donation Plugin and Fundraising Platform v2.3.0
4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-notices.php
give / includes Last commit date
admin 7 years ago api 7 years ago deprecated 7 years ago donors 7 years ago emails 7 years ago forms 7 years ago gateways 7 years ago libraries 7 years ago payments 7 years ago actions.php 7 years ago ajax-functions.php 7 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 7 years ago class-give-cache.php 7 years ago class-give-cli-commands.php 8 years ago class-give-comment.php 7 years ago class-give-cron.php 8 years ago class-give-db-comments-meta.php 7 years ago class-give-db-comments.php 7 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 7 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 7 years ago class-give-db-meta.php 7 years ago class-give-db-payment-meta.php 7 years ago class-give-db-sequential-ordering.php 7 years ago class-give-db-sessions.php 7 years ago class-give-db.php 7 years ago class-give-donate-form.php 8 years ago class-give-donor-wall-widget.php 7 years ago class-give-donor.php 7 years ago class-give-email-access.php 7 years ago class-give-html-elements.php 7 years ago class-give-license-handler.php 7 years ago class-give-logging.php 8 years ago class-give-readme-parser.php 8 years ago class-give-roles.php 8 years ago class-give-scripts.php 7 years ago class-give-session.php 7 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 7 years ago country-functions.php 7 years ago currency-functions.php 7 years ago error-tracking.php 8 years ago filters.php 7 years ago formatting.php 7 years ago import-functions.php 7 years ago install.php 7 years ago login-register.php 8 years ago misc-functions.php 7 years ago plugin-compatibility.php 8 years ago post-types.php 7 years ago price-functions.php 7 years ago process-donation.php 7 years ago shortcodes.php 7 years ago template-functions.php 8 years ago user-functions.php 7 years ago
class-notices.php
746 lines
1 <?php
2 /**
3 * Admin Notices Class.
4 *
5 * @package Give
6 * @subpackage Admin/Notices
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.8.9
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Give_Notices Class
19 *
20 * @since 1.8.9
21 */
22 class Give_Notices {
23 /**
24 * List of notices
25 * @var array
26 * @since 1.8.9
27 * @access private
28 */
29 private static $notices = array();
30
31
32 /**
33 * Flag to check if any notice auto dismissible among all notices
34 *
35 * @since 1.8.9
36 * @access private
37 * @var bool
38 */
39 private static $has_auto_dismissible_notice = false;
40
41 /**
42 * Flag to check if any notice has dismiss interval among all notices
43 *
44 * @since 1.8.9
45 * @access private
46 * @var bool
47 */
48 private static $has_dismiss_interval_notice = false;
49
50 /**
51 * Get things started.
52 *
53 * @since 1.8.9
54 */
55 public function __construct() {
56 add_action( 'admin_notices', array( $this, 'render_admin_notices' ), 999 );
57 add_action( 'admin_footer', array( $this, '__reveal_notices' ) );
58 add_action( 'give_dismiss_notices', array( $this, 'dismiss_notices' ) );
59
60 add_action( 'give_frontend_notices', array( $this, 'render_frontend_notices' ), 999 );
61 add_action( 'give_pre_form_output', array( $this, 'render_frontend_form_notices' ), 10, 1 );
62 add_action( 'give_ajax_donation_errors', array( $this, 'render_frontend_notices' ) );
63
64 /**
65 * Backward compatibility for deprecated params.
66 *
67 * @since 1.8.14
68 */
69 add_filter( 'give_register_notice_args', array( $this, 'bc_deprecated_params' ) );
70 add_filter( 'give_frontend_errors_args', array( $this, 'bc_deprecated_params' ) );
71 add_filter( 'give_frontend_notice_args', array( $this, 'bc_deprecated_params' ) );
72 }
73
74 /**
75 * Add backward compatibility to deprecated params.
76 *
77 * @since 1.8.14
78 * @access public
79 *
80 * @param array $args Array of notice params
81 *
82 * @return array
83 */
84 public function bc_deprecated_params( $args ) {
85 /**
86 * Param: auto_dismissible
87 * deprecated in 1.8.14
88 *
89 * Check if auto_dismissible is set and it true then unset and change dismissible parameter value to auto
90 */
91 if ( isset( $args['auto_dismissible'] ) ) {
92 if ( ! empty( $args['auto_dismissible'] ) ) {
93 $args['dismissible'] = 'auto';
94 }
95 // unset auto_dismissible as it has been deprecated.
96 unset( $args['auto_dismissible'] );
97 }
98
99 return $args;
100 }
101
102 /**
103 * Register notice.
104 *
105 * @since 1.8.9
106 * @access public
107 *
108 * @param $notice_args
109 *
110 * @return bool
111 */
112 public function register_notice( $notice_args ) {
113 // Bailout.
114 if ( empty( $notice_args['id'] ) || array_key_exists( $notice_args['id'], self::$notices ) ) {
115 return false;
116 }
117
118 $notice_args = wp_parse_args(
119 $notice_args,
120 array(
121 'id' => '',
122 'description' => '',
123
124 /*
125 * Add custom notice html
126 * Note: This param has more priority then description, so if you have both param then this one will be use
127 * for generating notice html. Most of feature of notice attach to core generated html, so if you set
128 * custom html then please add required classes and data attribute which help to apply feature on notice.
129 *
130 * @since 1.8.16
131 */
132 'description_html' => '',
133
134 /*
135 * Add New Parameter and remove the auto_dismissible parameter.
136 * Value: auto/true/false
137 *
138 * @since 1.8.14
139 */
140 'dismissible' => true,
141
142 // Value: error/warning/success/info/updated
143 'type' => 'error',
144
145 // Value: null/user/all
146 'dismissible_type' => null,
147
148 // Value: shortly/permanent/null/custom
149 'dismiss_interval' => null,
150
151 // Only set it when custom is defined.
152 'dismiss_interval_time' => null,
153
154
155 )
156 );
157
158 /**
159 * Filter to modify Notice args before it get add
160 *
161 * @since 1.8.14
162 */
163 $notice_args = apply_filters( 'give_register_notice_args', $notice_args );
164
165 // Set extra dismiss links if any.
166 if ( false !== strpos( $notice_args['description'], 'data-dismiss-interval' ) ) {
167
168 preg_match_all( "/data-([^\"]*)=\"([^\"]*)\"/", $notice_args['description'], $extra_notice_dismiss_link );
169
170 if ( ! empty( $extra_notice_dismiss_link ) ) {
171 $extra_notice_dismiss_links = array_chunk( current( $extra_notice_dismiss_link ), 3 );
172 foreach ( $extra_notice_dismiss_links as $extra_notice_dismiss_link ) {
173 // Create array og key ==> value by parsing query string created after renaming data attributes.
174 $data_attribute_query_str = str_replace( array( 'data-', '-', '"' ), array(
175 '',
176 '_',
177 '',
178 ), implode( '&', $extra_notice_dismiss_link ) );
179
180 $notice_args['extra_links'][] = wp_parse_args( $data_attribute_query_str );
181 }
182 }
183 }
184
185
186 self::$notices[ $notice_args['id'] ] = $notice_args;
187
188 // Auto set show param if not already set.
189 if ( ! isset( self::$notices[ $notice_args['id'] ]['show'] ) ) {
190 self::$notices[ $notice_args['id'] ]['show'] = $this->is_notice_dismissed( $notice_args ) ? false : true;
191 }
192
193 // Auto set time interval for shortly.
194 if ( 'shortly' === self::$notices[ $notice_args['id'] ]['dismiss_interval'] ) {
195 self::$notices[ $notice_args['id'] ]['dismiss_interval_time'] = DAY_IN_SECONDS;
196 }
197
198 return true;
199 }
200
201 /**
202 * Display notice.
203 *
204 * @since 1.8.9
205 *
206 */
207 public function render_admin_notices() {
208 // Bailout.
209 if ( empty( self::$notices ) ) {
210 return;
211 }
212
213 // Do not render notice on Gutenberg editor page.
214 if (
215 function_exists('is_gutenberg_page')
216 && is_gutenberg_page()
217 ) {
218 return;
219 }
220
221 $output = '';
222
223 foreach ( self::$notices as $notice_id => $notice ) {
224 // Check flag set to true to show notice.
225 if ( ! $notice['show'] ) {
226 continue;
227 }
228
229
230 // Render custom html.
231 if( ! empty( $notice['description_html'] ) ) {
232 $output .= "{$notice['description_html']} \n";
233 continue;
234 }
235
236 // Check if notice dismissible or not.
237 if ( ! self::$has_auto_dismissible_notice ) {
238 self::$has_auto_dismissible_notice = ( 'auto' === $notice['dismissible'] );
239 }
240
241 // Check if notice dismissible or not.
242 if ( ! self::$has_dismiss_interval_notice ) {
243 self::$has_dismiss_interval_notice = $notice['dismiss_interval'];
244 }
245
246 $css_id = ( false === strpos( $notice['id'], 'give' ) ? "give-{$notice['id']}" : $notice['id'] );
247
248 $css_class = 'give-notice notice ' . ( empty( $notice['dismissible'] ) ? 'non' : 'is' ) . "-dismissible {$notice['type']} notice-{$notice['type']}";
249 $output .= sprintf(
250 '<div id="%1$s" class="%2$s" data-dismissible="%3$s" data-dismissible-type="%4$s" data-dismiss-interval="%5$s" data-notice-id="%6$s" data-security="%7$s" data-dismiss-interval-time="%8$s" style="display: none">' . " \n",
251 $css_id,
252 $css_class,
253 give_clean( $notice['dismissible'] ),
254 $notice['dismissible_type'],
255 $notice['dismiss_interval'],
256 $notice['id'],
257 empty( $notice['dismissible_type'] ) ? '' : wp_create_nonce( "give_edit_{$notice_id}_notice" ),
258 $notice['dismiss_interval_time']
259 );
260
261 $output .= ( 0 === strpos( $notice['description'], '<div' ) || 0 === strpos( $notice['description'], '<p' ) ? $notice['description'] : "<p>{$notice['description']}</p>" );
262 $output .= "</div> \n";
263 }
264
265 echo $output;
266
267 $this->print_js();
268 }
269
270
271 /**
272 * Render give frontend notices.
273 *
274 * @since 1.8.9
275 * @access public
276 *
277 * @param int $form_id
278 */
279 public function render_frontend_notices( $form_id = 0 ) {
280 $errors = give_get_errors();
281
282 $request_form_id = isset( $_REQUEST['form-id'] ) ? absint( $_REQUEST['form-id'] ) : 0;
283
284 // Sanity checks first: Ensure that gateway returned errors display on the appropriate form.
285 if ( ! isset( $_POST['give_ajax'] ) && $request_form_id !== $form_id ) {
286 return;
287 }
288
289 if ( $errors ) {
290 self::print_frontend_errors( $errors );
291
292 give_clear_errors();
293 }
294 }
295
296 /**
297 * Renders notices for different actions depending on
298 * the type of form display option.
299 *
300 * @since 2.2
301 * @access public
302 *
303 * @param int $form_id Form ID.
304 *
305 * @return void
306 */
307 public function render_frontend_form_notices( $form_id ) {
308 $display_option = give_get_meta( $form_id, '_give_payment_display', true );
309
310 if ( 'modal' === $display_option ) {
311 add_action( 'give_payment_mode_top', array( $this, 'render_frontend_notices' ) );
312 } else {
313 add_action( 'give_pre_form', array( $this, 'render_frontend_notices' ), 11 );
314 }
315 }
316
317 /**
318 * Print notice js.
319 *
320 * @since 1.8.9
321 * @access private
322 */
323 private function print_js() {
324 if ( self::$has_auto_dismissible_notice ) :
325 ?>
326 <script>
327 jQuery(document).ready(function () {
328 // auto hide setting message in 5 seconds.
329 window.setTimeout(
330 function () {
331 jQuery('.give-notice[data-dismissible="auto"]').slideUp();
332 },
333 5000
334 );
335 })
336 </script>
337 <?php
338 endif;
339
340 if ( self::$has_dismiss_interval_notice ) :
341 ?>
342 <script>
343 jQuery(document).ready(function () {
344 var $body = jQuery('body');
345
346 $body.on('click', '.give_dismiss_notice', function (e) {
347 var $parent = jQuery(this).parents('.give-notice'),
348 custom_notice_data = {
349 'dismissible_type': jQuery(this).data('dismissible-type'),
350 'dismiss_interval': jQuery(this).data('dismiss-interval'),
351 'dismiss_interval_time': jQuery(this).data('dismiss-interval-time')
352 };
353
354 $parent.find('button.notice-dismiss').trigger('click', [custom_notice_data]);
355 return false;
356 });
357
358 $body.on('click', 'button.notice-dismiss', function (e, custom_notice_data) {
359 var $parent = jQuery(this).parents('.give-notice'),
360 custom_notice_data = custom_notice_data || {};
361
362 e.preventDefault();
363
364 var data = {
365 'give-action': 'dismiss_notices',
366 'notice_id': $parent.data('notice-id'),
367 'dismissible_type': $parent.data('dismissible-type'),
368 'dismiss_interval': $parent.data('dismiss-interval'),
369 'dismiss_interval_time': $parent.data('dismiss-interval-time'),
370 '_wpnonce': $parent.data('security')
371 };
372
373 if (Object.keys(custom_notice_data).length) {
374 jQuery.extend(data, custom_notice_data);
375 }
376
377 // Bailout.
378 if (
379 !data.dismiss_interval ||
380 !data.dismissible_type
381 ) {
382 return false;
383 }
384
385 jQuery.post(
386 '<?php echo admin_url(); ?>admin-ajax.php',
387 data,
388 function (response) {
389
390 })
391 })
392 });
393 </script>
394 <?php
395 endif;
396 }
397
398 /**
399 * Show notices
400 * Note: only for internal use
401 *
402 * @since 2.3.0
403 */
404 public function __reveal_notices(){
405 ?>
406 <script>
407 jQuery(document).ready(function($){
408 // Fix notice appearance issue.
409 window.setTimeout(
410 function(){
411 var give_notices = $('.give-notice');
412
413 if( give_notices.length ) {
414 give_notices.slideDown();
415 }
416 },
417 1000
418 );
419 });
420 </script>
421 <?php
422 }
423
424
425 /**
426 * Hide notice.
427 *
428 * @since 1.8.9
429 * @access public
430 */
431 public function dismiss_notices() {
432 $_post = give_clean( $_POST );
433 $notice_id = esc_attr( $_post['notice_id'] );
434
435 // Bailout.
436 if (
437 empty( $notice_id ) ||
438 empty( $_post['dismissible_type'] ) ||
439 empty( $_post['dismiss_interval'] ) ||
440 ! check_ajax_referer( "give_edit_{$notice_id}_notice", '_wpnonce' )
441 ) {
442 wp_send_json_error();
443 }
444
445 $notice_key = Give()->notices->get_notice_key( $notice_id, $_post['dismiss_interval'] );
446 if ( 'user' === $_post['dismissible_type'] ) {
447 $current_user = wp_get_current_user();
448 $notice_key = Give()->notices->get_notice_key( $notice_id, $_post['dismiss_interval'], $current_user->ID );
449 }
450
451 $notice_dismiss_time = ! empty( $_post['dismiss_interval_time'] ) ? $_post['dismiss_interval_time'] : null;
452
453 // Save option to hide notice.
454 Give_Cache::set( $notice_key, true, $notice_dismiss_time, true );
455
456 /**
457 * Fire the action when notice dismissed
458 *
459 * @since 2.2.0
460 */
461 do_action( 'give_notice_dismissed', $_post );
462
463 wp_send_json_success();
464 }
465
466
467 /**
468 * Get notice key.
469 *
470 * @since 1.8.9
471 * @access public
472 *
473 * @param string $notice_id
474 * @param string $dismiss_interval
475 * @param int $user_id
476 *
477 * @return string
478 */
479 public function get_notice_key( $notice_id, $dismiss_interval = null, $user_id = 0 ) {
480 $notice_key = "_give_notice_{$notice_id}";
481
482 if ( ! empty( $dismiss_interval ) ) {
483 $notice_key .= "_{$dismiss_interval}";
484 }
485
486 if ( $user_id ) {
487 $notice_key .= "_{$user_id}";
488 }
489
490 $notice_key = sanitize_key( $notice_key );
491
492 return $notice_key;
493 }
494
495
496 /**
497 * Get notice dismiss link.
498 *
499 * @param $notice_args
500 *
501 * @return string
502 */
503 public function get_dismiss_link( $notice_args ) {
504 $notice_args = wp_parse_args(
505 $notice_args,
506 array(
507 'title' => __( 'Click here', 'give' ),
508 'dismissible_type' => '',
509 'dismiss_interval' => '',
510 'dismiss_interval_time' => null,
511 )
512 );
513
514 return sprintf(
515 '<a href="#" class="give_dismiss_notice" data-dismissible-type="%1$s" data-dismiss-interval="%2$s" data-dismiss-interval-time="%3$s">%4$s</a>',
516 $notice_args['dismissible_type'],
517 $notice_args['dismiss_interval'],
518 $notice_args['dismiss_interval_time'],
519 $notice_args['title']
520 );
521 }
522
523
524 /**
525 * Check if notice dismissed or not
526 *
527 * @since 1.8.9
528 * @access public
529 *
530 * @param array $notice
531 *
532 * @return bool|null
533 */
534 public function is_notice_dismissed( $notice ) {
535 $notice_key = $this->get_notice_key( $notice['id'], $notice['dismiss_interval'] );
536 $is_notice_dismissed = false;
537
538 if ( 'user' === $notice['dismissible_type'] ) {
539 $current_user = wp_get_current_user();
540 $notice_key = Give()->notices->get_notice_key( $notice['id'], $notice['dismiss_interval'], $current_user->ID );
541 }
542
543 $notice_data = Give_Cache::get( $notice_key, true );
544
545 // Find notice dismiss link status if notice has extra dismissible links.
546 if ( ( empty( $notice_data ) || is_wp_error( $notice_data ) ) && ! empty( $notice['extra_links'] ) ) {
547
548 foreach ( $notice['extra_links'] as $extra_link ) {
549 $new_notice_data = wp_parse_args( $extra_link, $notice );
550 unset( $new_notice_data['extra_links'] );
551
552 if ( $is_notice_dismissed = $this->is_notice_dismissed( $new_notice_data ) ) {
553 return $is_notice_dismissed;
554 }
555 }
556 }
557
558 $is_notice_dismissed = ! empty( $notice_data ) && ! is_wp_error( $notice_data );
559
560 return $is_notice_dismissed;
561 }
562
563
564 /**
565 * Print frontend errors.
566 *
567 * @since 1.8.9
568 * @access public
569 *
570 * @param array $errors
571 */
572 public static function print_frontend_errors( $errors ) {
573 // Bailout.
574 if ( ! $errors ) {
575 return;
576 }
577
578 /**
579 * Change auto_dismissible to dismissible and set the value to true
580 *
581 * @since 1.8.14
582 */
583 $default_notice_args = array(
584 'dismissible' => true,
585 'dismiss_interval' => 5000,
586 );
587
588 // Note: we will remove give_errors class in future.
589 $classes = apply_filters( 'give_error_class', array( 'give_notices', 'give_errors' ) );
590
591 echo sprintf( '<div class="%s">', implode( ' ', $classes ) );
592
593 // Loop error codes and display errors.
594 foreach ( $errors as $error_id => $error ) {
595 // Backward compatibility v<1.8.11
596 if ( is_string( $error ) ) {
597 $error = array(
598 'message' => $error,
599 'notice_args' => array(),
600 );
601 }
602
603 $notice_args = wp_parse_args( $error['notice_args'], $default_notice_args );
604
605 /**
606 * Filter to modify Frontend Errors args before errors is display.
607 *
608 * @since 1.8.14
609 */
610 $notice_args = apply_filters( 'give_frontend_errors_args', $notice_args );
611
612 echo sprintf(
613 '<div class="give_error give_notice" id="give_error_%1$s" data-dismissible="%2$s" data-dismiss-interval="%3$d">
614 <p><strong>%4$s</strong>: %5$s</p>
615 </div>',
616 $error_id,
617 give_clean( $notice_args['dismissible'] ),
618 absint( $notice_args['dismiss_interval'] ),
619 esc_html__( 'Error', 'give' ),
620 $error['message']
621 );
622 }
623
624 echo '</div>';
625 }
626
627 /**
628 * Print frontend notice.
629 * Notice: notice type can be success/error/warning
630 *
631 * @since 1.8.9
632 * @access public
633 *
634 * @param string $message
635 * @param bool $echo
636 * @param string $notice_type
637 * @param array $notice_args
638 *
639 * @return string
640 */
641 public static function print_frontend_notice( $message, $echo = true, $notice_type = 'warning', $notice_args = array() ) {
642 if ( empty( $message ) ) {
643 return '';
644 }
645
646 /**
647 * Change auto_dismissible to dismissible and set the value to true
648 *
649 * @since 1.8.14
650 */
651 $default_notice_args = array(
652 'dismissible' => false,
653 'dismiss_type' => 'auto',
654 'dismiss_interval' => 5000,
655 );
656
657 $notice_args = wp_parse_args( $notice_args, $default_notice_args );
658
659 // Notice dismissible must be true for dismiss type.
660 $notice_args['dismiss_type'] = ! $notice_args['dismissible'] ? '' : $notice_args['dismiss_type'];
661
662 /**
663 * Filter to modify Frontend notice args before notices is display.
664 *
665 * @since 1.8.14
666 */
667 $notice_args = apply_filters( 'give_frontend_notice_args', $notice_args );
668
669 $close_icon = 'manual' === $notice_args['dismiss_type'] ?
670 sprintf(
671 '<img class="notice-dismiss give-notice-close" src="%s" />',
672 esc_url( GIVE_PLUGIN_URL . 'assets/dist/images/close.svg' )
673
674 ) :
675 '';
676
677 // Note: we will remove give_errors class in future.
678 $error = sprintf(
679 '<div class="give_notices give_errors" id="give_error_%1$s">
680 <p class="give_notice give_%1$s" data-dismissible="%2$s" data-dismiss-interval="%3$d" data-dismiss-type="%4$s">
681 %5$s
682 </p>
683 %6$s
684 </div>',
685 $notice_type,
686 give_clean( $notice_args['dismissible'] ),
687 absint( $notice_args['dismiss_interval'] ),
688 give_clean( $notice_args['dismiss_type'] ),
689 $message,
690 $close_icon
691
692 );
693
694 if ( ! $echo ) {
695 return $error;
696 }
697
698 echo $error;
699 }
700
701 /**
702 * Print Inline Notice.
703 * Note: dismissible feature will note work if notice will add to dom by javascript after document load.
704 *
705 * @param array $notice_args An array of notice arguments.
706 *
707 * @todo Implement render_admin_notices function within this function in future.
708 *
709 * @access public
710 * @since 1.8.17
711 *
712 * @return string
713 */
714 public function print_admin_notices( $notice_args = array() ) {
715 // Bailout.
716 if ( empty( $notice_args['description'] ) ) {
717 return '';
718 }
719
720 $defaults = array(
721 'id' => '',
722 'echo' => true,
723 'notice_type' => 'warning',
724 'dismissible' => true,
725 );
726 $notice_args = wp_parse_args( $notice_args, $defaults );
727
728 $output = '';
729 $css_id = ! empty( $notice_args['id'] ) ? $notice_args['id'] : uniqid( 'give-inline-notice-' );
730 $css_class = "notice-{$notice_args['notice_type']} give-notice notice inline";
731 $css_class .= ( $notice_args['dismissible'] ) ? ' is-dismissible' : '';
732 $output .= sprintf(
733 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
734 $css_id,
735 $css_class,
736 $notice_args['description']
737 );
738
739 if ( ! $notice_args['echo'] ) {
740 return $output;
741 }
742
743 echo $output;
744 }
745 }
746