1 <?php
2 /**
3 * UIX Help
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 Help. Handles displaying of contextual help items in admin
15 *
16 * @package uix\ui
17 * @author David Cramer
18 */
19 class help extends uix{
20
21 /**
22 * The type of object
23 *
24 * @since 1.0.0
25 * @access public
26 * @var string
27 */
28 public $type = 'help';
29
30 /**
31 * The current screen
32 *
33 * @since 1.0.0
34 * @access private
35 * @var screen
36 */
37 private $screen;
38
39
40 /**
41 * Set hooks on when to load the notices
42 *
43 * @since 1.0.0
44 * @access protected
45 */
46 protected function actions() {
47 parent::actions();
48 // init uix after loaded
49 // queue helps
50 add_action( 'admin_head', array( $this, 'render' ) );
51 }
52
53
54 /**
55 * Add defined contextual help to current screen
56 *
57 * @since 1.0.0
58 * @access public
59 */
60 public function render(){
61
62 $this->screen = get_current_screen();
63
64 if( ! $this->is_active() ){ return; }
65
66 $this->screen->add_help_tab( array(
67 'id' => $this->slug,
68 'title' => $this->struct['title'],
69 'content' => $this->struct['content']
70 ));
71
72 }
73
74 /**
75 * Determin if a help is on this page
76 * @since 1.0.0
77 * @access public
78 */
79 public function is_active(){
80
81 if( !empty( $this->struct['screen'] ) && !in_array( $this->screen->id, (array) $this->struct['screen'] ) )
82 return false;
83
84 return parent::is_active();
85 }
86 }