• Resolved unrelatedmedia

    (@unrelatedmedia)


    I’m trying to write a simple class to add menus to the administration page within the current menus there. The problem I am facing is that the class allows for me to place a link once in every section and any html will work fine. But when I try to add two links to a single section the page html shows both.

    Using the alternate method add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ) the links appear but the pages tell me I don’t have permmission to view, even as super admin.

    The class I need advice on:

    <?php
    /*############################################
    * CLASS ADMIN OPTIONS
    *#############################################
    * Admin Options simply builds a new menu item
    * under the Appearance drop down in wordpress.
    *
    * Parameters: $Link_Location => the menu the new link is to be placed in
    ###########################################################################################
    ###  $Link_Location OPTIONS
    ###	   Appearance, Posts, Media, Links, Pages, Comments, Plugins, Users, Tools, Settings
    ###########################################################################################
    *             $Display_Function => html to show when the link is clicked in the WordPress
    *
    *
    *
    * Returns: Nothing
    *
    * @copyright 2011 Unrelated Media
    * @license http://www.zend.com/license/3_0.txt PHP License 3.0
    * @version Release: 1.2
    * @link http://unrelatedmedia.ca
    * @since Class available since Release 1.0
    */ 
    
    class Admin_Options
    {
      public $Display_Html_Output;
      public $Place_In_Menu;
      public $L_Name;
    
      function Admin_Options($Link_Location,$Link_Name,$Display_Function)
      {
    	$this->Place_In_Menu = strtolower($Link_Location);
    	$this->Display_Html_Output = $Display_Function;
    	$this->L_Name = $Link_Name;
    
    	add_action('admin_menu', array(&$this, 'Add_New_Theme_Menu'),3);
    
      }
      function Add_New_Theme_Menu()
      {
    
    	switch ($this->Place_In_Menu){
    		case "appearance":
    			add_theme_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "posts":
    			add_posts_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "media":
    			add_media_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "links":
    			add_links_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "pages":
    			add_pages_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "comments":
    			add_comments_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "plugins":
    			add_plugins_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "users":
    			add_users_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "tools":
    			add_management_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		case "settings":
    			add_options_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    		default: //Dashboard
    			add_dashboard_page( $this->L_Name,$this->L_Name , 'administrator', basename(__file__),array(&$this,'Display_Html'));
    			break;
    	}		
    
      }
      function Display_Html()
    	{
    	  echo $this->Display_Html_Output;
    	}  
    
    }
    /*
    * Example Usage
    ###############################################
    //Instantiate the class; */
     $t = &new Admin_Options("","Link 1", '<h2>Hello World</h2>');
     $r = &new Admin_Options("Settings","Link 2",'<h2>Hello World</h2>');
     $s = &new Admin_Options("Settings","Link 3",'<h2>Hello World</h2>');
    ###############################################
    
    ?>

  • The topic ‘Add Menu Class’ is closed to new replies.