WordPress.org

Ready to get started?Download WordPress

Forums

Developing Plugin: Call to undefined function add_menu_page() (2 posts)

  1. dan.imbrogno
    Member
    Posted 6 years ago #

    <?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"));
    	}
    
    ?>
  2. dan.imbrogno
    Member
    Posted 6 years ago #

    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'));
    	}
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic