add_menu_page not available from Class
-
Hello everyone!
I created a Help-Class for Administration Menus, where I wanted to encapsulate all nessecary names and functionality required by wordpress to add one.
The class structure looks like this:
fileAdminMenu.php
abstract Class AdminMenu { // ... various variables // __construct() {} // ... various final methods abstract function register_with_wp(); } Class ToplevelAdminMenu extends AdminMenu { // __construct() {} function register_with_wp() { add_menu_page (....); } }
file
Pluginname.php
require_once(DIRECTORY.'AdminMenu.php'); // doesnot create fatal errors class Pluginname { __construct () { $this->adminmenu = new ToplevelAdminMenu(); // works fine $this->adminmenu->register_with_wp(); // breaks because of undefined function within this function called 'add_menu_page' add_menu_page(...); // PHP knows function } }
In my Sub-Class I’ve got a problem: it says, I cannot access an undefined function. But: I create these objects within a plugin-file, so it has to be defined – or nor?
Where can I access these functions like
add_menu_page
, cause, as it is described in the PHP-Docs, required files should have the same variables-visibility as the line where it was required.I’m still working on this but am thankful for any help provided.
If it’s an PHP-specific problem, I am sorry for posting it in this forum, but I think that the wordpress communitiy is much more aware of the structure of wordpress than any other PHP-programmer.
- The topic ‘add_menu_page not available from Class’ is closed to new replies.