michaeluno / admin-page-framework

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

Sub-menu pages to pages created by another plugin #260

Closed tyaakow closed 7 years ago

tyaakow commented 7 years ago

I want to add a submenu page to a page which was created by another plugin (anspress in this case).

I tried this, I thought it should work - slugs/names are correct - $this->setRootMenuPage( 'anspress' ); $this->setRootMenuPage( 'AnsPress' ); $this->setRootMenuPageBySlug( 'admin.php?page=anspress' );

But it didnt work

michaeluno commented 7 years ago

Hi,

What's the class name of the main plugin that creates the admin page?

tyaakow commented 7 years ago

More than one possible. I tried adding possible classes names to setRootMenuPageBySlug, but it didnt work

tyaakow commented 7 years ago

Standard WordPress add_submenu_page works. eg add_submenu_page('anspress', 'Anspress Polls', 'Anspress_Polls', 'manage_options', 'edit-tags.php?taxonomy=question_category');

tyaakow commented 7 years ago

Class AnsPress_Admin has function which calls add_menu_page, so I tried calling $this->setRootMenuPageBySlug( 'AnsPress_Admin' );, but it didnt add submenu page.

michaeluno commented 7 years ago

Class AnsPress_Admin has function which calls add_menu_page.

Use the setRootMenuPage() method to add a top-level menu instead of add_menu_page(). Otherwise, you won't be able to add sub-menu items by calling $this->setRootMenuPageBySlug( 'AnsPress_Admin' );.

Also, make sure the class that calls $this->setRootMenuPageBySlug( 'AnsPress_Admin' ); gets instantiated after the AnsPress_Admin class gets instantiated.

Another way to add a submenu page from a separate script is to use the set_up_{class name} hook.

class APFTest_AddAnotherSubMenuPage {

    public function __construct() {

        // set_up_{class name}
        add_action( 'set_up_AnsPress_Admin', array( $this, 'setUp' ) );

        add_action( 'do_test_another_page', array( $this, 'doPage' ) );

    }

    public function setUp( $oFactory ) {
        $oFactory->addSubMenuItems(
            array(
                'title'         => __( 'Another Page', 'admin-page-framework-test' ),
                'page_slug'     => 'test_another_page',
            )               
        );
    }

    public function doPage( $oFactory ) {
        echo "<h3>Test</h3>"
            . "<p>This is a test.</p>";
    }

}
new APFTest_AddAnotherSubMenuPage;
tyaakow commented 7 years ago

No, this didnt solve it.

It even didnt add thedo_test_another_page

tyaakow commented 7 years ago

I cant use different functions in AnsPress for adding top-level menu, cause that is bad practice, cant upgrade it then

michaeluno commented 7 years ago

I suggest you create two very simple test plugins to know how it works.

Create one with this tutorial. And create the other plugin with the code posted in my previous reply. Don't forget to change the class name, AnsPress_Admin used in the above code.

tyaakow commented 7 years ago

I know how it works.

I just dont know how it works with submenu to menu items created by other plugins. Otherwise it works.

Other things work, but this feature doesnt seem to (or it isnt documented how to)

Tonino Jankov

studio.croati.co http://studio.croati.co GSM: +385 91 7979138

On Mon, Sep 5, 2016 at 12:37 PM, Michael Uno notifications@github.com wrote:

I suggest you create two very simple test plugins to know how it works.

Create one with this tutorial http://admin-page-framework.michaeluno.jp/tutorials/03-create-a-page-group/. And create the other plugin with the code posted in my previous reply. Don't forget to change the class name, AnsPress_Admin used in the above code.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/michaeluno/admin-page-framework/issues/260#issuecomment-244716037, or mute the thread https://github.com/notifications/unsubscribe-auth/ABF7E8-T9LjXVOrwAheDh0Q_Tsh84eGLks5qm_EDgaJpZM4J0IeC .

michaeluno commented 7 years ago

I just dont know how it works with submenu to menu items created by other plugins.

Try what I suggested in the previous reply. It is just about using the filter hooks.

tyaakow commented 7 years ago

I did try it, thats why I replied now.

tyaakow commented 7 years ago

I didnt even change AnsPress_Admin cause that IS the class

michaeluno commented 7 years ago

Create two test plugins apart from your main project. You don't have to use the class name, AnsPress_Admin, in the test plugins.

tyaakow commented 7 years ago

With what class should I use set_up_ then? I dont need to create separate project, this plugin works as is. But if I want to use it in a submenu of another plugin - I still have to have that plugin.

michaeluno commented 7 years ago

I dont need to create separate project, this plugin works as is.

Then don't.

tyaakow commented 7 years ago

It doesnt work with another plugin.

On its own it works.

But it wont add submenu to menu item created by another plugin.

You could just say so, so I dont waste my time.

tyaakow commented 7 years ago

And no, its not a support request.

michaeluno commented 7 years ago

Try this to see how it works.