示例#1
0
 /**
  * Determines if this tab has one of more form(s) that require an API.
  *
  * @return bool
  */
 function requires_api()
 {
     $requires_api = false;
     /**
      * @var string|array|Sidecar_Form $form
      */
     foreach ($this->forms as $index => $form) {
         if (!is_object($form)) {
             $form = $this->plugin->get_form($form);
         }
         if ($form->requires_api) {
             $requires_api = true;
             break;
         }
     }
     return $requires_api;
 }
示例#2
0
    /**
     *
     */
    function the_page_content()
    {
        echo <<<HTML
<div id="admin-content">
HTML;
        /**
         * @var bool|Sidecar_Admin_Tab
         */
        $current_tab = $this->has_tabs() ? $this->get_current_tab() : false;
        $this->the_tab_specific_content($current_tab, 'before_page_title', array('wrap' => false));
        if ($current_tab && $current_tab->page_title) {
            echo "<h1 class=\"admin-page-title\">";
            echo "\n" . $current_tab->page_title;
            echo "\n" . '</h1>';
        }
        $this->the_tab_specific_content($current_tab, 'before_content');
        if ($current_tab && $current_tab->tab_handler) {
            $handler = $current_tab->tab_handler;
            if (!is_callable($handler)) {
                $method = $handler;
                if (is_array($method)) {
                    $method = (is_string($handler[0]) ? "{$handler[0]}::" : get_class($handler[0]) . '->') . $handler[1];
                }
                $message = __('%s provided as %s for admin tab %s of admin page %s is not a valid callable.', 'sidecar');
                Sidecar::show_error($message, "<strong><code>{$method}()</code></strong>", "<strong><code>tab_handler</code></strong>", "<strong><em>\"{$current_tab->tab_slug}\"</em></strong>", "<strong><em>\"{$this->page_name}\"</em></strong>");
            }
        } else {
            $page_name = str_replace('-', '_', $this->page_name);
            $handler = array($this->plugin, "the_{$page_name}_admin_page");
            if ($current_tab) {
                $tab_slug = str_replace('-', '_', $current_tab->tab_slug);
                $tab_handler = array($this->plugin, "the_{$this->page_name}_{$tab_slug}_tab");
                /**
                 * Fallback to page handler if tab handler is not callable
                 */
                $handler = is_callable($tab_handler) ? $tab_handler : $handler;
            }
            if (!is_callable($handler) && $this->plugin->has_form($current_tab->tab_slug)) {
                /*
                 * If we have no handler but do have a form with same name as the tab slug, show it.
                 */
                $handler = array($this->plugin->get_form($current_tab->tab_slug), 'the_form');
            }
            if (!is_callable($handler)) {
                if (isset($tab_handler)) {
                    /**
                     * If it was a tab then report the more specific function as the one we are missing
                     */
                    $handler = $tab_handler;
                }
                $message = __('No method named %s defined yet for %s.', 'sidecar');
                Sidecar::show_error($message, "<strong><code>{$handler[1]}()</code></strong>", "<strong><code>{$this->plugin->plugin_class}</code></strong>");
            }
        }
        if (is_callable($handler)) {
            $this->_do_plugin_action('initialize_tab', $current_tab, $this);
            call_user_func($handler, $this);
        }
        $this->the_tab_specific_content($current_tab, 'after_content');
        echo '</div>';
    }