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 Pages
  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 Page class for creating admin/settings pages.
 15  * @package uix\ui
 16  * @author  David Cramer
 17  */
 18 class page extends box implements \uix\data\save{
 19 
 20     /**
 21      * The type of object
 22      *
 23      * @since 1.0.0
 24      * @access public
 25      * @var      string
 26      */
 27     public $type = 'page';
 28 
 29     /**
 30      * Holds the option screen prefix
 31      *
 32      * @since 1.0.0
 33      * @access public
 34      * @var      array
 35      */
 36     public $screen_hook_suffix = array();
 37 
 38 
 39     /**
 40      * setup actions and hooks to add settings pate and save settings
 41      *
 42      * @since 1.0.0
 43      * @access protected
 44      */
 45     protected function actions() {
 46         // run parent actions ( keep 'admin_head' hook )
 47         parent::actions();
 48 
 49         if( empty( $this->struct[ 'page_title' ] ) || empty( $this->struct['menu_title'] ) )
 50             return;
 51 
 52 
 53         $this->setup_pages();
 54 
 55     }
 56 
 57     /**
 58      * Adds settings page to adminh
 59      *
 60      * @since 1.0.0
 61      * @access private
 62      */
 63     private function setup_pages(){
 64 
 65         $args = array(
 66             'capability'    => 'manage_options',
 67             'icon'          =>  null,
 68             'position'      => null
 69         );
 70         $this->struct['args'] = array_merge( $args, $this->struct );
 71 
 72         if( !isset( $this->struct['parent'] ) ) {
 73             add_action('admin_menu', array($this, 'add_settings_page'), 9);
 74         }else{
 75             add_action('admin_menu', array($this, 'add_sub_page'), 9);
 76         }
 77 
 78     }
 79 
 80 
 81     /**
 82      * Define core page styles
 83      *
 84      * @since 1.0.0
 85      * @access public
 86      */
 87     public function set_assets() {
 88 
 89         $this->assets['style']['page'] =  $this->url . 'assets/css/page' . UIX_ASSET_DEBUG . '.css';
 90 
 91         parent::set_assets();
 92     }
 93 
 94     /**
 95      * Sets the wrappers attributes
 96      *
 97      * @since 1.0.0
 98      * @access public
 99      */
100     public function set_attributes(){
101 
102         parent::set_attributes();
103 
104         $this->attributes['class'] = 'wrap uix-ajax uix-page';
105 
106         if( empty( $this->struct['full_width'] ) )
107             $this->attributes['class'] .= ' uix-half-page';
108 
109         if( !empty( $this->struct['attributes'] ) )
110             $this->attributes = array_merge( $this->attributes, $this->struct['attributes'] );
111 
112 
113 
114     }
115 
116 
117     /**
118      * get a UIX config store key
119      * @since 1.0.0
120      * @access public
121      * @return string $store_key the defiuned option name for this UIX object
122      */
123     public function store_key(){
124 
125         if( !empty( $this->struct['store_key'] ) ){
126             $store_key = $this->struct['store_key'];
127         }else{
128             $store_key = 'uix-' . $this->type . '-' . sanitize_text_field( $this->slug );
129         }
130 
131         return $store_key;
132     }
133 
134     /**
135      * Determin if a page is to be loaded and set it active
136      * @since 1.0.0
137      * @access public
138      */
139     public function is_active(){
140         if( !is_admin() ){ return false; }
141 
142         // check that the screen object is valid to be safe.
143         $screen = get_current_screen();
144         return $screen->base === $this->screen_hook_suffix;
145 
146     }
147 
148     /**
149      * Enqueues specific tabs assets for the active pages
150      *
151      * @since 1.0.0
152      * @access protected
153      */
154     protected function enqueue_active_assets(){
155 
156         parent::enqueue_active_assets();
157 
158         echo '<style type="text/css">';
159 
160         echo '.uix-page #panel-' . $this->id() . ' > .uix-panel-tabs > li[aria-selected="true"] a {box-shadow: 0 -3px 0 ' . $this->base_color() . ' inset;}';
161         echo '.uix-page #panel-' . $this->id() . '.uix-top-tabs > .uix-panel-tabs > li[aria-selected="true"] a {box-shadow: 0 3px 0 ' . $this->base_color() . ' inset;}';
162 
163         echo '.contextual-help-tabs .active {border-left: 6px solid ' . $this->base_color(). ' !important;}';
164         echo '#' . $this->id() . '.uix-page h1{box-shadow: 0 0 2px rgba(0, 2, 0, 0.1),11px 0 0 ' . $this->base_color() . ' inset;}';
165         echo '#' . $this->id() . '.uix-page .page-title-action:hover{background: ' . $this->base_color() . ';border-color: rgba(0,0,0,0.1);}';
166         echo '#' . $this->id() . '.uix-page .page-title-action:focus{box-shadow: 0 0 2px ' . $this->base_color() . ';border-color: ' . $this->base_color() . ';}';
167 
168         if( $this->child_count() > 1 )
169             echo '#' . $this->id() . '.uix-page h1{ box-shadow: 0 0px 13px 12px ' . $this->base_color() . ', 11px 0 0 ' . $this->base_color() . ' inset;}';
170 
171         echo '</style>';
172 
173     }
174 
175     /**
176      * Add the settings page
177      *
178      * @since 1.0.0
179      * @access public
180      * @uses "admin_menu" hook
181      */
182     public function add_settings_page(){
183 
184         $this->screen_hook_suffix = add_menu_page(
185             $this->struct['args'][ 'page_title' ],
186             $this->struct['args'][ 'menu_title' ],
187             $this->struct['args'][ 'capability' ],
188             $this->slug,
189             array( $this, 'create_page' ),
190             $this->struct['args'][ 'icon' ],
191             $this->struct['args'][ 'position' ]
192         );
193 
194     }
195 
196     /**
197      * Add the sub settings page
198      *
199      * @since 1.0.0
200      * @access public
201      * @uses "admin_menu" hook
202      */
203     public function add_sub_page(){
204 
205         $this->screen_hook_suffix = add_submenu_page(
206             $this->struct['args'][ 'parent' ],
207             $this->struct['args'][ 'page_title' ],
208             $this->struct['args'][ 'menu_title' ],
209             $this->struct['args'][ 'capability' ],
210             $this->slug,
211             array( $this, 'create_page' )
212         );
213 
214     }
215 
216     /**
217      * create the admin page
218      *
219      * @since 1.0.0
220      * @access public
221      */
222     public function create_page(){
223         echo $this->render();
224     }
225 
226 
227 
228 }
UIX Documentation API documentation generated by ApiGen