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