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 | } |