wp custom admin menu no plugin

Solutions on MaxInterview for wp custom admin menu no plugin by the best coders in the world

showing results for - "wp custom admin menu no plugin"
Enrico
05 Feb 2018
1// Check out the add_menu_page() WordPress documentation for more details:
2// https://developer.wordpress.org/reference/functions/add_menu_page/
3
4
5// Add menu and pages to WordPress admin area
6add_action('admin_menu', 'myplugin_create_top_level_menu');
7
8function myplugin_create_top_level_menu() {
9
10    // This is the menu on the side
11    add_menu_page(
12      'MyPlugin', 
13      'MyPlugin', 
14      'manage_options', 
15      'myplugin-top-level-page'
16    );
17
18    // This is the first page that is displayed when the menu is clicked
19    add_submenu_page(
20      'myplugin-top-level-page', 
21      'MyPlugin Top Level Page',
22      'MyPlugin Top Level Page', 
23      'manage_options', 
24      'myplugin-top-level-page', 
25      'myplugin_top_level_page_callback'
26     );
27
28     // This is the hidden page
29     add_submenu_page(
30      null, 
31      'MyPlugin Details Page',
32      'MyPlugin Details Page', 
33      'manage_options', 
34      'myplugin-details-page', 
35      'myplugin_details_page_callback'
36     );
37}
38
39function myplugin_top_level_page_callback() {
40
41    global $wpdb;
42    $results_from_db = $wpdb->get_results("SELECT * FROM myplugin_custom_table");
43
44    foreach ($results_from_db as $result) {
45
46        $id = $result->id;
47
48        $link = add_query_arg(
49            array(
50                'page' => 'myplugin-details-page', // as defined in the hidden page
51                'id' => $id
52            ),
53            admin_url('admin.php')
54        );
55
56        echo '<ul>';
57        echo '<li><a href="'.$link.'">'.$id.'</a><li>';
58        echo '</ul>';
59    }
60}
61
62function myplugin_details_page_callback () {
63    // This function is to display the hidden page (html and php)
64}
65