michaeluno / admin-page-framework

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

[x] Namespace bug #270

Closed dualjack closed 6 years ago

dualjack commented 7 years ago

I have found a bug, when creating root menu page while using namespacing. When namespace occurs, some things are broken.

The simplest code to reproduce it:

<?php
namespace tmc\newsletter\src\Controllers;

class apf_mainPluginPages extends \ns_tmcAdminPageFramework {

    function setUp() {

        $this->setRootMenuPage( 'I am broken' );

        $this->addSubMenuItems(
            array(
                'title'         =>  __( 'Emails', 'ns_tmc' ),
                'page_slug'     =>  'ns_tm_emails'
            )

        );

    }

}

new apf_mainPluginPages( 'ns_tmc_options', $this->mainPluginFile, 'manage_options', 'ns_tmc'  );

screenshot_1

As you can see, it creates root menu but also sub menu with broken link. The broken link follows namespace structure.

When namespaceing is gone, everything works fine.

<?php
class apf_mainPluginPages extends ns_tmcAdminPageFramework {

    function setUp() {

        $this->setRootMenuPage( 'I am broken' );

        $this->addSubMenuItems(
            array(
                'title'         =>  __( 'Emails', 'ns_tmc' ),
                'page_slug'     =>  'ns_tm_emails'
            )

        );

    }

}

new apf_mainPluginPages( 'ns_tmc_options', $this->mainPluginFile, 'manage_options', 'ns_tmc'  );

screenshot_2

I am not sure for now, but maybe transforming className, used in scripts, to some safe string without backslashes will fix it.

I think this problem occurs, because wordpress method add_menu_page() returns slug with "/" not "\".

dualjack commented 7 years ago

Don't mind $this->mainPluginFile I just moved it from upper file for simplicity.

michaeluno commented 7 years ago

I could confirm this problem. Thanks for the report.