← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Notification.php
+9
-61
3.10.2
→
3.4.10
View file →
| @@ -83,9 +83,9 @@ | ||
| 83 | 83 | } |
| 84 | 84 | $notification_html = self::get_notification_html( $notification_details ); |
| 85 | 85 | do_action( $notification_details['id'] . '_before_render' ); |
| 86 | 86 | |
| 87 | - echo $notification_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, already escaped internally. | |
| 87 | + echo $notification_html; | |
| 88 | 88 | |
| 89 | 89 | do_action( $notification_details['id'] . '_after_render' ); |
| 90 | 90 | self::render_snippets(); |
| 91 | 91 | } |
| @@ -255,9 +255,8 @@ | ||
| 255 | 255 | public static function get_notification_html( $notification_details ) { |
| 256 | 256 | $default = [ |
| 257 | 257 | 'id' => '', |
| 258 | 258 | 'heading' => '', |
| 259 | - 'img_src' => '', | |
| 260 | 259 | 'message' => '', |
| 261 | 260 | 'ctas' => [ |
| 262 | 261 | 'confirm' => [ |
| 263 | 262 | 'link' => '#', |
| @@ -267,28 +266,18 @@ | ||
| 267 | 266 | 'link' => '#', |
| 268 | 267 | 'text' => '', |
| 269 | 268 | ], |
| 270 | 269 | ], |
| 271 | - 'type' => 'success', | |
| 272 | 270 | ]; |
| 273 | 271 | $notification_details = wp_parse_args( $notification_details, $default ); |
| 274 | - global $pagenow; | |
| 275 | - $type = in_array( $notification_details['type'], [ 'success', 'info', 'warning', 'error' ], true ) ? $notification_details['type'] : 'success'; | |
| 276 | - $notification_details['ctas']['cancel']['link'] = wp_nonce_url( add_query_arg( [ 'nid' => $notification_details['id'] ], admin_url( $pagenow ) ), $notification_details['id'], 'tsdk_dismiss_nonce' ); | |
| 277 | - $notification_html = '<div class="notice notice-' . $type . ' is-dismissible themeisle-sdk-notice" data-notification-id="' . esc_attr( $notification_details['id'] ) . '" id="' . esc_attr( $notification_details['id'] ) . '-notification"> <div class="themeisle-sdk-notification-box">'; | |
| 278 | 272 | |
| 273 | + $notification_html = '<div class="notice notice-success is-dismissible themeisle-sdk-notice" data-notification-id="' . esc_attr( $notification_details['id'] ) . '" id="' . esc_attr( $notification_details['id'] ) . '-notification"> <div class="themeisle-sdk-notification-box">'; | |
| 274 | + | |
| 279 | 275 | if ( ! empty( $notification_details['heading'] ) ) { |
| 280 | 276 | $notification_html .= sprintf( '<h4>%s</h4>', wp_kses_post( $notification_details['heading'] ) ); |
| 281 | 277 | } |
| 282 | - if ( ! empty( $notification_details['img_src'] ) ) { | |
| 283 | - $notification_html .= '<div class="wrap-flex">'; | |
| 284 | - $notification_html .= sprintf( '<img src="%s" alt="%s" />', esc_attr( $notification_details['img_src'] ), esc_attr( $notification_details['heading'] ) ); | |
| 285 | - } | |
| 286 | 278 | if ( ! empty( $notification_details['message'] ) ) { |
| 287 | 279 | $notification_html .= wp_kses_post( $notification_details['message'] ); |
| 288 | - if ( ! empty( $notification_details['img_src'] ) ) { | |
| 289 | - $notification_html .= '</div>'; | |
| 290 | - } | |
| 291 | 280 | } |
| 292 | 281 | $notification_html .= '<div class="actions">'; |
| 293 | 282 | |
| 294 | 283 | if ( ! empty( $notification_details['ctas']['confirm']['text'] ) ) { |
| @@ -326,20 +315,8 @@ | ||
| 326 | 315 | .themeisle-sdk-notification-box { |
| 327 | 316 | padding: 3px; |
| 328 | 317 | } |
| 329 | 318 | |
| 330 | - .themeisle-sdk-notification-box .wrap-flex { | |
| 331 | - display: flex; | |
| 332 | - align-items: center; | |
| 333 | - justify-content: start; | |
| 334 | - gap: 12px; | |
| 335 | - } | |
| 336 | - | |
| 337 | - .themeisle-sdk-notification-box .wrap-flex img { | |
| 338 | - width: 42px; | |
| 339 | - object-fit: cover; | |
| 340 | - } | |
| 341 | - | |
| 342 | 319 | .themeisle-sdk-notification-box .actions { |
| 343 | 320 | margin-top: 6px; |
| 344 | 321 | margin-bottom: 4px; |
| 345 | 322 | } |
| @@ -362,16 +339,14 @@ | ||
| 362 | 339 | } |
| 363 | 340 | $.post( |
| 364 | 341 | ajaxurl, |
| 365 | 342 | { |
| 366 | - 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>', | |
| 343 | + 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>', | |
| 367 | 344 | 'action': 'themeisle_sdk_dismiss_notice', |
| 368 | 345 | 'id': notification_id, |
| 369 | - 'confirm': confirm, | |
| 370 | - }, | |
| 371 | - ).fail(function() { | |
| 372 | - location.href = encodeURI(link.attr('href')); | |
| 373 | - }); | |
| 346 | + 'confirm': confirm | |
| 347 | + } | |
| 348 | + ); | |
| 374 | 349 | if (confirm === 'yes') { |
| 375 | 350 | $(this).trigger('themeisle-sdk:confirmed'); |
| 376 | 351 | } else { |
| 377 | 352 | $(this).trigger('themeisle-sdk:canceled'); |
| @@ -376,9 +351,9 @@ | ||
| 376 | 351 | } else { |
| 377 | 352 | $(this).trigger('themeisle-sdk:canceled'); |
| 378 | 353 | } |
| 379 | 354 | container.hide(); |
| 380 | - if (confirm === 'no' || link.attr('href') === '#') { | |
| 355 | + if (link.attr('href') === '#') { | |
| 381 | 356 | return false; |
| 382 | 357 | } |
| 383 | 358 | }); |
| 384 | 359 | }); |
| @@ -389,9 +364,9 @@ | ||
| 389 | 364 | |
| 390 | 365 | /** |
| 391 | 366 | * Dismiss the notification. |
| 392 | 367 | */ |
| 393 | - public static function dismiss() { | |
| 368 | + static function dismiss() { | |
| 394 | 369 | check_ajax_referer( (string) __CLASS__, 'nonce' ); |
| 395 | 370 | |
| 396 | 371 | $id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : ''; |
| 397 | 372 | $confirm = isset( $_POST['confirm'] ) ? sanitize_text_field( $_POST['confirm'] ) : 'no'; |
| @@ -398,9 +373,8 @@ | ||
| 398 | 373 | |
| 399 | 374 | if ( empty( $id ) ) { |
| 400 | 375 | wp_send_json( [] ); |
| 401 | 376 | } |
| 402 | - self::setup_notifications(); | |
| 403 | 377 | $ids = wp_list_pluck( self::$notifications, 'id' ); |
| 404 | 378 | if ( ! in_array( $id, $ids, true ) ) { |
| 405 | 379 | wp_send_json( [] ); |
| 406 | 380 | } |
| @@ -408,33 +382,8 @@ | ||
| 408 | 382 | update_option( $id, $confirm ); |
| 409 | 383 | do_action( $id . '_process_confirm', $confirm ); |
| 410 | 384 | wp_send_json( [] ); |
| 411 | 385 | } |
| 412 | - /** | |
| 413 | - * Dismiss the notification. | |
| 414 | - */ | |
| 415 | - public static function dismiss_get() { | |
| 416 | - $is_nonce_dismiss = sanitize_text_field( isset( $_GET['tsdk_dismiss_nonce'] ) ? $_GET['tsdk_dismiss_nonce'] : '' ); | |
| 417 | - if ( strlen( $is_nonce_dismiss ) < 5 ) { | |
| 418 | - return; | |
| 419 | - } | |
| 420 | - $id = sanitize_text_field( isset( $_GET['nid'] ) ? $_GET['nid'] : '' ); | |
| 421 | - if ( empty( $id ) ) { | |
| 422 | - return; | |
| 423 | - } | |
| 424 | - $nonce = wp_verify_nonce( sanitize_text_field( $_GET['tsdk_dismiss_nonce'] ), $id ); | |
| 425 | - if ( $nonce !== 1 ) { | |
| 426 | - return; | |
| 427 | - } | |
| 428 | - $ids = wp_list_pluck( self::$notifications, 'id' ); | |
| 429 | - if ( ! in_array( $id, $ids, true ) ) { | |
| 430 | - return; | |
| 431 | - } | |
| 432 | - $confirm = 'no'; | |
| 433 | - self::set_last_active_notification_timestamp(); | |
| 434 | - update_option( $id, $confirm ); | |
| 435 | - do_action( $id . '_process_confirm', $confirm ); | |
| 436 | - } | |
| 437 | 386 | |
| 438 | 387 | /** |
| 439 | 388 | * Check if we should load the notification module. |
| 440 | 389 | * |
| @@ -506,9 +455,8 @@ | ||
| 506 | 455 | ); |
| 507 | 456 | self::$notifications = $notifications; |
| 508 | 457 | add_action( 'admin_notices', array( __CLASS__, 'show_notification' ) ); |
| 509 | 458 | add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', array( __CLASS__, 'dismiss' ) ); |
| 510 | - add_action( 'admin_head', array( __CLASS__, 'dismiss_get' ) ); | |
| 511 | 459 | add_action( 'admin_head', array( __CLASS__, 'setup_notifications' ) ); |
| 512 | 460 | |
| 513 | 461 | return $this; |
| 514 | 462 | } |