| 1 |
<?php |
| 2 |
|
| 3 |
namespace BubbleMenu\Admin; |
| 4 |
|
| 5 |
use BubbleMenu\WOWP_Plugin; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
class AdminNotices { |
| 10 |
|
| 11 |
|
| 12 |
public static function init(): void { |
| 13 |
add_action( 'admin_notices', [ __CLASS__, 'admin_notice' ] ); |
| 14 |
} |
| 15 |
|
| 16 |
public static function admin_notice(): bool { |
| 17 |
|
| 18 |
if ( ! isset( $_GET['page'] ) ) { |
| 19 |
return false; |
| 20 |
} |
| 21 |
|
| 22 |
if ( $_GET['page'] !== WOWP_Plugin::SLUG ) { |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! empty( $_GET['notice'] ) && $_GET['notice'] === 'save_item' ) { |
| 27 |
self::save_item(); |
| 28 |
} elseif ( ! empty( $_GET['notice'] ) && $_GET['notice'] === 'remove_item' ) { |
| 29 |
self::remove_item(); |
| 30 |
} |
| 31 |
|
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
public static function save_item(): void { |
| 36 |
$nonce = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ) : ''; |
| 37 |
|
| 38 |
if ( ! empty( $nonce ) && wp_verify_nonce( $nonce, 'save-item' ) ) { |
| 39 |
$text = __( 'Item Saved', 'bubble-menu' ); |
| 40 |
echo '<div class="wpie-notice notice notice-success is-dismissible">' . esc_html( $text ) . '</div>'; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
public static function remove_item(): void { |
| 45 |
$text = __( 'Item Remove', 'bubble-menu' ); |
| 46 |
echo '<div class="wpie-notice notice notice-warning is-dismissible">' . esc_html( $text ) . '</div>'; |
| 47 |
} |
| 48 |
|
| 49 |
} |