Closed tyaakow closed 7 years ago
Hi,
What's the class name of the main plugin that creates the admin page?
More than one possible. I tried adding possible classes names to setRootMenuPageBySlug, but it didnt work
Standard WordPress add_submenu_page works.
eg add_submenu_page('anspress', 'Anspress Polls', 'Anspress_Polls', 'manage_options', 'edit-tags.php?taxonomy=question_category');
Class AnsPress_Admin
has function which calls add_menu_page
, so I tried calling
$this->setRootMenuPageBySlug( 'AnsPress_Admin' );
, but it didnt add submenu page.
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;
No, this didnt solve it.
It even didnt add thedo_test_another_page
I cant use different functions in AnsPress for adding top-level menu, cause that is bad practice, cant upgrade it then
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.
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 .
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.
I did try it, thats why I replied now.
I didnt even change AnsPress_Admin cause that IS the class
Create two test plugins apart from your main project. You don't have to use the class name, AnsPress_Admin
, in the test plugins.
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.
I dont need to create separate project, this plugin works as is.
Then don't.
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.
And no, its not a support request.
Try this to see how it works.
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