• dan.imbrogno

    (@danimbrogno)


    <?php
    
    	//Set Up Class
    	if (!class_exists("B2BannerRotator")) {		
    
        	class B2BannerRotator {
    
            	function B2BannerRotator() { //constructor
    				}
    
    			//Admin Views
    
    		function Main() {
    				return 0;
    			}
    
           	}
       }
    
    	//Create new instance of class
       if (class_exists("B2BannerRotator")) {
              $b2_banner_rotator = new B2BannerRotator();
       }
    
    	//Actions and Filters
    	if(isset($b2_banner_rotator)){
    
    		// Administration Actions
    		add_submenu_page(__FILE__, "Banner Rotator", "Banner Rotator", 6, __FILE__, array($b2_banner_rotator, "Main"));
    	}
    
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter dan.imbrogno

    (@danimbrogno)

    Go figure, I try for 4 hours, then solve the problem 5 minutes after I post on the forum.

    The issue seems to be that you cannot call add_menu_page or any of those functions from outside the class. You need to call add_action(‘admin_menu’,array(class,function_to_setup_menu));

    Then in function_to_setup_menu, use add_menu_page().
    Here is a code sample:

    <?php
    
    	//Set Up Class
    	if (!class_exists("B2BannerRotator")) {		
    
        	class B2BannerRotator {
    
            	function B2BannerRotator() { //constructor
    
    				}
    
    		function Main() {
    				return 0;
    			}
    
    		function ConfigureMenu() {
    			add_menu_page("Test", "tesT", 6, 'b2_bannerrotator', array('B2BannerRotator','Main'));
    		}
    
           	}
       }
    
    	//Create new instance of class
       if (class_exists("B2BannerRotator")) {
              $b2_banner_rotator = new B2BannerRotator();
       }
    
    	//Actions and Filters
    	if(isset($b2_banner_rotator)){
    
    		// Administration Actions
    		add_action('admin_menu', array($b2_banner_rotator,'ConfigureMenu'));
    	}
    
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Developing Plugin: Call to undefined function add_menu_page()’ is closed to new replies.