init(); } /** * @return void */ private function init(){ if(!wpforo_is_session_started()) session_start(); } /** * * @param string|array $args * @param string $type (e.g. success|error) * @param string|array $s * * @return bool */ public function add( $args, $type = 'neutral', $s = array() ){ if(!$args) return FALSE; $args = (array) $args; if( $s && count($args) == 1 && is_array($s) && isset($s[0]) && !is_array($s[0]) ){ $s = array($s); }else{ $s = (array) $s; } if( wpforo_is_session_started() ){ $type = strtolower($type); if( !isset($_SESSION['wpforo_notices']) ) $_SESSION['wpforo_notices'] = array(); if( !isset($_SESSION['wpforo_notices'][$type]) ) $_SESSION['wpforo_notices'][$type] = array(); foreach($args as $key => $arg){ if( $s && isset($s[$key]) ){ $args[$key] = wpforo_sprintf_array( wpforo_phrase($arg, FALSE), $s[$key] ); }else{ $args[$key] = wpforo_phrase($arg, FALSE); } } $_SESSION['wpforo_notices'][$type] = array_merge( (array) $_SESSION['wpforo_notices'][$type], (array) $args); $_SESSION['wpforo_notices'][$type] = array_unique($_SESSION['wpforo_notices'][$type]); return TRUE; } return FALSE; } /** * * @return bool * */ public function clear(){ if( wpforo_is_session_started() ){ $_SESSION['wpforo_notices'] = array(); return TRUE; } return FALSE; } /** *
success msg text
error msg text
* * @return string */ public function get_notices(){ $inner = ''; if(empty($_SESSION['wpforo_notices'])) return $inner; foreach($_SESSION['wpforo_notices'] as $type => $notice){ $notice = (array) $notice; foreach ($notice as $msg){ if( !is_array($msg) ){ $msg = trim($msg); if($msg) $inner .= sprintf('%s
', sanitize_html_class($type), $msg); } } } $this->clear(); return $inner; } /** * * @param bool $frontend (default TRUE) * * @return void */ public function show( $frontend = TRUE ){ if(empty($_SESSION['wpforo_notices'])) return; $inner = ''; $backend_inner = ''; foreach($_SESSION['wpforo_notices'] as $type => $notice){ $notice = (array) $notice; foreach ($notice as $msg){ if( !is_array($msg) ){ $msg = trim($msg); if($msg) { $inner .= sprintf('%s
', sanitize_html_class($type), $msg); $backend_inner .= sprintf( '%s