michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
339 stars 71 forks source link

Two SubMenuItems, but only one works #177

Closed baskettcase closed 9 years ago

baskettcase commented 9 years ago

I'm really struggling with this framework for some reason. I'm sure I'm missing something simple. For example, I have two pages and the second page will not show the form fields, yet the first page will. If I remove the first submenu then the second one works. I add it back and it doesn't work anymore. I've tried making it two different classes outside of the core, but still, nothing on the second submenu page, although the submit button shows up. Is it even possible to do two different pages of options and each page saves it's own option variable?

Ill do a quick bit of code for a fun test:

if ( !class_exists( 'AIC_AdminPageFramework' ) ) {
    include_once( AIC_PATH . 'library/admin-page-framework.min.php' );
}
class AIC_APF extends AIC_AdminPageFramework {

    public function setUp() {
        $this->setRootMenuPage(
            'Ice Cream',
            plugin_dir_url( __FILE__ ) . 'images/icecream-icon-1.png',
            24
        );
        $this->addSubMenuItems(
            array(
                'title' => 'Flavors',
                'page_slug' => 'aic_flavors',
                'capability' => 'manage_options',
                'page_title' => 'Ice Cream Flavors'
            ),
            array(
                'title' => 'Locations',
                'page_slug' => 'aic_locations',
                'capability' => 'manage_options',
                'page_title' => 'Ice Cream Locations'
            )
        );
        $_sClassName = get_class( $this );
        include( AIC_PATH .'admin/partials/locations.php' );
        new AIC_APF_Locations;
        include( AIC_PATH .'admin/partials/flavors.php' );
        new AIC_APF_Flavors;
    }

    public function load_AIC_APF( $oAdminPage ) {
        $this->setPageHeadingTabsVisibility( false );
    }

}
new AIC_APF($_GET['page'], __FILE__, 'manage_options', 'icecream');

So that's the core part, it saves the options in the database as the slug which that works fine. The flavors.php shows up just fine, yet the locations does not. If I remove the addSubMenuItems for flavors then the locations does show up. Im missing something and I can't figure out what.

baskettcase commented 9 years ago

The problem seems to be in the load_aic_locations(). The $oAdminPage->addSettingSections() and $oAdminPage->addSettingFields() are not actually displaying anything for the aic_locations slug page. It does for the aic_flavors page though. And like I said if I remove the aic_flavors page from the menu, then the locations page works. Some kind of conflict it seems, but I can't figure out why.

michaeluno commented 9 years ago

I cannot tell what's wrong unless I see the other files, locations.php and flavors.php. Can you post them? (If they are long, make them short enough to see the problem)

baskettcase commented 9 years ago

I emailed you on your website since Im not sure it's ok to post all the code here. Hopefull you're able to get it. I wasn't sure how to send you a private message here on github.

michaeluno commented 9 years ago

Try not omitting the target page slug in the addSettingSections() method.

        $oAdminPage->addSettingSections(
            'aic_locations', // <-- this one, the target page slug
            array(
                'section_id' => '...',
                'title' => '...',
            ),
baskettcase commented 9 years ago

Ugh, sure enough that was it. Now everything is working. Thank you!

michaeluno commented 9 years ago

Glad it helped and thanks for the donation!