UIX Documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • None
  • uix
    • data
    • ui
      • control

Classes

  • uix\data\data
  • uix\ui
  • uix\ui\box
  • uix\ui\control
  • uix\ui\control\autocomplete
  • uix\ui\control\button
  • uix\ui\control\checkbox
  • uix\ui\control\color
  • uix\ui\control\editor
  • uix\ui\control\email
  • uix\ui\control\file
  • uix\ui\control\hidden
  • uix\ui\control\number
  • uix\ui\control\post_relation
  • uix\ui\control\radio
  • uix\ui\control\select
  • uix\ui\control\separator
  • uix\ui\control\slider
  • uix\ui\control\template
  • uix\ui\control\text
  • uix\ui\control\textarea
  • uix\ui\control\toggle
  • uix\ui\footer
  • uix\ui\grid
  • uix\ui\header
  • uix\ui\help
  • uix\ui\metabox
  • uix\ui\modal
  • uix\ui\notice
  • uix\ui\page
  • uix\ui\panel
  • uix\ui\post_type
  • uix\ui\repeat
  • uix\ui\section
  • uix\ui\uix

Interfaces

  • uix\data\load
  • uix\data\save

Functions

  • uix
  • uix_autoload_class
  1 <?php
  2 /**
  3  * UIX Notice
  4  *
  5  * @package   ui
  6  * @author    David Cramer
  7  * @license   GPL-2.0+
  8  * @link
  9  * @copyright 2016 David Cramer
 10  */
 11 namespace uix\ui;
 12 
 13 /**
 14  * UIX Notice. Handles displaying of admin notices.
 15  * 
 16  * @package uix\ui
 17  * @author  David Cramer
 18  */
 19 class notice extends \uix\data\data{
 20 
 21     /**
 22      * The type of object
 23      *
 24      * @since 1.0.0
 25      * @access public
 26      * @var string
 27      */
 28     public $type = 'notice';
 29 
 30     /**
 31      * The wrapper elements class names
 32      *
 33      * @since 1.0.0
 34      * @access public
 35      * @var array
 36      */
 37     public $classes = array( 'uix-notice', 'notice' );
 38 
 39     /**
 40      * The wrapper elements main attributes
 41      *
 42      * @since 1.0.0
 43      * @access public
 44      * @var array
 45      */
 46     public $attributes;
 47 
 48     /**
 49      * The state type of the notice ( warning, error, success )
 50      *
 51      * @since 1.0.0
 52      * @access public
 53      * @var string
 54      */
 55     public $state = 'notice';
 56 
 57 
 58     /**
 59      * setup notice
 60      *
 61      * @since 1.0.0
 62      * @access public
 63      */
 64     public function setup(){
 65         
 66         if( isset( $this->struct['description'] ) )
 67             $this->set_data( $this->struct['description'] );
 68 
 69         $this->set_attributes();
 70         $this->set_dismissable();
 71         $this->set_state();        
 72 
 73     }
 74 
 75     /**
 76      * Set hooks on when to load the notices
 77      *
 78      * @since 1.0.0
 79      * @access protected
 80      */
 81     protected function actions() {
 82         parent::actions();
 83         // init uix after loaded        
 84         add_action( 'admin_notices', array( $this, 'render' ) );
 85     }
 86 
 87     /**
 88      * Render the panel
 89      *
 90      * @since 1.0.0
 91      * @access public
 92      * @return string HTML of notice
 93      */
 94     public function render(){
 95         $output = null;
 96 
 97         $this->attributes['class'] = implode( ' ', $this->classes );
 98         $note = $this->get_data();
 99         $output .= '<div ' . $this->build_attributes() . '>';
100         $output .= '<p>';
101         $output .= $note[ $this->slug ];
102         $output .= '</p>';
103         $output .= $this->dismiss();
104         $output .= '</div>';
105 
106         return $output;
107 
108     }
109 
110     /**
111      * Render a dismiss button
112      *
113      * @since 1.0.0
114      * @access public
115      * @return string|null HTML of dismiss button
116      */
117     public function dismiss(){
118         $output = null;
119         if( !empty( $this->struct['dismissable'] ) )
120             $output .= '<button class="notice-dismiss" type="button"><span class="screen-reader-text">' . esc_attr__( 'Dismiss this notice.' ) . '</span></button>';
121 
122         return $output;
123     }
124 
125     /**
126      * Sets the wrappers class names
127      *
128      * @since 1.0.0
129      * @access public
130      */
131     public function set_dismissable(){
132         if( !empty( $this->struct['dismissable'] ) )
133             $this->classes[] = 'is-dismissible';
134     }
135 
136     /**
137      * Sets the wrappers class names
138      *
139      * @since 1.0.0
140      * @access public
141      */
142     public function set_state(){
143         if( !empty( $this->struct['state'] ) ){
144             $this->classes[] = 'notice-' . $this->struct['state'];
145         }else{
146             $this->classes[] = 'notice-warning';
147         }
148     }
149 
150 }
UIX Documentation API documentation generated by ApiGen