0

I have two extensions : Core where there all the common files and Wooster extension in Wordpress. In Wooster extension I have WoosterPartnerSetup.php and in the Core WoosterSetup.php. I am trying to to remove the onglet if there is only one but I want the onglet to appear if there are more than 2.

partner\includes\WoosterPartnerSetup.php :

    <?php
/**
 * Add setup content to page
 */
class WoosterPartnerSetup
{
    /**
     * Hook to display the contents of the Setup menu
     */
    public function __construct()
    {
        add_action('init_onglet', array($this, 'wooster_partner_setup_content'));
        add_action('tab_onglet_content', array($this, 'wooster_setup_content'));
    }

    /**
     * Add setup content to page
     * @return void
     */
    public function wooster_partner_setup_content()
    {
        $wooster_tabs = new WoosterSetup();
        $wooster_tabs->add_wooster_tab('Compagnon', __('Contenu du compagnon', 'wooster-partner'));


    }

    /**
     * Allows you to display the form to choose the style sheet to display
     *
     * @return void
     */
    function wooster_setup_content()
    {
    ?>
        <!-- Content of the compagnon tab -->
        <div class="tab-content compagnon-content">
            <?php
                do_action('tab_content_setupCompagnon');
            ?>
        </div>
    <?php
    }

}
new WoosterPartnerSetup();

wooster-core\includes\WoosterSetup.php :

<?php
// The class cannot be redeclared otherwise it will generate an error
// Class will be in all woobster plugin
if (!class_exists('WoosterSetup')) {
    /**
     * Allows you to display all the extension setup wizards
     */
    class WoosterSetup
    {
        /**
         * Hook to add setup menu to Wooster menu
         */
        public function __construct()
        {
            add_action('wooster_menu', array($this, 'wooster_setup_menu'));

            // Hide the configuration menu if there is no more configuration to do
            if ($this->wooster_configs_steps()) {
                add_action('admin_head', array($this, 'remove_admin_menu'));
            }
        }


        /**
         * Add setup menu to Wooster menu
         * @return void
         */
        public function wooster_setup_menu()
        {
            add_submenu_page(
                'wooster',
                'Assistant d’installation',
                'Installation',
                'manage_options',
                'wooster-setup',
                array($this, 'wooster_setup_partner'),
                1
            );
        }
        public function wooster_setup_partner()
        {
            ?>
            <div class="wrap">
            <!-- Print the page title -->
            <h1><?= __('Assistant d\'installation', 'wooster-core') ?></h1>
            <nav class="nav-tab-wrapper">
                <?php
                    do_action('init_onglet');

                ?>
            </nav>

            <div class="tab-content container">
                <?php
                    do_action('tab_onglet_content');
                ?>
            </div>
        </div>
    <?php
        }


        public function add_wooster_tab($tab_name, $tab_content) {
            $tabs = get_option('wooster_tabs', array());
            $tabs[$tab_name] = $tab_content;
            update_option('wooster_tabs', $tabs);
        }

        public function display_wooster_tabs() {
            $tabs = get_option('wooster_tabs', array());
            $num_tabs = count($tabs);

            if ($num_tabs > 1) { // Vérifie s'il y a plus d'un onglet
                echo '<nav class="nav-tab-wrapper">';
                foreach ($tabs as $tab_name => $tab_content) {
                    echo '<a class="nav-tab">' . esc_html($tab_name) . '</a>';
                }
                echo '</nav>';

                echo '<div class="tab-content container">';
                foreach ($tabs as $tab_name => $tab_content) {
                    echo '<div class="tab-pane">' . esc_html($tab_content) . '</div>';
                }
                echo '</div>';
            }
        }


        /**
         * Remove the admin menu
         * @return void
         */
        function remove_admin_menu()
        {
            remove_submenu_page('wooster', 'wooster-setup');
        }

        /**
         * Check if there are any configurations left to do
         * @return boolean
         */
        function wooster_configs_steps()
        {
            // Get the steps from the database
            $steps = maybe_unserialize(get_option('wooster_configs_compagnon', array()));

            // Check if the steps are completed or not
            if (isset($steps['step1']) && ($steps['step1'] )
            && isset($steps['step2']) && ($steps['step2'])
            && isset($steps['step3']) && $steps['step3'])
            {
                return true;
            }
                return false;
        }
    }
    new WoosterSetup();
}

I am trying to understand how onglet are made and the system of hook. I tried to put all the onglet in the option of wordpress and then retrieve it so I can use it for each page of my plugin. Maybe , a simple solution is possible.

0

Browse other questions tagged or ask your own question.