Code_Manager.php
7 months ago
Code_Manager_Dashboard.php
7 months ago
Code_Manager_Export.php
7 months ago
Code_Manager_Form.php
7 months ago
Code_Manager_Import.php
7 months ago
Code_Manager_Import_File.php
7 months ago
Code_Manager_List.php
7 months ago
Code_Manager_List_View.php
7 months ago
Code_Manager_Model.php
7 months ago
Code_Manager_Preview.php
7 months ago
Code_Manager_Settings.php
7 months ago
Code_Manager_Tabs.php
7 months ago
Message_Box.php
7 months ago
WP_List_Table.php
7 months 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 |