| @@ -1,46 +1,45 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace WPCoder\Admin; |
| 4 | 4 | |
| 5 | -use WPCoder\WOW_Plugin; | |
| 5 | +use WPCoder\WPCoder; | |
| 6 | 6 | |
| 7 | 7 | defined( 'ABSPATH' ) || exit; |
| 8 | 8 | |
| 9 | 9 | class AdminNotices { |
| 10 | 10 | |
| 11 | - | |
| 12 | 11 | public function __construct() { |
| 13 | 12 | add_action( 'admin_notices', [ $this, 'admin_notice' ] ); |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | public function admin_notice() { |
| 17 | - $notice = $_GET['notice'] ?? ''; | |
| 18 | - | |
| 19 | - if(!isset($_GET['page'])) { | |
| 20 | - return false; | |
| 16 | + if ( ! isset( $_GET['page'], $_GET['notice'] ) ) { | |
| 17 | + return; | |
| 21 | 18 | } |
| 22 | 19 | |
| 23 | - if($_GET['page'] !== WOW_Plugin::SLUG) { | |
| 24 | - return false; | |
| 25 | - } | |
| 20 | + $page = $_GET['page']; | |
| 21 | + $notice = $_GET['notice']; | |
| 26 | 22 | |
| 27 | - | |
| 28 | - | |
| 29 | - if ( ! empty( $notice ) && $notice === 'save_item' ) { | |
| 30 | - $this->save_item(); | |
| 31 | - } elseif ( ! empty( $notice ) && $notice === 'remove_item' ) { | |
| 32 | - $this->remove_item(); | |
| 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 | + } | |
| 33 | 32 | } |
| 34 | 33 | } |
| 35 | 34 | |
| 36 | 35 | public function save_item() { |
| 37 | - $text = __( 'Item saved.', 'wpcoder' ); | |
| 38 | - 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>'; | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | 40 | public function remove_item() { |
| 42 | - $text = __( 'Item delete.', 'wpcoder' ); | |
| 43 | - 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>'; | |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | } |