Wordpress - Creating a WordPress admin page without a menu for a plugin

I am less convinced that I know what you are doing than I once was.

// Add menu and pages to WordPress admin area
add_action('admin_menu', 'myplugin_create_top_level_menu');

function myplugin_create_top_level_menu() {

    // This is the menu on the side
    add_menu_page(
      'MyPlugin', 
      'MyPlugin', 
      'manage_options', 
      'myplugin-top-level-page'
    );

    // This is the first page that is displayed when the menu is clicked
    add_submenu_page(
      'myplugin-top-level-page', 
      'MyPlugin Top Level Page',
      'MyPlugin Top Level Page', 
      'manage_options', 
      'myplugin-top-level-page', 
      'myplugin_top_level_page_callback'
     );

     // This is the hidden page
     add_submenu_page(
      null, 
      'MyPlugin Details Page',
      'MyPlugin Details Page', 
      'manage_options', 
      'myplugin-details-page', 
      'myplugin_details_page_callback'
     );
}

function myplugin_top_level_page_callback() {

    global $wpdb;
    $results_from_db = $wpdb->get_results("SELECT * FROM myplugin_custom_table");

    foreach ($results_from_db as $result) {

        $id = $result->id;

        $link = add_query_arg(
            array(
                'page' => 'myplugin-details-page', // as defined in the hidden page
                'id' => $id
            ),
            admin_url('admin.php')
        );

        echo '<ul>';
        echo '<li><a href="'.$link.'">'.$id.'</a><li>';
        echo '</ul>';
    }
}

function myplugin_details_page_callback () {
    // This function is to display the hidden page (html and php)
}

You are using two additional Core functions in there, so for reference:

  • http://codex.wordpress.org/Function_Reference/add_query_arg
  • http://codex.wordpress.org/Function_Reference/admin_url