-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFontsamplerMessages.php
More file actions
executable file
·71 lines (56 loc) · 1.44 KB
/
FontsamplerMessages.php
File metadata and controls
executable file
·71 lines (56 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Class FontsamplerMessages
*
* Simple unified way of outputting messages of difference priority
*/
class FontsamplerMessages {
private $messages;
function __construct() {
$this->messages = array();
}
public function get_messages( $asString = false ) {
if ( $asString === true ) {
return implode( "\n", $this->messages );
}
return $this->messages;
}
public function has_messages() {
return sizeof( $this->get_messages() ) !== 0;
}
public function add_message( $string ) {
if ( ! empty( $string ) ) {
array_push( $this->messages, $string );
}
}
/*
* Shortcuts for adding messages of a certain type to the $message buffer
*/
public function add_error( $message ) {
ob_start();
$this->error( $message );
$this->add_message( ob_get_clean() );
}
public function add_info( $message ) {
ob_start();
$this->info( $message );
$this->add_message( ob_get_clean() );
}
public function add_notice( $message ) {
ob_start();
$this->notice( $message );
$this->add_message( ob_get_clean() );
}
/*
* Render different confirmation messages
*/
public static function info( $message ) {
echo '<div class="notice notice-info"><p>' . $message . '</p></div>';
}
public static function notice( $message ) {
echo '<div class="notice notice-warning"><p>' . $message . '</p></div>';
}
public static function error( $message ) {
echo '<div class="notice notice-error"><p>' . $message . '</p></div>';
}
}