notifications = array(); add_action('admin_notices', array($this, 'generate_active_notices')); add_action( 'wp_ajax_essb_notice_dismiss', array( $this, 'notice_dismiss' ) ); } /** * Register a new notification inside the pool * * @param unknown_type $key * @param unknown_type $text * @param unknown_type $buttons * @param unknown_type $start_date * @param unknown_type $end_date */ public function add_notification($key, $text, $buttons = array(), $type = '', $start_date = '', $end_date = '') { if (empty($key)) { return; } // notice was dismissed by the user if ($this->is_dismissed($key)){ return; } // notice has a timeframe and it is not active right now if (!$this->is_active($key, $start_date, $end_date)) { return; } $buttons = $this->default_button($buttons); $this->notifications[$key] = array('text' => $text, 'buttons' => $buttons, 'type' => $type, 'start' => $start_date, 'end' => $end_date); } public function add_interface_notification($key, $text, $buttons = array(), $type = '', $start_date = '', $end_date = '') { if (empty($key)) { return; } // notice was dismissed by the user if ($this->is_dismissed($key)){ return; } // notice has a timeframe and it is not active right now if (!$this->is_active($key, $start_date, $end_date)) { return; } $buttons = $this->default_button($buttons); $this->interface_notifications[$key] = array('text' => $text, 'buttons' => $buttons, 'type' => $type, 'start' => $start_date, 'end' => $end_date); } /** * Notification is dismissed by user * * @param unknown_type $key */ public function is_dismissed($key) { $dismissed_notices = get_option( 'essb_dismissed_notices', false ); if ( false === $dismissed_notices ) { $dismissed_notices = array(); } if (!is_array($dismissed_notices)) { $dismissed_notices = array(); } return isset($dismissed_notices[$key]) ? true : false; } /** * Notification has a period of appearance. Check if it is active * * @param unknown_type $key * @param unknown_type $fromdate * @param unknown_type $todate */ public function is_active($key, $fromdate = '', $todate = '') { $is_active = true; if ($fromdate != '' || $todate != '') { $today = date ( "Ymd" ); $fromdate = str_replace ( '-', '', $fromdate ); $todate = str_replace ( '-', '', $todate ); if (intval ( $today ) < intval ( $fromdate ) && intval ( $today ) > intval ( $todate )) { $is_active = false; } } return $is_active; } public function generate_active_notices() { $has_one = false; foreach ($this->notifications as $key => $data) { $type = isset($data['type']) ? $data['type'] : 'info'; if ($type == '') { $type = 'info'; } //type = warning, error, success, info echo '
Easy Social Share Buttons for WordPress: '.$data['text'].'
'; echo '