class-admin-feed-columns.php
2 years ago
class-admin-menu.php
3 years ago
class-admin-notice.php
3 years ago
class-admin-page.php
3 years ago
class-admin-rateus-ajax.php
3 years ago
class-admin-rev.php
3 years ago
class-admin-tophead.php
3 years ago
class-admin-notice.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes\Admin; |
| 4 | |
| 5 | class Admin_Notice { |
| 6 | |
| 7 | private $notice_id; |
| 8 | |
| 9 | private static $plugin_notices = array( |
| 10 | 'settings_active_0' => 'Plugin disabled successfully.', |
| 11 | 'settings_active_1' => 'Plugin enabled successfully.', |
| 12 | 'settings_save' => 'Settings saved successfully.', |
| 13 | 'settings_create_db' => 'Database re-created successfully.', |
| 14 | 'settings_reset' => 'Settings deleted successfully.', |
| 15 | 'settings_install' => 'Plugin installed from scratch successfully.', |
| 16 | 'settings_reset_all' => 'All data including settings and reviews deleted successfully.', |
| 17 | 'settings_debug_mode_0' => 'Debug mode disabled successfully.', |
| 18 | 'settings_debug_mode_1' => 'Debug mode enabled successfully.', |
| 19 | 'settings_update_db' => 'Database updated successfully.', |
| 20 | 'settings_revupd_cron_0' => 'Reviews update daily schedule disabled successfully.', |
| 21 | 'settings_revupd_cron_1' => 'Reviews update daily schedule enabled successfully.', |
| 22 | ); |
| 23 | |
| 24 | public function register() { |
| 25 | add_filter('removable_query_args', array($this, 'remove_query_args')); |
| 26 | add_action('admin_notices', array($this, 'parse_notices_from_url')); |
| 27 | add_action('admin_notices', array($this, 'render_notices')); |
| 28 | } |
| 29 | |
| 30 | public function remove_query_args($args) { |
| 31 | return array_merge($args, array('grw_notice')); |
| 32 | } |
| 33 | |
| 34 | public function parse_notices_from_url() { |
| 35 | if (!isset($_GET['grw_notice'])) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $this->notice_id = sanitize_text_field(wp_unslash($_GET['grw_notice'])); |
| 40 | } |
| 41 | |
| 42 | public function render_notices() { |
| 43 | if (empty($this->notice_id) || !$this->is_valid_screen()) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | if (doing_action('admin_notices') && $this->needs_repositioned()) { |
| 48 | add_action('grw_admin_notices', array($this, 'render_notices')); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | ?> |
| 53 | <div class="notice notice-<?php echo get_option('grw_notice_type'); ?> is-dismissible"> |
| 54 | <p><?php echo $this->notice_id != 'custom_msg' ? self::$plugin_notices[$this->notice_id] : get_option('grw_notice_msg'); ?></p> |
| 55 | </div> |
| 56 | <?php |
| 57 | |
| 58 | $this->notice_id = ''; |
| 59 | } |
| 60 | |
| 61 | protected function is_valid_screen($screen_id = '') { |
| 62 | if ($screen_id === '') { |
| 63 | $screen = get_current_screen(); |
| 64 | $screen_id = $screen->id; |
| 65 | } |
| 66 | |
| 67 | return ($screen_id === 'dashboard' || $screen_id === 'plugins' || strpos($screen_id, 'grw') !== false) ? true : false; |
| 68 | } |
| 69 | |
| 70 | protected function needs_repositioned($screen_id = '') { |
| 71 | if ($screen_id === '') { |
| 72 | $screen = get_current_screen(); |
| 73 | $screen_id = $screen->id; |
| 74 | } |
| 75 | |
| 76 | $screen_ids = array('google-reviews_page_grw-settings'); |
| 77 | return in_array($screen_id, $screen_ids) ? true : false; |
| 78 | } |
| 79 | |
| 80 | } |
| 81 |