PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / trunk
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization vtrunk
4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 All 135 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Notification.php +61 -9 2.5.7 → trunk 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;
87 + echo $notification_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, already escaped internally.
88 88
89 89 do_action( $notification_details['id'] . '_after_render' );
90 90 self::render_snippets();
91 91 }
@@ -255,8 +255,9 @@
255 255 public static function get_notification_html( $notification_details ) {
256 256 $default = [
257 257 'id' => '',
258 258 'heading' => '',
259 + 'img_src' => '',
259 260 'message' => '',
260 261 'ctas' => [
261 262 'confirm' => [
262 263 'link' => '#',
@@ -266,18 +267,28 @@
266 267 'link' => '#',
267 268 'text' => '',
268 269 ],
269 270 ],
271 + 'type' => 'success',
270 272 ];
271 273 $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">';
272 278
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 -
275 279 if ( ! empty( $notification_details['heading'] ) ) {
276 280 $notification_html .= sprintf( '<h4>%s</h4>', wp_kses_post( $notification_details['heading'] ) );
277 281 }
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 + }
278 286 if ( ! empty( $notification_details['message'] ) ) {
279 287 $notification_html .= wp_kses_post( $notification_details['message'] );
288 + if ( ! empty( $notification_details['img_src'] ) ) {
289 + $notification_html .= '</div>';
290 + }
280 291 }
281 292 $notification_html .= '<div class="actions">';
282 293
283 294 if ( ! empty( $notification_details['ctas']['confirm']['text'] ) ) {
@@ -315,8 +326,20 @@
315 326 .themeisle-sdk-notification-box {
316 327 padding: 3px;
317 328 }
318 329
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 +
319 342 .themeisle-sdk-notification-box .actions {
320 343 margin-top: 6px;
321 344 margin-bottom: 4px;
322 345 }
@@ -339,14 +362,16 @@
339 362 }
340 363 $.post(
341 364 ajaxurl,
342 365 {
343 - 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>',
366 + 'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
344 367 'action': 'themeisle_sdk_dismiss_notice',
345 368 'id': notification_id,
346 - 'confirm': confirm
347 - }
348 - );
369 + 'confirm': confirm,
370 + },
371 + ).fail(function() {
372 + location.href = encodeURI(link.attr('href'));
373 + });
349 374 if (confirm === 'yes') {
350 375 $(this).trigger('themeisle-sdk:confirmed');
351 376 } else {
352 377 $(this).trigger('themeisle-sdk:canceled');
@@ -351,9 +376,9 @@
351 376 } else {
352 377 $(this).trigger('themeisle-sdk:canceled');
353 378 }
354 379 container.hide();
355 - if (link.attr('href') === '#') {
380 + if (confirm === 'no' || link.attr('href') === '#') {
356 381 return false;
357 382 }
358 383 });
359 384 });
@@ -364,9 +389,9 @@
364 389
365 390 /**
366 391 * Dismiss the notification.
367 392 */
368 - static function dismiss() {
393 + public static function dismiss() {
369 394 check_ajax_referer( (string) __CLASS__, 'nonce' );
370 395
371 396 $id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
372 397 $confirm = isset( $_POST['confirm'] ) ? sanitize_text_field( $_POST['confirm'] ) : 'no';
@@ -373,8 +398,9 @@
373 398
374 399 if ( empty( $id ) ) {
375 400 wp_send_json( [] );
376 401 }
402 + self::setup_notifications();
377 403 $ids = wp_list_pluck( self::$notifications, 'id' );
378 404 if ( ! in_array( $id, $ids, true ) ) {
379 405 wp_send_json( [] );
380 406 }
@@ -382,8 +408,33 @@
382 408 update_option( $id, $confirm );
383 409 do_action( $id . '_process_confirm', $confirm );
384 410 wp_send_json( [] );
385 411 }
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 + }
386 437
387 438 /**
388 439 * Check if we should load the notification module.
389 440 *
@@ -455,8 +506,9 @@
455 506 );
456 507 self::$notifications = $notifications;
457 508 add_action( 'admin_notices', array( __CLASS__, 'show_notification' ) );
458 509 add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', array( __CLASS__, 'dismiss' ) );
510 + add_action( 'admin_head', array( __CLASS__, 'dismiss_get' ) );
459 511 add_action( 'admin_head', array( __CLASS__, 'setup_notifications' ) );
460 512
461 513 return $this;
462 514 }