PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.38
Code Manager v1.0.38
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / Code_Manager / Message_Box.php
code-manager / Code_Manager Last commit date
Code_Manager.php 1 year ago Code_Manager_Dashboard.php 1 year ago Code_Manager_Export.php 1 year ago Code_Manager_Form.php 1 year ago Code_Manager_Import.php 1 year ago Code_Manager_Import_File.php 1 year ago Code_Manager_List.php 1 year ago Code_Manager_List_View.php 1 year ago Code_Manager_Model.php 1 year ago Code_Manager_Preview.php 1 year ago Code_Manager_Settings.php 1 year ago Code_Manager_Tabs.php 1 year ago Message_Box.php 1 year ago WP_List_Table.php 1 year ago
Message_Box.php
141 lines
1 <?php
2 /**
3 * Code Manager message box
4 *
5 * @package Code_Manager
6 */
7
8 namespace Code_Manager {
9
10 /**
11 * Class Message_Box
12 *
13 * Displays a message box the WordPress way.
14 *
15 * @author Peter Schulz
16 * @since 1.0.0
17 */
18 class Message_Box {
19
20 /**
21 * Default message type
22 */
23 const DEFAULT_MESSAGE_TYPE = 'notice';
24
25 /**
26 * Default setting dismissible
27 */
28 const DEFAULT_MESSAGE_IS_DISMISSIBLE = true;
29
30 /**
31 * Sequence number
32 *
33 * Used to give message boxes a unique number within the current response
34 *
35 * @var int
36 */
37 protected static $message_box_seq = 0;
38
39 /**
40 * Message box number
41 *
42 * @var int
43 */
44 protected $message_box_no;
45
46 /**
47 * Message box text
48 *
49 * @var string
50 */
51 protected $message_text;
52
53 /**
54 * Message type (error, notice, action)
55 *
56 * @var string
57 */
58 protected $message_type;
59
60 /**
61 * Indicates whether message is dismissible
62 *
63 * @var string
64 */
65 protected $message_is_dismissible;
66
67 /**
68 * Message type shown to user
69 *
70 * @var string
71 */
72 protected $message_hint;
73
74 /**
75 * Message_Box constructor
76 *
77 * @param array $args [
78 *
79 * 'message_text' => (string) Message text
80 *
81 * 'message_type' => (string) Message type
82 *
83 * 'message_is_dismissible' => (boolean) Indicates whether message box is dismissible
84 *
85 * ].
86 * @since 1.0.0
87 */
88 public function __construct( $args = array() ) {
89 $args = wp_parse_args(
90 $args,
91 array(
92 'message_text' => '',
93 'message_type' => self::DEFAULT_MESSAGE_TYPE,
94 'message_is_dismissible' => self::DEFAULT_MESSAGE_IS_DISMISSIBLE,
95 )
96 );
97
98 if ( '' === $args['message_text'] ) {
99 wp_die( __( 'ERROR: Wrong arguments [missing message text argument]', 'code-manager' ) );
100 }
101
102 $this->message_text = $args['message_text'];
103 $this->message_type = $args['message_type'];
104 $this->message_is_dismissible = true === $args['message_is_dismissible'] ? 'is-dismissible' : '';
105 switch ( $this->message_type ) {
106 case 'error':
107 $this->message_hint = 'ERROR';
108 break;
109 case 'action':
110 $this->message_hint = 'ACTION';
111 $this->message_type = 'notice';
112 break;
113 default:
114 $this->message_hint = 'INFO';
115 }
116
117 $this->message_box_no = ++ self::$message_box_seq; // Give message box a unique number.
118 }
119
120 /**
121 * Show message box
122 *
123 * @since 1.0.0
124 */
125 public function box() {
126 $msgbox_id = 'message_box_' . esc_attr( $this->message_box_no );
127 global $allowedposttags;
128 ?>
129 <div id='<?php echo esc_attr( $msgbox_id ); ?>'
130 class='updated published <?php echo esc_attr( $this->message_type ); ?> <?php echo esc_attr( $this->message_is_dismissible ); ?>'>
131 <p>
132 <?php echo esc_attr( $this->message_hint ); ?>: <?php echo wp_kses( $this->message_text, $allowedposttags ); ?>
133 </p>
134 </div>
135 <?php
136 }
137
138 }
139
140 }
141