The MU forums have moved to WordPress.org

Solved: Generate add_submenu_page array (3 posts)

  1. Lovedoodle
    Member
    Posted 14 years ago #

    I'm in the process of creating a plugin for 3 blogs running on a single install of WPMU, but the plugin's submenus need to be different for each one.

    Each site has it's own unique table (wp_1_ksettings, wp_2_kpsettings, wp_3_kpsettings) with columns that contain the strings needed for the options, identifier, and etc used in this line:

    add_submenu_page(__FILE__, $row['option_name'], $row['option_name'], $row['capability'], $row['identifier'], $row['identifier']);

    I'm wondering if it's possible to use mysql_fetch_array to generate these submenu pages based on that data in the database using this code.

    //Add a menu to the top level
    add_action('admin_menu', 'Add_kp_plugin');
    
    //Add a main menu for the plugin
    function Add_kp_plugin() {
       if (function_exists('add_menu_page')){
    		add_menu_page('KP Settings', 'KP Settings', 2, __FILE__, 'startup');
    		global $wpdb;
    		$result = mysql_query("SELECT * FROM wp_" $wpdb->$siteid . "_kpsettings");
    		while($row = mysql_fetch_array($result))
    		{
    			add_submenu_page(__FILE__, $row['option_name'], $row['option_name'], $row['capability'], $row['identifier'], $row['identifier']);
    		}
    	}
    }

    I'm sure there's another way to do this but I just can't think of it. If anyone out there has any ideas or other suggestions it would be greatly appreciated.

  2. Lovedoodle
    Member
    Posted 14 years ago #

    Actually... nevermind. To my surprise, the code is actually working exactly the way I want it to. But suggestions are still welcome!

  3. DeannaS
    Member
    Posted 14 years ago #

    Um, so you realize that every blog, by default, has an options table? And, that you can set custom options by blog and that wordpress has all sorts of built in functions to do exactly that? In general, having your plugin create custom tables is frowned upon if there's a way to do what you need to do in the existing tables. So, while I'm not sure exactly what all you're trying to do, I'd encourage you to see if you can't use the existing blog options table to store your data.

About this Topic

  • Started 14 years ago by Lovedoodle
  • Latest reply from DeannaS