array(), 'infos'=>array(), 'alerts'=>array(), 'confirms'=>array()); function __construct(){ session_start(); //Grab from session if( !empty($_SESSION['events-manager']['notices']) && is_serialized($_SESSION['events-manager']['notices']) ){ $this->notices = unserialize($_SESSION['events-manager']['notices']); } //Flush notices that weren't made to stay cross-requests, we can do this if initialized immediately. foreach($this->notices as $notice_type => $notices){ foreach ($notices as $key => $notice){ if( empty($notice['static']) ){ unset($this->notices[$notice_type][$key]); }else{ unset($this->notices[$notice_type][$key]['static']); //so it gets removed next request } } } add_action('shutdown', array(&$this,'destruct')); add_filter('wp_redirect', array(&$this,'destruct'), 1,1); } function destruct($redirect = false){ //die('destructing'); $_SESSION['events-manager']['notices'] = serialize($this->notices); return $redirect; } function __toString(){ $string = false; if(count($this->notices['errors']) > 0){ $string .= "
{$error['string']}
"; if( empty($error['static']) || $error['static'] !== true){ $this->remove($key, $type); } } return $string; } return false; } function count($type){ if( isset($this->notices[$type]) ){ return count($this->notices[$type]); } return 0; } /* Errors */ function add_error($string, $static=false){ return $this->add($string, 'errors', $static); } function remove_error($key){ return $this->remove($key, 'errors'); } function get_errors(){ return $this->get('errors'); } function count_errors(){ return $this->count('errors'); } /* Alerts */ function add_alert($string, $static=false){ return $this->add($string, 'alerts', $static); } function remove_alert($key){ return $this->remove($key, 'alerts'); } function get_alerts(){ return $this->get('alerts'); } function count_alerts(){ return $this->count('alerts'); } /* Info */ function add_info($string, $static=false){ return $this->add($string, 'infos', $static); } function remove_info($key){ return $this->remove($key, 'infos'); } function get_infos(){ return $this->get('infos'); } function count_infos(){ return $this->count('infos'); } /* Confirms */ function add_confirm($string, $static=false){ return $this->add($string, 'confirms', $static); } function remove_confirm($key){ return $this->remove($key, 'confirms'); } function get_confirms(){ return $this->get('confirms'); } function count_confirms(){ return $this->count('confirms'); } //Iterator Implementation function rewind(){ reset($this->bookings); } function current(){ $var = current($this->bookings); return $var; } function key(){ $var = key($this->bookings); return $var; } function next(){ $var = next($this->bookings); return $var; } function valid(){ $key = key($this->bookings); $var = ($key !== NULL && $key !== FALSE); return $var; } } global $EM_Notices; $EM_Notices = new EM_Notices(); ?>