/** * Used this method to add tab and sidebar to the screen * * @brief Display */ public function display() { // Merging $this->tabs = array_merge($this->tabs, (array) $this->tabs()); // Add the tabs foreach ($this->tabs as $title => $callable_content) { $this->addTab($title, $callable_content); } // Add the sidebar if exists $sidebar = $this->sidebar(); if (!empty($sidebar)) { $current = $this->currentScreen->get_help_sidebar(); $this->currentScreen->set_help_sidebar($current . $sidebar); } }
/** * Applies the new sidebar contents based on loaded files. * * This should be called during WordPress's `admin_head` hook. * * @link https://developer.wordpress.org/reference/hooks/admin_head/ * * @uses Parsedown::text() * @uses WP_Screen::get_help_sidebar() * @uses WP_Screen::set_help_sidebar() * * @return @void */ public function applySidebar() { foreach ($this->_sidebar_files as $file) { if (is_readable($file)) { $this->_screen->set_help_sidebar($this->_screen->get_help_sidebar() . $this->get_parsedown()->text(file_get_contents($file))); } } }
/** * This function adds help tabs and a help sidebar to a screen. * * @since 0.5.0 * @param WP_Screen $screen the screen to add the help data to * @param array $data help tabs and sidebar (if specified) */ public static function render_help($screen, $data) { foreach ($data['tabs'] as $slug => $tab) { $args = array_merge(array('id' => $slug), $tab); $screen->add_help_tab($args); } if (!empty($data['sidebar'])) { $screen->set_help_sidebar($data['sidebar']); } }
/** * _add_help_tabs * * Note child classes define their help tabs within the page_config array. * @link http://codex.wordpress.org/Function_Reference/add_help_tab * * @access protected * @return void */ protected function _add_help_tabs() { $tour_buttons = ''; if (isset($this->_page_config[$this->_req_action])) { $config = $this->_page_config[$this->_req_action]; //is there a help tour for the current route? if there is let's setup the tour buttons if (isset($this->_help_tour[$this->_req_action])) { $tb = array(); $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; foreach ($this->_help_tour['tours'] as $tour) { //if this is the end tour then we don't need to setup a button if ($tour instanceof EE_Help_Tour_final_stop) { continue; } $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; } $tour_buttons .= implode('<br />', $tb); $tour_buttons .= '</div></div>'; } // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. if (is_array($config) && isset($config['help_sidebar'])) { //check that the callback given is valid if (!method_exists($this, $config['help_sidebar'])) { throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', 'event_espresso'), $config['help_sidebar'], get_class($this))); } $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); $content .= $tour_buttons; //add help tour buttons. //do we have any help tours setup? Cause if we do we want to add the buttons $this->_current_screen->set_help_sidebar($content); } //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. if (!isset($config['help_sidebar']) && !empty($tour_buttons)) { $this->_current_screen->set_help_sidebar($tour_buttons); } //handle if no help_tabs are set so the sidebar will still show for the help tour buttons if (!isset($config['help_tabs']) && !empty($tour_buttons)) { $_ht['id'] = $this->page_slug; $_ht['title'] = __('Help Tours', 'event_espresso'); $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; $this->_current_screen->add_help_tab($_ht); } /**/ if (!isset($config['help_tabs'])) { return; } //no help tabs for this route foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { //we're here so there ARE help tabs! //make sure we've got what we need if (!isset($cfg['title'])) { throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); } if (!isset($cfg['filename']) && !isset($cfg['callback']) && !isset($cfg['content'])) { throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', 'event_espresso')); } //first priority goes to content. if (!empty($cfg['content'])) { $content = !empty($cfg['content']) ? $cfg['content'] : NULL; //second priority goes to filename } else { if (!empty($cfg['filename'])) { $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) $file_path = !is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. if (!is_readable($file_path) && !isset($cfg['callback'])) { EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); return; } $template_args['admin_page_obj'] = $this; $content = EEH_Template::display_template($file_path, $template_args, true); } else { $content = ''; } } //check if callback is valid if (empty($content) && (!isset($cfg['callback']) || !method_exists($this, $cfg['callback']))) { EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); return; } //setup config array for help tab method $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; $_ht = array('id' => $id, 'title' => $cfg['title'], 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : NULL, 'content' => $content); $this->_current_screen->add_help_tab($_ht); } } }
/** * Load the help sidebar * @param WP_Screen $screen Screen object */ function code_snippets_load_help_sidebar($screen) { $screen->set_help_sidebar('<p><strong>' . __('For more information:', 'code-snippets') . '</strong></p>' . '<p><a href="https://wordpress.org/plugins/code-snippets">' . __('About Plugin', 'code-snippets') . '</a></p>' . '<p><a href="https://wordpress.org/plugins/code-snippets/faq">' . __('FAQ', 'code-snippets') . '</a></p>' . '<p><a href="https://wordpress.org/support/plugin/code-snippets">' . __('Support Forums', 'code-snippets') . '</a></p>' . '<p><a href="http://bungeshea.com/plugins/code-snippets/">' . __('Plugin Website</a>', 'code-snippets') . '</a></p>'); }