WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-screen-help.php
Go to the documentation of this file.
1 <?php
2 
18 
27 
35  private $tabs = array();
36 
44  public function __construct()
45  {
46  $this->currentScreen = get_current_screen();
47  }
48 
59  public function tabs( $tabs = array() )
60  {
61  die( __METHOD__ . ' must be override in your subclass' );
62  }
63 
69  public function display()
70  {
71  // Merging
72  $this->tabs = array_merge( $this->tabs, (array)$this->tabs() );
73 
74  // Add the tabs
75  foreach ( $this->tabs as $title => $callable_content ) {
76  $this->addTab( $title, $callable_content );
77  }
78 
79  // Add the sidebar if exists
80  $sidebar = $this->sidebar();
81  if ( !empty( $sidebar ) ) {
82  $this->currentScreen->set_help_sidebar( $sidebar );
83  }
84  }
85 
94  public function addTab( $title, $callable_content )
95  {
96  // If $callable_content is empty exit
97  if ( empty( $callable_content ) ) {
98  return;
99  }
100 
101  // Store in global
102  $this->tabs[$title] = $callable_content;
103 
104  $help_tab = array(
105  'id' => sanitize_key( $title ),
106  'title' => $title,
107  );
108 
109  if ( is_string( $callable_content ) && !is_callable( $callable_content ) ) {
110  $help_tab['content'] = $callable_content;
111  }
112 
113  if ( is_callable( $callable_content ) ) {
114  $help_tab['callback'] = $callable_content;
115  }
116 
117  $this->currentScreen->add_help_tab( $help_tab );
118  }
119 
127  public function sidebar()
128  {
129  // You can override if you will support a sidebar content
130  return '';
131  }
132 
133 }