michaeluno/admin-page-framework

[x] Namespace bug

Closed this issue · 2 comments

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 "\".

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

I could confirm this problem. Thanks for the report.