| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class AdminNotices |
| 5 |
* |
| 6 |
* This class handles the admin notices for the plugin. |
| 7 |
* |
| 8 |
* @package WowPlugin |
| 9 |
* @subpackage Admin |
| 10 |
* @author Dmytro Lobov <dev@wow-company.com>, Wow-Company |
| 11 |
* @copyright 2024 Dmytro Lobov |
| 12 |
* @license GPL-2.0+ |
| 13 |
* |
| 14 |
*/ |
| 15 |
|
| 16 |
namespace FloatMenuLite\Admin; |
| 17 |
|
| 18 |
use FloatMenuLite\WOWP_Plugin; |
| 19 |
|
| 20 |
defined( 'ABSPATH' ) || exit; |
| 21 |
|
| 22 |
class AdminNotices { |
| 23 |
|
| 24 |
|
| 25 |
public static function init(): void { |
| 26 |
add_action( 'admin_notices', [ __CLASS__, 'admin_notice' ] ); |
| 27 |
} |
| 28 |
|
| 29 |
public static function admin_notice(): bool { |
| 30 |
|
| 31 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce verification is handled elsewhere. |
| 32 |
if ( ! isset( $_GET['page'] ) ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
if ( $_GET['page'] !== WOWP_Plugin::SLUG ) { |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
$notice = isset( $_GET['notice'] ) ? sanitize_text_field( wp_unslash( $_GET['notice'] ) ) : ''; |
| 41 |
// phpcs:enable |
| 42 |
|
| 43 |
if ( ! empty( $notice ) && $notice === 'save_item' ) { |
| 44 |
self::save_item(); |
| 45 |
} elseif ( ! empty( $notice ) && $notice === 'remove_item' ) { |
| 46 |
self::remove_item(); |
| 47 |
} |
| 48 |
|
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
public static function save_item(): void { |
| 53 |
if ( isset( $_REQUEST['nonce'] ) ) { |
| 54 |
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ); |
| 55 |
|
| 56 |
if ( wp_verify_nonce( $nonce, 'save-item' ) ) { |
| 57 |
$text = __( 'Item Saved', 'float-menu' ); |
| 58 |
echo '<div class="wpie-notice notice notice-success is-dismissible">' . esc_html( $text ) . '</div>'; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
public static function remove_item(): void { |
| 63 |
$text = __( 'Item Remove', 'float-menu' ); |
| 64 |
echo '<div class="wpie-notice notice notice-warning is-dismissible">' . esc_html( $text ) . '</div>'; |
| 65 |
} |
| 66 |
|
| 67 |
} |