getRealFile() ){ $error->setCallee(1); } // write error immediately under WP_CLI if( 'cli' === PHP_SAPI && class_exists('WP_CLI',false) ){ $error->logCli(); return $error; } // else buffer notices for displaying when UI is ready $notices->errors[] = $error; // do late flush if we missed the boat if( did_action('loco_admin_init') ){ $notices->on_loco_admin_init(); } if( did_action('admin_notices') ){ $notices->on_admin_notices(); } // Log message automatically if enabled if( $error->loggable() ){ $error->log(); } return $error; } /** * Raise a success message * @param string $message * @return Loco_error_Exception */ public static function success( $message ){ $notice = new Loco_error_Success($message); return self::add( $notice->setCallee(1) ); } /** * Raise a failure message * @param string $message * @return Loco_error_Exception */ public static function err( $message ){ $notice = new Loco_error_Exception($message); return self::add( $notice->setCallee(1) ); } /** * Raise a warning message * @param string $message * @return Loco_error_Exception */ public static function warn( $message ){ $notice = new Loco_error_Warning($message); return self::add( $notice->setCallee(1) ); } /** * Raise a generic info message * @param string $message * @return Loco_error_Exception */ public static function info( $message ){ $notice = new Loco_error_Notice($message); return self::add( $notice->setCallee(1) ); } /** * Raise a debug notice, if debug is enabled * @param string $message * @return Loco_error_Debug */ public static function debug( $message ){ $notice = new Loco_error_Debug($message); $notice->setCallee(1); loco_debugging() and self::add( $notice ); return $notice; } /** * Destroy and return buffer * @return Loco_error_Exception[] */ public static function destroy(){ $notices = self::$singleton; if( $notices instanceof Loco_error_AdminNotices ){ $buffer = $notices->errors; $notices->errors = []; self::$singleton = null; return $buffer; } return []; } /** * Destroy and return all serialized notices, suitable for ajax response * @return array */ public static function destroyAjax(){ $data = []; foreach( self::destroy() as $notice ){ $data[] = $notice->jsonSerialize(); } return $data; } /** * @return void */ private function flushHtml(){ if( $this->errors ){ $htmls = []; foreach( $this->errors as $error ){ $html = sprintf ( '
%s: %s
', esc_html( $error->getTitle() ), esc_html( $error->getMessage() ) ); $styles = [ 'notice', 'notice-'.$error->getType() ]; if( $this->inline ){ $styles[] = 'inline'; } if( $links = $error->getLinks() ){ $styles[] = 'has-nav'; $html .= ''; } $htmls[] = '