| @@ -1,33 +1,45 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace WPCoder\Admin; |
| 4 | 4 | |
| 5 | +use WPCoder\WPCoder; | |
| 6 | + | |
| 5 | 7 | defined( 'ABSPATH' ) || exit; |
| 6 | 8 | |
| 7 | 9 | class AdminNotices { |
| 8 | 10 | |
| 9 | - | |
| 10 | 11 | public function __construct() { |
| 11 | 12 | add_action( 'admin_notices', [ $this, 'admin_notice' ] ); |
| 12 | 13 | } |
| 13 | 14 | |
| 14 | 15 | public function admin_notice() { |
| 15 | - $notice = $_GET['notice'] ?? ''; | |
| 16 | - if ( ! empty( $notice ) && $notice === 'save_item' ) { | |
| 17 | - $this->save_item(); | |
| 18 | - } elseif ( ! empty( $notice ) && $notice === 'remove_item' ) { | |
| 19 | - $this->remove_item(); | |
| 16 | + if ( ! isset( $_GET['page'], $_GET['notice'] ) ) { | |
| 17 | + return; | |
| 20 | 18 | } |
| 19 | + | |
| 20 | + $page = $_GET['page']; | |
| 21 | + $notice = $_GET['notice']; | |
| 22 | + | |
| 23 | + if ( in_array( $page, [ WPCoder::SLUG, WPCoder::SLUG . '-settings' ], true ) ) { | |
| 24 | + switch ( $notice ) { | |
| 25 | + case 'save_item': | |
| 26 | + $this->save_item(); | |
| 27 | + break; | |
| 28 | + case 'remove_item': | |
| 29 | + $this->remove_item(); | |
| 30 | + break; | |
| 31 | + } | |
| 32 | + } | |
| 21 | 33 | } |
| 22 | 34 | |
| 23 | 35 | public function save_item() { |
| 24 | - $text = __( 'Item saved.', 'wpcoder' ); | |
| 25 | - echo '<div class="wowp-notice notice notice-success is-dismissible">' . esc_html( $text ) . '</div>'; | |
| 36 | + $text = __( 'Item saved successfully.', 'wp-coder' ); | |
| 37 | + echo '<div class="wowp-notification notification-success notice notice-success is-dismissible">' . esc_html( $text ) . '</div>'; | |
| 26 | 38 | } |
| 27 | 39 | |
| 28 | 40 | public function remove_item() { |
| 29 | - $text = __( 'Item delete.', 'wpcoder' ); | |
| 30 | - echo '<div class="wowp-notice notice notice-warning is-dismissible">' . esc_html( $text ) . '</div>'; | |
| 41 | + $text = __( 'Item has been deleted', 'wp-coder' ); | |
| 42 | + echo '<div class="wowp-notification notification-warning notice notice-warning is-dismissible">' . esc_html( $text ) . '</div>'; | |
| 31 | 43 | } |
| 32 | 44 | |
| 33 | 45 | } |